Skip to content

Commit

Permalink
feat: set up tailwind
Browse files Browse the repository at this point in the history
  • Loading branch information
n1ru4l committed Mar 24, 2022
1 parent a24f0b5 commit 27ccbe7
Show file tree
Hide file tree
Showing 10 changed files with 326 additions and 105 deletions.
6 changes: 5 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"recommendations": ["esbenp.prettier-vscode", "GraphQL.vscode-graphql"]
"recommendations": [
"esbenp.prettier-vscode",
"GraphQL.vscode-graphql",
"bradlc.vscode-tailwindcss"
]
}
74 changes: 63 additions & 11 deletions app/lib/navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,68 @@ import React from "react";
export function Navigation() {
const user = Auth.useUser();
return (
<div>
SupaNews{" "}
{user.user === null ? (
<Link href="/login">login</Link>
) : (
<>
<Link href="/account">account</Link>
<Link href="/logout">logout</Link>
</>
)}
</div>
<header className="text-gray-600 body-font">
<div className="container mx-auto flex flex-wrap p-5 flex-col md:flex-row items-center">
<Link href="/">
<a className="flex title-font font-medium items-center text-gray-900 mb-4 md:mb-0">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
className="w-10 h-10 text-white p-2 bg-indigo-500 rounded-full"
viewBox="0 0 24 24"
>
<path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5"></path>
</svg>
<span className="ml-3 text-xl">SupaNews</span>
</a>
</Link>
<nav className="md:mr-auto md:ml-4 md:py-1 md:pl-4 md:border-l md:border-gray-400 flex flex-wrap items-center text-base justify-center">
<Link href="/new">
<a className="mr-5 hover:text-gray-900">new</a>
</Link>
<Link href="/comments">
<a className="mr-5 hover:text-gray-900">comments</a>
</Link>
<Link href="/submit">
<a className="mr-5 hover:text-gray-900">submit</a>
</Link>
</nav>
{user.user === null ? (
<Link href="login">
<button className="inline-flex items-center bg-gray-100 border-0 py-1 px-3 focus:outline-none hover:bg-gray-200 rounded text-base mt-4 md:mt-0">
login
<svg
fill="none"
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
className="w-4 h-4 ml-1"
viewBox="0 0 24 24"
>
<path d="M5 12h14M12 5l7 7-7 7"></path>
</svg>
</button>
</Link>
) : (
<>
<Link href="/account">
<a className="inline-flex items-center bg-gray-100 border-0 py-1 px-3 focus:outline-none hover:bg-gray-200 rounded text-base mt-4 md:mt-0">
account
</a>
</Link>
<Link href="/logout">
<button className="inline-flex items-center bg-gray-100 border-0 py-1 px-3 focus:outline-none hover:bg-gray-200 rounded text-base mt-4 md:mt-0">
logout
</button>
</Link>
</>
)}
</div>
</header>
);
}
3 changes: 3 additions & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
"dependencies": {
"@supabase/supabase-js": "1.31.2",
"@supabase/ui": "0.36.4",
"autoprefixer": "10.4.4",
"graphql": "16.3.0",
"next": "12.1.0",
"postcss": "8.4.12",
"react": "17.0.2",
"react-dom": "17.0.2",
"tailwindcss": "3.0.23",
"urql": "2.2.0"
},
"devDependencies": {
Expand Down
91 changes: 41 additions & 50 deletions app/pages/account.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from "react";
import { NextPage } from "next";
import { useRouter } from "next/router";
import { Auth, Loading } from "@supabase/ui";
import { Auth, Button } from "@supabase/ui";
import { CombinedError, useMutation, useQuery } from "urql";
import { Input } from "@supabase/ui";
import { useSupabaseClient } from "../lib/supabase";
import { DocumentType, gql } from "../gql";
import { CombinedError, useMutation, useQuery } from "urql";

const UserProfileQuery = gql(/* GraphQL */ `
query UserProfileQuery($profileId: UUID!) {
Expand Down Expand Up @@ -100,55 +101,45 @@ function AccountForm(props: { profile: DocumentType<typeof ProfileFragment> }) {
const errorState = extractExpectedGraphQLErrors(updateProfileMutation.error);

return (
<>
<div className="form-widget">
<div>
<label htmlFor="username">Name</label>
<input
id="username"
type="text"
value={username}
onChange={(e) => setUsername(e.target.value)}
/>
</div>
<div>
<label htmlFor="website">Website</label>
<input
id="website"
type="website"
value={website || ""}
onChange={(e) => setWebsite(e.target.value)}
/>
</div>

<div>
<button
className="button block primary"
onClick={() =>
updateProfile({
userId: props.profile.id,
newUsername: username,
newWebsite: website,
})
}
disabled={updateProfileMutation.fetching}
>
{updateProfileMutation.fetching ? "Loading ..." : "Update"}
</button>
</div>

<div>{errorState}</div>

<div>
<button
className="button block"
onClick={() => supabaseClient.auth.signOut()}
>
Sign Out
</button>
</div>
<section className="container px-5 py-24 mx-auto">
<div>
<label htmlFor="username" className="text-blue-600">
Name
</label>
<Input
id="username"
type="text"
value={username}
onChange={(e) => setUsername(e.target.value)}
/>
</div>
<div>
<label htmlFor="website">Website</label>
<Input
id="website"
type="website"
value={website || ""}
onChange={(e) => setWebsite(e.target.value)}
/>
</div>
</>

<div>
<Button
onClick={() =>
updateProfile({
userId: props.profile.id,
newUsername: username,
newWebsite: website,
})
}
disabled={updateProfileMutation.fetching}
>
{updateProfileMutation.fetching ? "Loading ..." : "Update"}
</Button>
</div>

<div>{errorState}</div>
</section>
);
}

Expand Down
5 changes: 3 additions & 2 deletions app/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ const FeedQuery = gql(/* GraphQL */ `
`);

const Home: NextPage = () => {
const [data] = useQuery({ query: FeedQuery });
const [feedQuery] = useQuery({ query: FeedQuery });

return (
<div className={styles.container}>
<Head>
Expand All @@ -51,7 +52,7 @@ const Home: NextPage = () => {

<main className={styles.main}>
<pre>
<code>{JSON.stringify(data?.data, null, 2)}</code>
<code>{JSON.stringify(feedQuery?.data, null, 2)}</code>
</pre>
</main>

Expand Down
27 changes: 13 additions & 14 deletions app/pages/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,24 @@ import React from "react";
import type { NextPage } from "next";
import { Auth } from "@supabase/ui";
import { useSupabaseClient } from "../lib/supabase";
import { useRouter } from "next/router";

const LogIn: NextPage = () => {
const { user } = Auth.useUser();
const supabaseClient = useSupabaseClient();
const router = useRouter();

return user ? (
<pre>
<code>{JSON.stringify(user, null, 2)}</code>
<button
onClick={() => {
supabaseClient.auth.signOut();
}}
>
Log out
</button>
</pre>
) : (
<Auth supabaseClient={supabaseClient} providers={["github"]} />
);
React.useEffect(() => {
if (user !== null) {
router.replace("/account");
}
}, []);

if (user) {
return null;
}

return <Auth supabaseClient={supabaseClient} providers={["github"]} />;
};

export default LogIn;
6 changes: 6 additions & 0 deletions app/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};
19 changes: 3 additions & 16 deletions app/styles/globals.css
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
html,
body {
padding: 0;
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen,
Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
}

a {
color: inherit;
text-decoration: none;
}

* {
box-sizing: border-box;
}
@tailwind base;
@tailwind components;
@tailwind utilities;
7 changes: 7 additions & 0 deletions app/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
content: ["./pages/**/*.{js,ts,jsx,tsx}", "./lib/**/*.{js,ts,jsx,tsx}"],
theme: {
extend: {},
},
plugins: [],
};
Loading

0 comments on commit 27ccbe7

Please sign in to comment.