first commit
This commit is contained in:
commit
6857e301fa
23 files changed
+5500
No files matched your search
@@ -0,0 +1,211 @@
|
||||
import React from "react";
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/router";
|
||||
import { signOut, useSession } from "next-auth/react";
|
||||
|
||||
const Header: React.FC = () => {
|
||||
const router = useRouter();
|
||||
const isActive: (pathname: string) => boolean = (pathname) =>
|
||||
router.pathname === pathname;
|
||||
|
||||
const {data: session, status} = useSession();
|
||||
|
||||
let left = (
|
||||
<div className="left">
|
||||
<Link href="/" legacyBehavior>
|
||||
<a className="bold" data-active={isActive("/")}>
|
||||
Feed
|
||||
</a>
|
||||
</Link>
|
||||
<style jsx>{`
|
||||
.bold {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
a {
|
||||
text-decoration: none;
|
||||
color: #000;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.left a[data-active="true"] {
|
||||
color: gray;
|
||||
}
|
||||
|
||||
a + a {
|
||||
margin-left: 1rem;
|
||||
}
|
||||
`}</style>
|
||||
</div>
|
||||
);
|
||||
|
||||
let right = null;
|
||||
|
||||
if (status === 'loading') {
|
||||
left = (
|
||||
<div className="left">
|
||||
<Link href="/" legacyBehavior>
|
||||
<a className="bold" data-active={isActive("/")}>
|
||||
Feed
|
||||
</a>
|
||||
</Link>
|
||||
<style jsx>{`
|
||||
.bold {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
a {
|
||||
text-decoration: none;
|
||||
color: #000;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.left a[data-active="true"] {
|
||||
color: gray;
|
||||
}
|
||||
|
||||
a + a {
|
||||
margin-left: 1rem;
|
||||
}
|
||||
`}</style>
|
||||
</div>
|
||||
);
|
||||
right = (
|
||||
<div className="right">
|
||||
<p>Validating session ...</p>
|
||||
<style jsx>{`
|
||||
.right {
|
||||
margin-left: auto;
|
||||
}
|
||||
`}</style>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!session) {
|
||||
right = (
|
||||
<div className="right">
|
||||
<Link href="/api/auth/signin" legacyBehavior>
|
||||
<a data-active={isActive("/signup")}>Log in</a>
|
||||
</Link>
|
||||
<style jsx>{`
|
||||
a {
|
||||
text-decoration: none;
|
||||
color: #000;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
a + a {
|
||||
margin-left: 1rem;
|
||||
}
|
||||
|
||||
.right {
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.right a {
|
||||
border: 1px solid black;
|
||||
padding: 0.5rem 1rem;
|
||||
border-radius: 3px;
|
||||
}
|
||||
`}</style>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (session) {
|
||||
left = (
|
||||
<div className="left">
|
||||
<Link href="/" legacyBehavior>
|
||||
<a className="bold" data-active={isActive("/")}>
|
||||
Feed
|
||||
</a>
|
||||
</Link>
|
||||
<Link href="/drafts" legacyBehavior>
|
||||
<a data-active={isActive("/drafts")}>My drafts</a>
|
||||
</Link>
|
||||
<style jsx>{`
|
||||
.bold {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
a {
|
||||
text-decoration: none;
|
||||
color: #000;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.left a[data-active="true"] {
|
||||
color: gray;
|
||||
}
|
||||
|
||||
a + a {
|
||||
margin-left: 1rem;
|
||||
}
|
||||
`}</style>
|
||||
</div>
|
||||
);
|
||||
right = (
|
||||
<div className="right">
|
||||
<p>
|
||||
{session.user.name} ({session.user.email})
|
||||
</p>
|
||||
<Link href="/create" legacyBehavior>
|
||||
<button>
|
||||
<a>New post</a>
|
||||
</button>
|
||||
</Link>
|
||||
<button onClick={() => signOut()}>
|
||||
<a>Log out</a>
|
||||
</button>
|
||||
<style jsx>{`
|
||||
a {
|
||||
text-decoration: none;
|
||||
color: #000;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
p {
|
||||
display: inline-block;
|
||||
font-size: 13px;
|
||||
padding-right: 1rem;
|
||||
}
|
||||
|
||||
a + a {
|
||||
margin-left: 1rem;
|
||||
}
|
||||
|
||||
.right {
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.right a {
|
||||
border: 1px solid black;
|
||||
padding: 0.5rem 1rem;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
button {
|
||||
border: none;
|
||||
}
|
||||
`}</style>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<nav>
|
||||
{left}
|
||||
{right}
|
||||
<style jsx>{`
|
||||
nav {
|
||||
display: flex;
|
||||
padding: 2rem;
|
||||
align-items: center;
|
||||
}
|
||||
`}</style>
|
||||
</nav>
|
||||
);
|
||||
};
|
||||
|
||||
export default Header;
|
||||
@@ -0,0 +1,50 @@
|
||||
import React, { ReactNode } from "react";
|
||||
import Header from "./Header";
|
||||
|
||||
type Props = {
|
||||
children: ReactNode;
|
||||
};
|
||||
|
||||
const Layout: React.FC<Props> = (props) => (
|
||||
<div>
|
||||
<Header />
|
||||
<div className="layout">{props.children}</div>
|
||||
<style jsx global>{`
|
||||
html {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
*,
|
||||
*:before,
|
||||
*:after {
|
||||
box-sizing: inherit;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
font-size: 16px;
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
|
||||
Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji",
|
||||
"Segoe UI Symbol";
|
||||
background: rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
input,
|
||||
textarea {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
button {
|
||||
cursor: pointer;
|
||||
}
|
||||
`}</style>
|
||||
<style jsx>{`
|
||||
.layout {
|
||||
padding: 0 2rem;
|
||||
}
|
||||
`}</style>
|
||||
</div>
|
||||
);
|
||||
|
||||
export default Layout;
|
||||
@@ -0,0 +1,33 @@
|
||||
import React from "react";
|
||||
import Router from "next/router";
|
||||
import ReactMarkdown from "react-markdown";
|
||||
|
||||
export type PostProps = {
|
||||
id: number;
|
||||
title: string;
|
||||
author: {
|
||||
name: string;
|
||||
email: string;
|
||||
} | null;
|
||||
content: string;
|
||||
published: boolean;
|
||||
};
|
||||
|
||||
const Post: React.FC<{ post: PostProps }> = ({ post }) => {
|
||||
const authorName = post.author ? post.author.name : "Unknown author";
|
||||
return (
|
||||
<div onClick={() => Router.push("/p/[id]", `/p/${post.id}`)}>
|
||||
<h2>{post.title}</h2>
|
||||
<small>By {authorName}</small>
|
||||
<ReactMarkdown children={post.content} />
|
||||
<style jsx>{`
|
||||
div {
|
||||
color: inherit;
|
||||
padding: 2rem;
|
||||
}
|
||||
`}</style>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Post;
|
||||
Reference in new issue
Block a user