From 951088bacfe47750257b33e5f71d22f85c66f3e5 Mon Sep 17 00:00:00 2001 From: Max Leiter Date: Thu, 24 Mar 2022 18:03:57 -0700 Subject: [PATCH] client/server: add post searching --- README.md | 4 +- client/.env.local | 2 - client/components/edit-document/index.tsx | 34 +++--- client/components/header/header.tsx | 2 +- client/components/home/home.module.css | 3 + client/components/home/index.tsx | 43 +++++++ client/components/my-posts/index.tsx | 10 +- client/components/post-list/index.tsx | 104 +++++++++------- .../components/post-list/post-list.module.css | 1 - .../view-document/document.module.css | 4 + client/components/view-document/index.tsx | 4 +- client/pages/index.tsx | 40 +++---- client/pages/mine.tsx | 13 +- client/pages/new.tsx | 2 +- server/src/app.ts | 31 +++-- server/src/routes/posts.ts | 111 +++++++++++++----- 16 files changed, 266 insertions(+), 142 deletions(-) create mode 100644 client/components/home/home.module.css create mode 100644 client/components/home/index.tsx diff --git a/README.md b/README.md index cc97d901..6b067875 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,6 @@ You can change these to your liking. `client/.env`: - `API_URL`: defaults to localhost:3001, but allows you to host the front-end separately from the backend on a service like Vercel or Netlify -- `WELCOME_CONTENT`: a markdown string (with \n newlines) that's rendered on the home page -- `WELCOME_TITLE`: the file title for the post on the homepage. - `SECRET_KEY`: a secret key used for validating API requests that is never exposed to the browser `server/.env`: @@ -40,6 +38,8 @@ You can change these to your liking. - `MEMORY_DB`: if `true`, a sqlite database will not be created and changes will only exist in memory. Mainly for the demo. - `REGISTRATION_PASSWORD`: if MEMORY_DB is not `true`, the user will be required to provide this password to sign-up, in addition to their username and account password. If it's not set, no password will be required. - `SECRET_KEY`: the same secret key as the client +- `WELCOME_CONTENT`: a markdown string that's rendered on the home page +- `WELCOME_TITLE`: the file title for the post on the homepage. ## Current status diff --git a/client/.env.local b/client/.env.local index 7d269349..1eac9b7c 100644 --- a/client/.env.local +++ b/client/.env.local @@ -1,4 +1,2 @@ API_URL=http://localhost:3000 -WELCOME_TITLE="Welcome to Drift" -WELCOME_CONTENT="## Drift is a self-hostable clone of GitHub Gist. \nIt is a simple way to share code and text snippets with your friends, with support for the following:\n \n - Render GitHub Extended Markdown (including images)\n - User authentication\n - Private, public, and password protected posts\n - Markdown is rendered and stored on the server\n - Syntax highlighting and automatic language detection\n - Drag-and-drop file uploading\n\n If you want to signup, you can join at [/signup](/signup) as long as you have a passcode provided by the administrator (which you don\\\'t need for this demo). **This demo is on a memory-only database, so accounts and pastes can be deleted at any time.** \n\nYou can find the source code on [GitHub](https://github.com/MaxLeiter/drift)." SECRET_KEY=secret diff --git a/client/components/edit-document/index.tsx b/client/components/edit-document/index.tsx index 652b12a2..f2a412e9 100644 --- a/client/components/edit-document/index.tsx +++ b/client/components/edit-document/index.tsx @@ -19,12 +19,11 @@ type Props = { setContent?: (content: string) => void handleOnContentChange?: (e: ChangeEvent) => void initialTab?: "edit" | "preview" - skeleton?: boolean remove?: () => void onPaste?: (e: any) => void } -const Document = ({ onPaste, remove, title, content, setTitle, setContent, initialTab = 'edit', skeleton, handleOnContentChange }: Props) => { +const Document = ({ onPaste, remove, title, content, setTitle, setContent, initialTab = 'edit', handleOnContentChange }: Props) => { const codeEditorRef = useRef(null) const [tab, setTab] = useState(initialTab) // const height = editable ? "500px" : '100%' @@ -52,21 +51,21 @@ const Document = ({ onPaste, remove, title, content, setTitle, setContent, initi } }, [content]) - if (skeleton) { - return <> - -
-
- - {remove && } -
-
-
- -
-
- - } + // if (skeleton) { + // return <> + // + //
+ //
+ // + // {remove && } + //
+ //
+ //
+ // + //
+ //
+ // + // } return ( <> @@ -112,7 +111,6 @@ const Document = ({ onPaste, remove, title, content, setTitle, setContent, initi - diff --git a/client/components/header/header.tsx b/client/components/header/header.tsx index 9a9aae95..5608906b 100644 --- a/client/components/header/header.tsx +++ b/client/components/header/header.tsx @@ -129,7 +129,7 @@ const Header = () => { return ( - +
{ + return (<>
+ + + {introTitle} +
+ + + + {/* */} +
+