sort your posts by time, style improvements

This commit is contained in:
Max Leiter 2022-03-09 01:33:22 -08:00
parent 73e32a58e7
commit 7ef696f88e
No known key found for this signature in database
GPG key ID: A3512F2F2F17EBDA
9 changed files with 37 additions and 27 deletions

View file

@ -13,4 +13,4 @@ const MyPosts = () => {
return <PostList posts={data} error={error} /> return <PostList posts={data} error={error} />
} }
export default MyPosts export default MyPosts

View file

@ -1,4 +1,4 @@
import { Loading, Card, Divider, Input, Text } from "@geist-ui/core" import { Loading, Card, Divider, Input, Text, Grid, Spacer } from "@geist-ui/core"
import Preview from "../preview" import Preview from "../preview"
import ShiftBy from "../shift-by" import ShiftBy from "../shift-by"
import VisibilityBadge from "../visibility-badge" import VisibilityBadge from "../visibility-badge"
@ -12,6 +12,16 @@ type Props = {
} }
const PostList = ({ posts, error }: Props) => { const PostList = ({ posts, error }: Props) => {
const FilenameInput = ({ title }: { title: string }) => <Input
value={title}
marginTop="var(--gap-double)"
size={1.2}
font={1.2}
label="Filename"
readOnly
width={"100%"}
/>
return ( return (
<div className={styles.container}> <div className={styles.container}>
{error && <Text type='error'>Failed to load.</Text>} {error && <Text type='error'>Failed to load.</Text>}
@ -22,33 +32,34 @@ const PostList = ({ posts, error }: Props) => {
<ul> <ul>
{posts.map((post: any) => { {posts.map((post: any) => {
return <li key={post.id}> return <li key={post.id}>
<Card height={'300px'} style={{ overflowY: 'scroll' }} hoverable> <Card style={{ overflowY: 'scroll' }}>
<Text h3 className={styles.postHeader}> <Spacer height={1 / 2} />
<Link color href={`/post/${post.id}`}>{post.title} <ShiftBy y={-1}><VisibilityBadge visibility={post.visibility} /></ShiftBy></Link> <span>{new Date(post.createdAt).toLocaleDateString()}</span> <Grid.Container justify={'space-between'}>
</Text> <Grid xs={8}>
<Text h3 paddingLeft={1 / 2}>
<Link color href={`/post/${post.id}`}>{post.title}
<ShiftBy y={-1}><VisibilityBadge visibility={post.visibility} /></ShiftBy>
</Link>
</Text></Grid>
<Grid xs={7}><Text type="secondary" h5>{new Date(post.createdAt).toLocaleDateString()} </Text></Grid>
<Grid xs={4}><Text type="secondary" h5>{post.files.length === 1 ? "1 file" : `${post.files.length} files`}</Text></Grid>
</Grid.Container>
<Divider h="1px" my={0} /> <Divider h="1px" my={0} />
<Card.Content > <Card.Content >
<Input {post.files.map((file: any) => {
placeholder="MyFile.md" return <FilenameInput key={file.id} title={file.title} />
value={post.files[0].title} })}
marginTop="var(--gap-double)"
size={1.2}
font={1.2}
label="Filename"
disabled={true}
readOnly
width={"100%"}
/>
<Preview height={220} content={post.files[0].content} />
</Card.Content> </Card.Content>
</Card> </Card>
</li> </li>
})} })}
</ul> </ul>
</div> </div>
} }
</div> </div >
) )
} }

View file

@ -93,7 +93,7 @@ const Post = () => {
style={{ flex: .5, lineHeight: '40px' }} style={{ flex: .5, lineHeight: '40px' }}
type="default" type="default"
> >
Add another document Add a File
</Button> </Button>
<ButtonDropdown loading={isSubmitting} type="success"> <ButtonDropdown loading={isSubmitting} type="success">

View file

@ -20,7 +20,7 @@ const Home = ({ theme, changeTheme }: { theme: "light" | "dark", changeTheme: ()
<Page.Header> <Page.Header>
<Header theme={theme} changeTheme={changeTheme} /> <Header theme={theme} changeTheme={changeTheme} />
</Page.Header> </Page.Header>
<Page.Content width={"var(--main-content-width)"} margin="0 auto" className={styles.main}> <Page.Content paddingTop={"var(--gap)"} width={"var(--main-content-width)"} margin="0 auto" className={styles.main}>
{isLoading && <div style={{ margin: "0 auto" }}><Loader /></div>} {isLoading && <div style={{ margin: "0 auto" }}><Loader /></div>}
{isSignedIn && <MyPosts />} {isSignedIn && <MyPosts />}
</Page.Content> </Page.Content>

View file

@ -1,7 +1,7 @@
import Head from 'next/head' import Head from 'next/head'
import styles from '../styles/Home.module.css' import styles from '../styles/Home.module.css'
import HomeComponent from '../components/post' import HomeComponent from '../components/post'
import { Loading, Page } from '@geist-ui/core' import { Page } from '@geist-ui/core'
import useSignedIn from '../lib/hooks/use-signed-in' import useSignedIn from '../lib/hooks/use-signed-in'
import Header from '../components/header' import Header from '../components/header'
import { ThemeProps } from './_app' import { ThemeProps } from './_app'
@ -25,7 +25,7 @@ const Home = ({ theme, changeTheme }: ThemeProps) => {
<Header theme={theme} changeTheme={changeTheme} /> <Header theme={theme} changeTheme={changeTheme} />
</Page.Header> </Page.Header>
<Page.Content width={"var(--main-content-width)"} margin="0 auto" className={styles.main}> <Page.Content paddingTop={"var(--gap)"} width={"var(--main-content-width)"} margin="0 auto" className={styles.main}>
{isSignedIn && <HomeComponent />} {isSignedIn && <HomeComponent />}
</Page.Content> </Page.Content>
</Page > </Page >

View file

@ -8,7 +8,7 @@ const SignIn = ({ theme, changeTheme }: ThemeProps) => (
<Page.Header> <Page.Header>
<Header theme={theme} changeTheme={changeTheme} /> <Header theme={theme} changeTheme={changeTheme} />
</Page.Header> </Page.Header>
<Page.Content width={"var(--main-content-width)"} margin="auto"> <Page.Content paddingTop={"var(--gap)"} width={"var(--main-content-width)"} margin="auto">
<Auth page="signin" /> <Auth page="signin" />
</Page.Content> </Page.Content>
</Page> </Page>

View file

@ -8,7 +8,7 @@ const SignUp = ({ theme, changeTheme }: ThemeProps) => (
<Page.Header> <Page.Header>
<Header theme={theme} changeTheme={changeTheme} /> <Header theme={theme} changeTheme={changeTheme} />
</Page.Header> </Page.Header>
<Page.Content width={"var(--main-content-width)"} margin="auto"> <Page.Content width={"var(--main-content-width)"} paddingTop={"var(--gap)"} margin="auto">
<Auth page="signup" /> <Auth page="signup" />
</Page.Content> </Page.Content>
</Page> </Page>

View file

@ -1,6 +1,5 @@
.main { .main {
min-height: 100vh; min-height: 100vh;
padding: 4rem 0;
flex: 1; flex: 1;
display: flex; display: flex;
flex-direction: column; flex-direction: column;

View file

@ -42,7 +42,7 @@ users.get("/mine", jwt, async (req: UserJwtRequest, res, next) => {
if (!user) { if (!user) {
return res.status(404).json({ error: "User not found" }) return res.status(404).json({ error: "User not found" })
} }
return res.json(user.posts) return res.json(user.posts?.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime()))
} catch (error) { } catch (error) {
next(error) next(error)
} }