(null)
- const [tab, setTab] = useState(initialTab)
- // const height = editable ? "500px" : '100%'
- const height = "100%";
+ const handleTabChange = (newTab: string) => {
+ if (newTab === "edit") {
+ codeEditorRef.current?.focus()
+ }
+ setTab(newTab as "edit" | "preview")
+ }
- const handleTabChange = (newTab: string) => {
- if (newTab === 'edit') {
- codeEditorRef.current?.focus()
- }
- setTab(newTab as 'edit' | 'preview')
- }
+ const rawLink = () => {
+ if (id) {
+ return `/file/raw/${id}`
+ }
+ }
- const rawLink = () => {
- if (id) {
- return `/file/raw/${id}`
- }
- }
+ if (skeleton) {
+ return (
+ <>
+
+
+ >
+ )
+ }
- if (skeleton) {
- return <>
-
-
- >
- }
-
-
- return (
-
-
-
-
-
- {title || 'Untitled'}
-
-
-
-
-
-
- {/* */}
-
-
-
-
-
-
-
-
-
-
-
-
-
- )
+ return (
+
+
+
+
+
+ {title || "Untitled"}
+
+
+
+
+
+
+ {/* */}
+
+
+
+
+
+
+
+
+
+
+
+
+
+ )
}
-
-export default memo(Document)
\ No newline at end of file
+export default memo(Document)
diff --git a/client/package.json b/client/package.json
index 142f3701..373a4d1f 100644
--- a/client/package.json
+++ b/client/package.json
@@ -1,74 +1,74 @@
{
- "name": "drift",
- "version": "0.1.0",
- "private": true,
- "scripts": {
- "dev": "next dev --port 3001",
- "build": "next build",
- "start": "next start",
- "lint": "next lint && prettier --config .prettierrc '{components,lib,pages}/**/*.ts' --write",
- "analyze": "cross-env ANALYZE=true next build",
- "find:unused": "next-unused"
- },
- "dependencies": {
- "@geist-ui/core": "^2.3.5",
- "@geist-ui/icons": "^1.0.1",
- "@types/cookie": "^0.4.1",
- "@types/js-cookie": "^3.0.1",
- "client-zip": "^2.0.0",
- "cookie": "^0.4.2",
- "dotenv": "^16.0.0",
- "js-cookie": "^3.0.1",
- "lodash.debounce": "^4.0.8",
- "marked": "^4.0.12",
- "next": "^12.1.1-canary.15",
- "next-themes": "^0.1.1",
- "postcss": "^8.4.12",
- "postcss-flexbugs-fixes": "^5.0.2",
- "postcss-hover-media-feature": "^1.0.2",
- "postcss-preset-env": "^7.4.3",
- "preact": "^10.6.6",
- "prism-react-renderer": "^1.3.1",
- "react": "17.0.2",
- "react-datepicker": "^4.7.0",
- "react-dom": "17.0.2",
- "react-dropzone": "^12.0.4",
- "react-loading-skeleton": "^3.0.3",
- "react-markdown": "^8.0.0",
- "react-syntax-highlighter": "^15.4.5",
- "rehype-autolink-headings": "^6.1.1",
- "rehype-raw": "^6.1.1",
- "rehype-slug": "^5.0.1",
- "remark-gfm": "^3.0.1",
- "swr": "^1.2.2"
- },
- "devDependencies": {
- "@next/bundle-analyzer": "^12.1.0",
- "@types/lodash.debounce": "^4.0.6",
- "@types/marked": "^4.0.3",
- "@types/node": "17.0.21",
- "@types/nprogress": "^0.2.0",
- "@types/react": "17.0.39",
- "@types/react-datepicker": "^4.3.4",
- "@types/react-dom": "^17.0.14",
- "@types/react-syntax-highlighter": "^13.5.2",
- "cross-env": "^7.0.3",
- "eslint": "8.10.0",
- "eslint-config-next": "^12.1.1-canary.16",
- "next-unused": "^0.0.6",
- "prettier": "^2.6.0",
- "typescript": "4.6.2",
- "typescript-plugin-css-modules": "^3.4.0"
- },
- "next-unused": {
- "alias": {
- "@components": "components/",
- "@lib": "lib/",
- "@styles": "styles/"
- },
- "include": [
- "components",
- "lib"
- ]
- }
+ "name": "drift",
+ "version": "0.1.0",
+ "private": true,
+ "scripts": {
+ "dev": "next dev --port 3001",
+ "build": "next build",
+ "start": "next start",
+ "lint": "next lint && prettier --list-different --config .prettierrc '{components,lib,pages}/**/*.{ts,tsx}' --write",
+ "analyze": "cross-env ANALYZE=true next build",
+ "find:unused": "next-unused"
+ },
+ "dependencies": {
+ "@geist-ui/core": "^2.3.5",
+ "@geist-ui/icons": "^1.0.1",
+ "@types/cookie": "^0.4.1",
+ "@types/js-cookie": "^3.0.1",
+ "client-zip": "^2.0.0",
+ "cookie": "^0.4.2",
+ "dotenv": "^16.0.0",
+ "js-cookie": "^3.0.1",
+ "lodash.debounce": "^4.0.8",
+ "marked": "^4.0.12",
+ "next": "^12.1.1-canary.15",
+ "next-themes": "^0.1.1",
+ "postcss": "^8.4.12",
+ "postcss-flexbugs-fixes": "^5.0.2",
+ "postcss-hover-media-feature": "^1.0.2",
+ "postcss-preset-env": "^7.4.3",
+ "preact": "^10.6.6",
+ "prism-react-renderer": "^1.3.1",
+ "react": "17.0.2",
+ "react-datepicker": "^4.7.0",
+ "react-dom": "17.0.2",
+ "react-dropzone": "^12.0.4",
+ "react-loading-skeleton": "^3.0.3",
+ "react-markdown": "^8.0.0",
+ "react-syntax-highlighter": "^15.4.5",
+ "rehype-autolink-headings": "^6.1.1",
+ "rehype-raw": "^6.1.1",
+ "rehype-slug": "^5.0.1",
+ "remark-gfm": "^3.0.1",
+ "swr": "^1.2.2"
+ },
+ "devDependencies": {
+ "@next/bundle-analyzer": "^12.1.0",
+ "@types/lodash.debounce": "^4.0.6",
+ "@types/marked": "^4.0.3",
+ "@types/node": "17.0.21",
+ "@types/nprogress": "^0.2.0",
+ "@types/react": "17.0.39",
+ "@types/react-datepicker": "^4.3.4",
+ "@types/react-dom": "^17.0.14",
+ "@types/react-syntax-highlighter": "^13.5.2",
+ "cross-env": "^7.0.3",
+ "eslint": "8.10.0",
+ "eslint-config-next": "^12.1.1-canary.16",
+ "next-unused": "^0.0.6",
+ "prettier": "^2.6.0",
+ "typescript": "4.6.2",
+ "typescript-plugin-css-modules": "^3.4.0"
+ },
+ "next-unused": {
+ "alias": {
+ "@components": "components/",
+ "@lib": "lib/",
+ "@styles": "styles/"
+ },
+ "include": [
+ "components",
+ "lib"
+ ]
+ }
}
diff --git a/client/pages/_app.tsx b/client/pages/_app.tsx
index 5b1da879..e28be06e 100644
--- a/client/pages/_app.tsx
+++ b/client/pages/_app.tsx
@@ -1,38 +1,58 @@
-import '@styles/globals.css'
-import type { AppProps as NextAppProps } from "next/app";
+import "@styles/globals.css"
+import type { AppProps as NextAppProps } from "next/app"
-import 'react-loading-skeleton/dist/skeleton.css'
-import Head from 'next/head';
-import { ThemeProvider } from 'next-themes'
-import App from '@components/app';
+import "react-loading-skeleton/dist/skeleton.css"
+import Head from "next/head"
+import { ThemeProvider } from "next-themes"
+import App from "@components/app"
type AppProps = {
- pageProps: P;
-} & Omit, "pageProps">;
-
+ pageProps: P
+} & Omit, "pageProps">
function MyApp({ Component, pageProps }: AppProps) {
- return (
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Drift
-
-
-
-
-
- )
+ return (
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Drift
+
+
+
+
+
+ )
}
export default MyApp
diff --git a/client/pages/_document.tsx b/client/pages/_document.tsx
index 4acbd87e..1aa7a433 100644
--- a/client/pages/_document.tsx
+++ b/client/pages/_document.tsx
@@ -1,31 +1,39 @@
-import { CssBaseline } from '@geist-ui/core'
-import Document, { Html, Head, Main, NextScript, DocumentContext } from 'next/document'
+import { CssBaseline } from "@geist-ui/core"
+import Document, {
+ Html,
+ Head,
+ Main,
+ NextScript,
+ DocumentContext
+} from "next/document"
class MyDocument extends Document {
- static async getInitialProps(ctx: DocumentContext) {
- const initialProps = await Document.getInitialProps(ctx)
- const styles = CssBaseline.flush()
+ static async getInitialProps(ctx: DocumentContext) {
+ const initialProps = await Document.getInitialProps(ctx)
+ const styles = CssBaseline.flush()
- return {
- ...initialProps,
- styles: (
- <>
- {initialProps.styles}
- {styles}
- >
- )
- }
- }
+ return {
+ ...initialProps,
+ styles: (
+ <>
+ {initialProps.styles}
+ {styles}
+ >
+ )
+ }
+ }
- render() {
- return (
-
-
-
-
-
- )
- }
+ render() {
+ return (
+
+
+
+
+
+
+
+ )
+ }
}
export default MyDocument
diff --git a/client/pages/_error.tsx b/client/pages/_error.tsx
index 6f118779..1796d6cd 100644
--- a/client/pages/_error.tsx
+++ b/client/pages/_error.tsx
@@ -1,17 +1,12 @@
-import ErrorComponent from '@components/error'
+import ErrorComponent from "@components/error"
-function Error({ statusCode }: {
- statusCode: number
-}) {
- return
+function Error({ statusCode }: { statusCode: number }) {
+ return
}
-Error.getInitialProps = ({ res, err }: {
- res: any
- err: any
-}) => {
- const statusCode = res ? res.statusCode : err ? err.statusCode : 404
- return { statusCode }
+Error.getInitialProps = ({ res, err }: { res: any; err: any }) => {
+ const statusCode = res ? res.statusCode : err ? err.statusCode : 404
+ return { statusCode }
}
export default Error
diff --git a/client/pages/_middleware.tsx b/client/pages/_middleware.tsx
index bf2c2ee7..47019f6e 100644
--- a/client/pages/_middleware.tsx
+++ b/client/pages/_middleware.tsx
@@ -1,53 +1,55 @@
-import { NextFetchEvent, NextRequest, NextResponse } from 'next/server'
+import { NextFetchEvent, NextRequest, NextResponse } from "next/server"
const PUBLIC_FILE = /\.(.*)$/
export function middleware(req: NextRequest, event: NextFetchEvent) {
- const pathname = req.nextUrl.pathname
- const signedIn = req.cookies['drift-token']
- const getURL = (pageName: string) => new URL(`/${pageName}`, req.url).href
- const isPageRequest =
- !PUBLIC_FILE.test(pathname) &&
- !pathname.startsWith('/api') &&
- // header added when next/link pre-fetches a route
- !req.headers.get('x-middleware-preflight')
+ const pathname = req.nextUrl.pathname
+ const signedIn = req.cookies["drift-token"]
+ const getURL = (pageName: string) => new URL(`/${pageName}`, req.url).href
+ const isPageRequest =
+ !PUBLIC_FILE.test(pathname) &&
+ !pathname.startsWith("/api") &&
+ // header added when next/link pre-fetches a route
+ !req.headers.get("x-middleware-preflight")
- if (!req.headers.get('x-middleware-preflight') && pathname === '/signout') {
- // If you're signed in we remove the cookie and redirect to the home page
- // If you're not signed in we redirect to the home page
- if (signedIn) {
- const resp = NextResponse.redirect(getURL(''));
- resp.clearCookie('drift-token');
- resp.clearCookie('drift-userid');
- const signoutPromise = new Promise((resolve) => {
- fetch(`${process.env.API_URL}/auth/signout`, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- 'Authorization': `Bearer ${signedIn}`,
- 'x-secret-key': process.env.SECRET_KEY || '',
- },
- })
- .then(() => {
- resolve(true)
- })
- })
- event.waitUntil(signoutPromise)
+ if (!req.headers.get("x-middleware-preflight") && pathname === "/signout") {
+ // If you're signed in we remove the cookie and redirect to the home page
+ // If you're not signed in we redirect to the home page
+ if (signedIn) {
+ const resp = NextResponse.redirect(getURL(""))
+ resp.clearCookie("drift-token")
+ resp.clearCookie("drift-userid")
+ const signoutPromise = new Promise((resolve) => {
+ fetch(`${process.env.API_URL}/auth/signout`, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: `Bearer ${signedIn}`,
+ "x-secret-key": process.env.SECRET_KEY || ""
+ }
+ }).then(() => {
+ resolve(true)
+ })
+ })
+ event.waitUntil(signoutPromise)
- return resp
- }
- } else if (isPageRequest) {
- if (signedIn) {
- if (pathname === '/' || pathname === '/signin' || pathname === '/signup') {
- return NextResponse.redirect(getURL('new'))
- }
- } else if (!signedIn) {
- if (pathname === '/new') {
- return NextResponse.redirect(getURL('signin'))
- }
- }
+ return resp
+ }
+ } else if (isPageRequest) {
+ if (signedIn) {
+ if (
+ pathname === "/" ||
+ pathname === "/signin" ||
+ pathname === "/signup"
+ ) {
+ return NextResponse.redirect(getURL("new"))
+ }
+ } else if (!signedIn) {
+ if (pathname === "/new") {
+ return NextResponse.redirect(getURL("signin"))
+ }
+ }
+ }
- }
-
- return NextResponse.next()
+ return NextResponse.next()
}
diff --git a/client/pages/admin.tsx b/client/pages/admin.tsx
index ff446919..474416b9 100644
--- a/client/pages/admin.tsx
+++ b/client/pages/admin.tsx
@@ -1,55 +1,55 @@
-import styles from '@styles/Home.module.css'
+import styles from "@styles/Home.module.css"
-import Header from '@components/header'
-import { Page } from '@geist-ui/core';
-import { useEffect } from 'react';
-import Admin from '@components/admin';
-import useSignedIn from '@lib/hooks/use-signed-in';
-import { useRouter } from 'next/router';
-import { GetServerSideProps } from 'next';
-import cookie from "cookie";
+import Header from "@components/header"
+import { Page } from "@geist-ui/core"
+import { useEffect } from "react"
+import Admin from "@components/admin"
+import useSignedIn from "@lib/hooks/use-signed-in"
+import { useRouter } from "next/router"
+import { GetServerSideProps } from "next"
+import cookie from "cookie"
const AdminPage = () => {
- const { signedIn } = useSignedIn()
- const router = useRouter()
- useEffect(() => {
- if (typeof window === 'undefined') return
- if (!signedIn) {
- router.push('/')
- }
- }, [router, signedIn])
- return (
-
-
-
-
-
- )
+ const { signedIn } = useSignedIn()
+ const router = useRouter()
+ useEffect(() => {
+ if (typeof window === "undefined") return
+ if (!signedIn) {
+ router.push("/")
+ }
+ }, [router, signedIn])
+ return (
+
+
+
+
+
+ )
}
export const getServerSideProps: GetServerSideProps = async ({ req }) => {
- const driftToken = cookie.parse(req.headers.cookie || '')[`drift-token`]
- const res = await fetch(`${process.env.API_URL}/admin/is-admin`, {
- headers: {
- 'Authorization': `Bearer ${driftToken}`,
- 'x-secret-key': process.env.SECRET_KEY || ''
- }
- })
+ const driftToken = cookie.parse(req.headers.cookie || "")[`drift-token`]
+ const res = await fetch(`${process.env.API_URL}/admin/is-admin`, {
+ headers: {
+ Authorization: `Bearer ${driftToken}`,
+ "x-secret-key": process.env.SECRET_KEY || ""
+ }
+ })
- if (res.ok) {
- return {
- props: {
- signedIn: true
- }
- }
- } else {
- return {
- redirect: {
- destination: '/',
- permanent: false
- }
- }
- }
+ if (res.ok) {
+ return {
+ props: {
+ signedIn: true
+ }
+ }
+ } else {
+ return {
+ redirect: {
+ destination: "/",
+ permanent: false
+ }
+ }
+ }
}
export default AdminPage
diff --git a/client/pages/expired.tsx b/client/pages/expired.tsx
index af849faa..57414ba0 100644
--- a/client/pages/expired.tsx
+++ b/client/pages/expired.tsx
@@ -1,18 +1,19 @@
import Header from "@components/header"
import { Note, Page, Text } from "@geist-ui/core"
-import styles from '@styles/Home.module.css'
+import styles from "@styles/Home.module.css"
const Expired = () => {
- return (
-
-
-
- Error: The Drift you're trying to view has expired.
-
-
-
-
- )
+ return (
+
+
+
+
+ Error: The Drift you're trying to view has expired.
+
+
+
+
+ )
}
export default Expired
diff --git a/client/pages/index.tsx b/client/pages/index.tsx
index 89c28fd5..c6e63627 100644
--- a/client/pages/index.tsx
+++ b/client/pages/index.tsx
@@ -1,60 +1,65 @@
-import styles from '@styles/Home.module.css'
-import PageSeo from '@components/page-seo'
-import HomeComponent from '@components/home'
-import { Page, Text } from '@geist-ui/core'
-import { GetServerSideProps } from 'next'
+import styles from "@styles/Home.module.css"
+import PageSeo from "@components/page-seo"
+import HomeComponent from "@components/home"
+import { Page, Text } from "@geist-ui/core"
+import { GetServerSideProps } from "next"
export const getServerSideProps: GetServerSideProps = async ({ res }) => {
- try {
- const resp = await fetch(process.env.API_URL + `/welcome`,
- {
- method: "GET",
- headers: {
- "Content-Type": "application/json",
- "x-secret-key": process.env.SECRET_KEY || ''
- }
- })
+ try {
+ const resp = await fetch(process.env.API_URL + `/welcome`, {
+ method: "GET",
+ headers: {
+ "Content-Type": "application/json",
+ "x-secret-key": process.env.SECRET_KEY || ""
+ }
+ })
- const { title, content, rendered } = await resp.json()
+ const { title, content, rendered } = await resp.json()
- res.setHeader(
- 'Cache-Control',
- `public, s-maxage=${60 * 60 * 24 * 360}, max-age=${60 * 60 * 24 * 360}`
- )
+ res.setHeader(
+ "Cache-Control",
+ `public, s-maxage=${60 * 60 * 24 * 360}, max-age=${60 * 60 * 24 * 360}`
+ )
- return {
- props: {
- introContent: content || null,
- rendered: rendered || null,
- introTitle: title || null,
- }
- }
- } catch (error) {
- return {
- props: {
- error: true
- }
- }
- }
+ return {
+ props: {
+ introContent: content || null,
+ rendered: rendered || null,
+ introTitle: title || null
+ }
+ }
+ } catch (error) {
+ return {
+ props: {
+ error: true
+ }
+ }
+ }
}
type Props = {
- introContent: string
- introTitle: string
- rendered: string
- error?: boolean
+ introContent: string
+ introTitle: string
+ rendered: string
+ error?: boolean
}
const Home = ({ rendered, introContent, introTitle, error }: Props) => {
- return (
-
-
-
- {error && Something went wrong. Is the server running?}
- {!error && }
-
-
- )
+ return (
+
+
+
+ {error && Something went wrong. Is the server running?}
+ {!error && (
+
+ )}
+
+
+ )
}
export default Home
diff --git a/client/pages/mine.tsx b/client/pages/mine.tsx
index a5f269e5..d4050379 100644
--- a/client/pages/mine.tsx
+++ b/client/pages/mine.tsx
@@ -1,59 +1,67 @@
-import styles from '@styles/Home.module.css'
+import styles from "@styles/Home.module.css"
-import Header from '@components/header'
-import MyPosts from '@components/my-posts'
-import cookie from "cookie";
-import type { GetServerSideProps } from 'next';
-import { Post } from '@lib/types';
-import { Page } from '@geist-ui/core';
+import Header from "@components/header"
+import MyPosts from "@components/my-posts"
+import cookie from "cookie"
+import type { GetServerSideProps } from "next"
+import { Post } from "@lib/types"
+import { Page } from "@geist-ui/core"
-const Home = ({ morePosts, posts, error }: { morePosts: boolean, posts: Post[]; error: boolean; }) => {
- return (
-
-
-
-
-
- )
+const Home = ({
+ morePosts,
+ posts,
+ error
+}: {
+ morePosts: boolean
+ posts: Post[]
+ error: boolean
+}) => {
+ return (
+
+
+
+
+
+ )
}
-// get server side props
+// get server side props
export const getServerSideProps: GetServerSideProps = async ({ req }) => {
- const driftToken = cookie.parse(req.headers.cookie || '')[`drift-token`]
- if (!driftToken) {
- return {
- redirect: {
- destination: '/',
- permanent: false,
- }
- }
- }
+ const driftToken = cookie.parse(req.headers.cookie || "")[`drift-token`]
+ if (!driftToken) {
+ return {
+ redirect: {
+ destination: "/",
+ permanent: false
+ }
+ }
+ }
- const posts = await fetch(process.env.API_URL + `/posts/mine`, {
- method: "GET",
- headers: {
- "Content-Type": "application/json",
- "Authorization": `Bearer ${driftToken}`,
- "x-secret-key": process.env.SECRET_KEY || ''
- }
- })
+ const posts = await fetch(process.env.API_URL + `/posts/mine`, {
+ method: "GET",
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: `Bearer ${driftToken}`,
+ "x-secret-key": process.env.SECRET_KEY || ""
+ }
+ })
- if (!posts.ok) {
- return {
- redirect: {
- destination: '/',
- permanent: false,
- }
- }
- }
+ if (!posts.ok) {
+ return {
+ redirect: {
+ destination: "/",
+ permanent: false
+ }
+ }
+ }
- const data = await posts.json()
- return {
- props: {
- posts: data.posts,
- error: posts.status !== 200,
- morePosts: data.hasMore,
- }
- }
+ const data = await posts.json()
+ return {
+ props: {
+ posts: data.posts,
+ error: posts.status !== 200,
+ morePosts: data.hasMore
+ }
+ }
}
export default Home
diff --git a/client/pages/new/from/[id].tsx b/client/pages/new/from/[id].tsx
index b65266b0..6f0eabfb 100644
--- a/client/pages/new/from/[id].tsx
+++ b/client/pages/new/from/[id].tsx
@@ -1,76 +1,78 @@
-import styles from '@styles/Home.module.css'
-import NewPost from '@components/new-post'
-import Header from '@components/header'
-import PageSeo from '@components/page-seo'
-import { Page } from '@geist-ui/core'
-import Head from 'next/head'
-import { GetServerSideProps } from 'next'
-import { Post } from '@lib/types'
-import cookie from 'cookie'
+import styles from "@styles/Home.module.css"
+import NewPost from "@components/new-post"
+import Header from "@components/header"
+import PageSeo from "@components/page-seo"
+import { Page } from "@geist-ui/core"
+import Head from "next/head"
+import { GetServerSideProps } from "next"
+import { Post } from "@lib/types"
+import cookie from "cookie"
const NewFromExisting = ({
- post,
- parentId
+ post,
+ parentId
}: {
- post: Post,
- parentId: string
+ post: Post
+ parentId: string
}) => {
- return (
-
-
-
- {/* TODO: solve this. */}
- {/* eslint-disable-next-line @next/next/no-css-tags */}
-
-
-
-
-
-
- )
+ return (
+
+
+
+ {/* TODO: solve this. */}
+ {/* eslint-disable-next-line @next/next/no-css-tags */}
+
+
+
+
+
+
+ )
}
-export const getServerSideProps: GetServerSideProps = async ({ req, params }) => {
- const id = params?.id
- const redirect = {
- redirect: {
- destination: '/new',
- permanent: false,
- }
- }
+export const getServerSideProps: GetServerSideProps = async ({
+ req,
+ params
+}) => {
+ const id = params?.id
+ const redirect = {
+ redirect: {
+ destination: "/new",
+ permanent: false
+ }
+ }
- if (!id) {
- return redirect
- }
+ if (!id) {
+ return redirect
+ }
- const driftToken = cookie.parse(req.headers.cookie || '')[`drift-token`]
+ const driftToken = cookie.parse(req.headers.cookie || "")[`drift-token`]
- const post = await fetch(`${process.env.API_URL}/posts/${id}`,
- {
- method: "GET",
- headers: {
- "Content-Type": "application/json",
- "Authorization": `Bearer ${driftToken}`,
- "x-secret-key": process.env.SECRET_KEY || ""
- }
- })
+ const post = await fetch(`${process.env.API_URL}/posts/${id}`, {
+ method: "GET",
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: `Bearer ${driftToken}`,
+ "x-secret-key": process.env.SECRET_KEY || ""
+ }
+ })
- if (!post.ok) {
- return redirect
- }
+ if (!post.ok) {
+ return redirect
+ }
- const data = await post.json()
+ const data = await post.json()
- if (!data) {
- return redirect
- }
+ if (!data) {
+ return redirect
+ }
- return {
- props: {
- post: data,
- parentId: id
- }
- }
+ return {
+ props: {
+ post: data,
+ parentId: id
+ }
+ }
}
export default NewFromExisting
diff --git a/client/pages/new/index.tsx b/client/pages/new/index.tsx
index 198aa8a8..5a2e152d 100644
--- a/client/pages/new/index.tsx
+++ b/client/pages/new/index.tsx
@@ -1,24 +1,24 @@
-import styles from '@styles/Home.module.css'
-import NewPost from '@components/new-post'
-import Header from '@components/header'
-import PageSeo from '@components/page-seo'
-import { Page } from '@geist-ui/core'
-import Head from 'next/head'
+import styles from "@styles/Home.module.css"
+import NewPost from "@components/new-post"
+import Header from "@components/header"
+import PageSeo from "@components/page-seo"
+import { Page } from "@geist-ui/core"
+import Head from "next/head"
const New = () => {
- return (
-
-
-
- {/* TODO: solve this. */}
- {/* eslint-disable-next-line @next/next/no-css-tags */}
-
-
-
-
-
-
- )
+ return (
+
+
+
+ {/* TODO: solve this. */}
+ {/* eslint-disable-next-line @next/next/no-css-tags */}
+
+
+
+
+
+
+ )
}
export default New
diff --git a/client/pages/post/[id].tsx b/client/pages/post/[id].tsx
index 59df7c5b..08c60c98 100644
--- a/client/pages/post/[id].tsx
+++ b/client/pages/post/[id].tsx
@@ -1,50 +1,51 @@
-import type { GetServerSideProps, GetStaticPaths, GetStaticProps } from "next";
+import type { GetServerSideProps, GetStaticPaths, GetStaticProps } from "next"
-import type { Post } from "@lib/types";
-import PostPage from "@components/post-page";
+import type { Post } from "@lib/types"
+import PostPage from "@components/post-page"
export type PostProps = {
- post: Post
+ post: Post
}
const PostView = ({ post }: PostProps) => {
- return
+ return
}
-export const getServerSideProps: GetServerSideProps = async ({ params, res }) => {
- const post = await fetch(process.env.API_URL + `/posts/${params?.id}`, {
- method: "GET",
- headers: {
- "Content-Type": "application/json",
- "x-secret-key": process.env.SECRET_KEY || "",
- }
- })
+export const getServerSideProps: GetServerSideProps = async ({
+ params,
+ res
+}) => {
+ const post = await fetch(process.env.API_URL + `/posts/${params?.id}`, {
+ method: "GET",
+ headers: {
+ "Content-Type": "application/json",
+ "x-secret-key": process.env.SECRET_KEY || ""
+ }
+ })
- const sMaxAge = 60 * 60 * 24
- res.setHeader(
- 'Cache-Control',
- `public, s-maxage=${sMaxAge}, max-age=${sMaxAge}`
- )
+ const sMaxAge = 60 * 60 * 24
+ res.setHeader(
+ "Cache-Control",
+ `public, s-maxage=${sMaxAge}, max-age=${sMaxAge}`
+ )
- if (!post.ok || post.status !== 200) {
- return {
- redirect: {
- destination: '/404',
- permanent: false,
- },
- props: {}
- }
- }
+ if (!post.ok || post.status !== 200) {
+ return {
+ redirect: {
+ destination: "/404",
+ permanent: false
+ },
+ props: {}
+ }
+ }
+ const json = await post.json()
- const json = await post.json();
-
- return {
- props: {
- post: json
- }
- }
+ return {
+ props: {
+ post: json
+ }
+ }
}
export default PostView
-
diff --git a/client/pages/post/private/[id].tsx b/client/pages/post/private/[id].tsx
index f3c7d1e1..8b6feca2 100644
--- a/client/pages/post/private/[id].tsx
+++ b/client/pages/post/private/[id].tsx
@@ -1,58 +1,60 @@
-import cookie from "cookie";
-import type { GetServerSideProps } from "next";
-import { Post } from "@lib/types";
-import PostPage from "@components/post-page";
+import cookie from "cookie"
+import type { GetServerSideProps } from "next"
+import { Post } from "@lib/types"
+import PostPage from "@components/post-page"
export type PostProps = {
- post: Post
+ post: Post
}
-const Post = ({ post, }: PostProps) => {
- return ()
+const Post = ({ post }: PostProps) => {
+ return
}
export const getServerSideProps: GetServerSideProps = async (context) => {
- const headers = context.req.headers
- const host = headers.host
- const driftToken = cookie.parse(headers.cookie || '')[`drift-token`]
+ const headers = context.req.headers
+ const host = headers.host
+ const driftToken = cookie.parse(headers.cookie || "")[`drift-token`]
- if (context.query.id) {
- const post = await fetch('http://' + host + `/server-api/posts/${context.query.id}`, {
- method: "GET",
- headers: {
- "Content-Type": "application/json",
- "Authorization": `Bearer ${driftToken}`,
- "x-secret-key": process.env.SECRET_KEY || "",
- }
- })
+ if (context.query.id) {
+ const post = await fetch(
+ "http://" + host + `/server-api/posts/${context.query.id}`,
+ {
+ method: "GET",
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: `Bearer ${driftToken}`,
+ "x-secret-key": process.env.SECRET_KEY || ""
+ }
+ }
+ )
- if (!post.ok || post.status !== 200) {
- return {
- redirect: {
- destination: '/',
- permanent: false,
- },
- }
- }
- try {
- const json = await post.json();
+ if (!post.ok || post.status !== 200) {
+ return {
+ redirect: {
+ destination: "/",
+ permanent: false
+ }
+ }
+ }
+ try {
+ const json = await post.json()
- return {
- props: {
- post: json
- }
- }
- } catch (e) {
- console.log(e)
- }
- }
+ return {
+ props: {
+ post: json
+ }
+ }
+ } catch (e) {
+ console.log(e)
+ }
+ }
- return {
- props: {
- post: null
- }
- }
+ return {
+ props: {
+ post: null
+ }
+ }
}
export default Post
-
diff --git a/client/pages/post/protected/[id].tsx b/client/pages/post/protected/[id].tsx
index a0c6a085..457e9446 100644
--- a/client/pages/post/protected/[id].tsx
+++ b/client/pages/post/protected/[id].tsx
@@ -1,83 +1,92 @@
-import { Page, useToasts } from '@geist-ui/core';
+import { Page, useToasts } from "@geist-ui/core"
-import type { Post } from "@lib/types";
-import PasswordModal from "@components/new-post/password-modal";
-import { useEffect, useState } from "react";
-import { useRouter } from "next/router";
-import Cookies from "js-cookie";
-import PostPage from "@components/post-page";
+import type { Post } from "@lib/types"
+import PasswordModal from "@components/new-post/password-modal"
+import { useEffect, useState } from "react"
+import { useRouter } from "next/router"
+import Cookies from "js-cookie"
+import PostPage from "@components/post-page"
const Post = () => {
- const [isPasswordModalOpen, setIsPasswordModalOpen] = useState(true);
- const [post, setPost] = useState()
- const router = useRouter()
- const { setToast } = useToasts()
+ const [isPasswordModalOpen, setIsPasswordModalOpen] = useState(true)
+ const [post, setPost] = useState()
+ const router = useRouter()
+ const { setToast } = useToasts()
- useEffect(() => {
- if (router.isReady) {
- const fetchPostWithAuth = async () => {
- const resp = await fetch(`/server-api/posts/${router.query.id}`, {
- headers: {
- Authorization: `Bearer ${Cookies.get('drift-token')}`
- }
- })
- if (!resp.ok) return
- const post = await resp.json()
+ useEffect(() => {
+ if (router.isReady) {
+ const fetchPostWithAuth = async () => {
+ const resp = await fetch(`/server-api/posts/${router.query.id}`, {
+ headers: {
+ Authorization: `Bearer ${Cookies.get("drift-token")}`
+ }
+ })
+ if (!resp.ok) return
+ const post = await resp.json()
- if (!post) return
- setPost(post)
- }
- fetchPostWithAuth()
- }
- }, [router.isReady, router.query.id])
+ if (!post) return
+ setPost(post)
+ }
+ fetchPostWithAuth()
+ }
+ }, [router.isReady, router.query.id])
- const onSubmit = async (password: string) => {
- const res = await fetch(`/server-api/posts/${router.query.id}?password=${password}`, {
- method: "GET",
- headers: {
- "Content-Type": "application/json",
- }
- })
+ const onSubmit = async (password: string) => {
+ const res = await fetch(
+ `/server-api/posts/${router.query.id}?password=${password}`,
+ {
+ method: "GET",
+ headers: {
+ "Content-Type": "application/json"
+ }
+ }
+ )
- if (!res.ok) {
- setToast({
- type: "error",
- text: "Wrong password"
- })
- return
- }
+ if (!res.ok) {
+ setToast({
+ type: "error",
+ text: "Wrong password"
+ })
+ return
+ }
- const data = await res.json()
- if (data) {
- if (data.error) {
- setToast({
- text: data.error,
- type: "error"
- })
- } else {
- setPost(data)
- setIsPasswordModalOpen(false)
- }
- }
- }
+ const data = await res.json()
+ if (data) {
+ if (data.error) {
+ setToast({
+ text: data.error,
+ type: "error"
+ })
+ } else {
+ setPost(data)
+ setIsPasswordModalOpen(false)
+ }
+ }
+ }
- const onClose = () => {
- setIsPasswordModalOpen(false);
- router.push("/");
- }
+ const onClose = () => {
+ setIsPasswordModalOpen(false)
+ router.push("/")
+ }
- if (!router.isReady) {
- return <>>
- }
+ if (!router.isReady) {
+ return <>>
+ }
- if (!post) {
- return
-
-
- }
+ if (!post) {
+ return (
+
+
+
+ )
+ }
- return ()
+ return
}
export default Post
-
diff --git a/client/pages/signin.tsx b/client/pages/signin.tsx
index 08fdfaa2..47815b21 100644
--- a/client/pages/signin.tsx
+++ b/client/pages/signin.tsx
@@ -1,14 +1,14 @@
-import { Page } from '@geist-ui/core';
-import PageSeo from "@components/page-seo";
-import Auth from "@components/auth";
-import styles from '@styles/Home.module.css'
+import { Page } from "@geist-ui/core"
+import PageSeo from "@components/page-seo"
+import Auth from "@components/auth"
+import styles from "@styles/Home.module.css"
const SignIn = () => (
-
-
-
-
-
-
+
+
+
+
+
+
)
export default SignIn
diff --git a/client/pages/signup.tsx b/client/pages/signup.tsx
index ff673213..85556f71 100644
--- a/client/pages/signup.tsx
+++ b/client/pages/signup.tsx
@@ -1,15 +1,15 @@
-import { Page } from '@geist-ui/core';
-import Auth from "@components/auth";
-import PageSeo from '@components/page-seo';
-import styles from '@styles/Home.module.css'
+import { Page } from "@geist-ui/core"
+import Auth from "@components/auth"
+import PageSeo from "@components/page-seo"
+import styles from "@styles/Home.module.css"
const SignUp = () => (
-
-
-
-
-
-
+
+
+
+
+
+
)
export default SignUp