From cb6faa50b06db277820ee213d056baac109dccc7 Mon Sep 17 00:00:00 2001 From: Max Leiter Date: Wed, 9 Mar 2022 17:11:37 -0800 Subject: [PATCH] client: add some loading skeletons --- .../components/document/document.module.css | 1 + client/components/document/index.tsx | 22 ++++++-- client/components/post-list/index.tsx | 53 +++++-------------- .../post-list/list-item-skeleton.tsx | 19 +++++++ client/components/post-list/list-item.tsx | 43 +++++++++++++++ .../preview/react-markdown-preview.tsx | 2 +- client/package.json | 1 + client/pages/_app.tsx | 2 + client/pages/mine.tsx | 7 +-- client/pages/post/[id].tsx | 13 +++-- client/yarn.lock | 5 ++ 11 files changed, 113 insertions(+), 55 deletions(-) create mode 100644 client/components/post-list/list-item-skeleton.tsx create mode 100644 client/components/post-list/list-item.tsx diff --git a/client/components/document/document.module.css b/client/components/document/document.module.css index ea8cbf60..60f6e539 100644 --- a/client/components/document/document.module.css +++ b/client/components/document/document.module.css @@ -13,6 +13,7 @@ display: flex; justify-content: space-between; align-items: center; + height: 36px; } .fileNameContainer { diff --git a/client/components/document/index.tsx b/client/components/document/index.tsx index 90c1fc17..14ad7f2f 100644 --- a/client/components/document/index.tsx +++ b/client/components/document/index.tsx @@ -4,17 +4,19 @@ import styles from './document.module.css' import MarkdownPreview from '../preview' import { Trash } from '@geist-ui/icons' import FormattingIcons from "../formatting-icons" +import Skeleton from "react-loading-skeleton" type Props = { - editable: boolean + editable?: boolean remove?: () => void title?: string content?: string setTitle?: (title: string) => void setContent?: (content: string) => void initialTab?: "edit" | "preview" + skeleton?: boolean } -const Document = ({ remove, editable, title, content, setTitle, setContent, initialTab = 'edit' }: Props) => { +const Document = ({ remove, editable, title, content, setTitle, setContent, initialTab = 'edit', skeleton }: Props) => { const codeEditorRef = useRef(null) const [tab, setTab] = useState(initialTab) const height = editable ? "500px" : '100%' @@ -46,7 +48,21 @@ const Document = ({ remove, editable, title, content, setTitle, setContent, init } } } - + if (skeleton) { + return <> + + +
+ + {editable && } +
+
+
+ +
+
+ + } return ( <> diff --git a/client/components/post-list/index.tsx b/client/components/post-list/index.tsx index 8f8befe7..eee4e536 100644 --- a/client/components/post-list/index.tsx +++ b/client/components/post-list/index.tsx @@ -1,10 +1,9 @@ -import { Loading, Card, Divider, Input, Text, Grid, Spacer } from "@geist-ui/core" -import Preview from "../preview" -import ShiftBy from "../shift-by" -import VisibilityBadge from "../visibility-badge" +import { Text } from "@geist-ui/core" import Link from '../Link' import styles from './post-list.module.css' +import ListItemSkeleton from "./list-item-skeleton" +import ListItem from "./list-item" type Props = { posts: any @@ -12,49 +11,23 @@ type Props = { } const PostList = ({ posts, error }: Props) => { - const FilenameInput = ({ title }: { title: string }) => - return (
{error && Failed to load.} - {!posts && } + {!posts &&
    +
  • + +
  • +
  • + +
  • +
} {posts?.length === 0 && You have no posts. Create one here.} { posts?.length > 0 &&
    {posts.map((post: any) => { - return
  • - - - - - - {post.title} - - - - {new Date(post.createdAt).toLocaleDateString()} - {post.files.length === 1 ? "1 file" : `${post.files.length} files`} - - - - - - {post.files.map((file: any) => { - return - })} - - - -
  • + return })}
@@ -63,4 +36,4 @@ const PostList = ({ posts, error }: Props) => { ) } -export default PostList \ No newline at end of file +export default PostList diff --git a/client/components/post-list/list-item-skeleton.tsx b/client/components/post-list/list-item-skeleton.tsx new file mode 100644 index 00000000..5d834c4a --- /dev/null +++ b/client/components/post-list/list-item-skeleton.tsx @@ -0,0 +1,19 @@ +import { Card, Spacer, Grid, Divider } from "@geist-ui/core"; +import Skeleton from "react-loading-skeleton"; + +const ListItemSkeleton = () => ( + + + + + + + + + + + + +) + +export default ListItemSkeleton \ No newline at end of file diff --git a/client/components/post-list/list-item.tsx b/client/components/post-list/list-item.tsx new file mode 100644 index 00000000..65c5c615 --- /dev/null +++ b/client/components/post-list/list-item.tsx @@ -0,0 +1,43 @@ +import { Card, Spacer, Grid, Divider, Link, Text, Input } from "@geist-ui/core" +import post from "../post" +import ShiftBy from "../shift-by" +import VisibilityBadge from "../visibility-badge" + +const FilenameInput = ({ title }: { title: string }) => + +const ListItem = ({ post }: { post: any }) => { + return (
  • + + + + + + {post.title} + + + + {new Date(post.createdAt).toLocaleDateString()} + {post.files.length === 1 ? "1 file" : `${post.files.length} files`} + + + + + + {post.files.map((file: any) => { + return + })} + + + +
  • ) +} + +export default ListItem \ No newline at end of file diff --git a/client/components/preview/react-markdown-preview.tsx b/client/components/preview/react-markdown-preview.tsx index 2b0d9f13..65dabe0e 100644 --- a/client/components/preview/react-markdown-preview.tsx +++ b/client/components/preview/react-markdown-preview.tsx @@ -23,7 +23,7 @@ const ReactMarkdownPreview = ({ content, height }: Props) => { return !inline && match ? ( void diff --git a/client/pages/mine.tsx b/client/pages/mine.tsx index cf4b6bd6..19c02cb1 100644 --- a/client/pages/mine.tsx +++ b/client/pages/mine.tsx @@ -3,13 +3,9 @@ import styles from '../styles/Home.module.css' import { Page } from '@geist-ui/core' import Header from '../components/header' -import useSignedIn from '../lib/hooks/use-signed-in' -import { Loader } from '@geist-ui/icons' import MyPosts from '../components/my-posts' const Home = ({ theme, changeTheme }: { theme: "light" | "dark", changeTheme: () => void }) => { - const { isLoading, isSignedIn } = useSignedIn({ redirectIfNotAuthed: true }) - return ( @@ -21,8 +17,7 @@ const Home = ({ theme, changeTheme }: { theme: "light" | "dark", changeTheme: ()
    - {isLoading &&
    } - {isSignedIn && } +
    ) diff --git a/client/pages/post/[id].tsx b/client/pages/post/[id].tsx index b127e66f..e4ec7b1b 100644 --- a/client/pages/post/[id].tsx +++ b/client/pages/post/[id].tsx @@ -1,7 +1,8 @@ -import { Loading, Page, Text } from "@geist-ui/core"; +import { Page, Text } from "@geist-ui/core"; +import Skeleton from 'react-loading-skeleton'; import { useRouter } from "next/router"; -import { useCallback, useEffect, useState } from "react"; +import { useEffect, useState } from "react"; import Document from '../../components/document' import Header from "../../components/header"; import VisibilityBadge from "../../components/visibility-badge"; @@ -51,7 +52,10 @@ const Post = ({ theme, changeTheme }: ThemeProps) => { {error && {error}} - {!error && (isLoading || !post?.files) && } + {/* {!error && (isLoading || !post?.files) && } */} + {!error && isLoading && <> + + } {!isLoading && post && <>{post.title} {post.files.map(({ id, content, title }: { id: any, content: string, title: string }) => ( { initialTab={'preview'} /> ))} - - } + } diff --git a/client/yarn.lock b/client/yarn.lock index 25617e03..50e23b31 100644 --- a/client/yarn.lock +++ b/client/yarn.lock @@ -2268,6 +2268,11 @@ react-lifecycles-compat@^3.0.4: resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362" integrity sha512-fBASbA6LnOU9dOU2eW7aQ8xmYBSXUIWr+UmF9b1efZBazGNO+rcXT/icdKnYm2pTwcRylVUYwW7H1PHfLekVzA== +react-loading-skeleton@^3.0.3: + version "3.0.3" + resolved "https://registry.yarnpkg.com/react-loading-skeleton/-/react-loading-skeleton-3.0.3.tgz#4f45467cf3193fb25456bc02aeb81922b82b8f1f" + integrity sha512-HPkEqQGwmbg1ImcYA9n4hDiLC3u92xUdU+sSfrv/9l3lNBChAubcl1azjV2WakapdkbA3gko+hPzZkZGIb/9xA== + react-markdown@^8.0.0: version "8.0.0" resolved "https://registry.yarnpkg.com/react-markdown/-/react-markdown-8.0.0.tgz#3243296a59ddb0f451d262cc2e11123674b416c2"