diff --git a/README.md b/README.md index 77bceb5e..c725e157 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,12 @@ Drift is a self-hostable Gist clone. It's also a major work-in-progress, but is You can try a demo at https://drift.maxleiter.com. The demo is built on master but has no database, so files and accounts can be wiped at any time. -If you want to contribute, need support, or want to stay updated, you can join the IRC channel at #drift on irc.libera.chat or [reach me on twitter](https://twitter.com/Max_Leiter). If you don't have an IRC client yet, you can use a webclient [here](https://demo.thelounge.chat/#/connect?join=%23drift&nick=drift-user&realname=Drift%20User). +If you want to contribute, need support, or want to stay updated, you can join the IRC channel at #drift on irc.libera.chat or [reach me on twitter](https://twitter.com/Max_Leiter). If you don't have an IRC client yet, you can use a webclient [here](https://demo.thelounge.chat/#/connect?join=%23drift&nick=drift-user&realname=Drift%20User). +
**Contents:** + - [Setup](#setup) - [Development](#development) - [Production](#production) @@ -27,7 +29,7 @@ To migrate the sqlite database in development, you can use `yarn migrate` to see ### Production -`yarn build` in both `client/` and `server/` will produce production code for the client and server respectively. +`yarn build` in both `client/` and `server/` will produce production code for the client and server respectively. If you're deploying the front-end to something like Vercel, you'll need to set the root folder to `client/`. @@ -50,8 +52,6 @@ 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 `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 additional 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. - `ENABLE_ADMIN`: the first account created is an administrator account - `DRIFT_HOME`: defaults to ~/.drift, the directory for storing the database and eventually images diff --git a/client/components/admin/action-dropdown/index.tsx b/client/components/admin/action-dropdown/index.tsx index 48c57335..41516896 100644 --- a/client/components/admin/action-dropdown/index.tsx +++ b/client/components/admin/action-dropdown/index.tsx @@ -2,42 +2,37 @@ import { Popover, Button } from "@geist-ui/core" import { MoreVertical } from "@geist-ui/icons" type Action = { - title: string - onClick: () => void + title: string + onClick: () => void } const ActionDropdown = ({ - title = "Actions", - actions, - showTitle = false, + title = "Actions", + actions, + showTitle = false }: { - title?: string, - showTitle?: boolean, - actions: Action[] + title?: string + showTitle?: boolean + actions: Action[] }) => { - return ( - - {showTitle && - {title} - } - {actions.map(action => ( - - {action.title} - - ))} - - } - hideArrow - > - - - ) + return ( + + {showTitle && {title}} + {actions.map((action) => ( + + {action.title} + + ))} + + } + hideArrow + > + + + ) } -export default ActionDropdown \ No newline at end of file +export default ActionDropdown diff --git a/client/components/admin/index.tsx b/client/components/admin/index.tsx index 338babe9..bb09b59d 100644 --- a/client/components/admin/index.tsx +++ b/client/components/admin/index.tsx @@ -2,6 +2,7 @@ import { Text, Spacer } from "@geist-ui/core" import Cookies from "js-cookie" import styles from "./admin.module.css" import PostTable from "./post-table" +import ServerInfo from "./server-info" import UserTable from "./user-table" export const adminFetcher = async ( @@ -24,6 +25,8 @@ const Admin = () => { return (
Administration + + diff --git a/client/components/admin/post-table.tsx b/client/components/admin/post-table.tsx index c66f99ea..a7f5c4a6 100644 --- a/client/components/admin/post-table.tsx +++ b/client/components/admin/post-table.tsx @@ -9,7 +9,7 @@ import ActionDropdown from "./action-dropdown" const PostTable = () => { const [posts, setPosts] = useState() - const { setToast } = useToasts() + // const { setToast } = useToasts() useEffect(() => { const fetchPosts = async () => { @@ -35,8 +35,8 @@ const PostTable = () => { visibility: post.visibility, size: post.files ? byteToMB( - post.files.reduce((acc, file) => acc + file.html.length, 0) - ) + post.files.reduce((acc, file) => acc + file.html.length, 0) + ) : 0, actions: "" } @@ -109,14 +109,14 @@ const PostTable = () => { dataIndex: "", key: "actions", width: 50, - render(post: Post) { + render() { return ( deletePost(post.id) + onClick: () => deletePost() } ]} /> @@ -128,7 +128,11 @@ const PostTable = () => { return ( {!posts && Loading...} - {posts &&
{posts.length} posts
} + {posts && ( + +
{posts.length} posts
+
+ )} {posts && } ) diff --git a/client/components/admin/server-info.tsx b/client/components/admin/server-info.tsx new file mode 100644 index 00000000..2b7bf96b --- /dev/null +++ b/client/components/admin/server-info.tsx @@ -0,0 +1,75 @@ +import SettingsGroup from "@components/settings-group" +import { Button, Input, Spacer, Textarea, useToasts } from "@geist-ui/core" +import { useEffect, useState } from "react" +import { adminFetcher } from "." + +const Homepage = () => { + const [description, setDescription] = useState("") + const [title, setTitle] = useState("") + const { setToast } = useToasts() + useEffect(() => { + const fetchServerInfo = async () => { + const res = await adminFetcher("/server-info") + const data = await res.json() + setDescription(data.welcomeMessage) + setTitle(data.welcomeTitle) + } + fetchServerInfo() + }, []) + + const onSubmit = async (e: React.FormEvent) => { + e.preventDefault() + + const res = await adminFetcher("/server-info", { + method: "PUT", + body: { + description, + title + } + }) + + if (res.status === 200) { + setToast({ + type: "success", + text: "Server info updated" + }) + setDescription(description) + setTitle(title) + } else { + setToast({ + text: "Something went wrong", + type: "error" + }) + } + } + + return ( + +
+
+ + setTitle(e.target.value)} + /> +
+ +
+ +