From 0566670286608e44ae2245558b04b6fda4b1b51a Mon Sep 17 00:00:00 2001 From: amirfakhrullah Date: Sat, 18 Jun 2022 00:41:30 +0800 Subject: [PATCH] loading handling My Posts page and Header --- src/components/Header.tsx | 4 +-- src/components/loaders/TagsLeftNavLoader.tsx | 2 +- src/pages/index.tsx | 3 -- src/pages/posts/index.tsx | 32 ++++++++++++-------- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/components/Header.tsx b/src/components/Header.tsx index 2e6855a..b36f58f 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -7,7 +7,7 @@ import Image from "next/image"; const Header: React.FC<{ displayButtons?: boolean; }> = ({ displayButtons = true }) => { - const { data: session } = useSession(); + const { data: session, status } = useSession(); const router = useRouter(); return ( @@ -18,7 +18,7 @@ const Header: React.FC<{ BloqDown - {displayButtons && ( + {displayButtons && status !== "loading" && (
{session && session.user ? (
diff --git a/src/components/loaders/TagsLeftNavLoader.tsx b/src/components/loaders/TagsLeftNavLoader.tsx index aa3ec19..9cfd3c6 100644 --- a/src/components/loaders/TagsLeftNavLoader.tsx +++ b/src/components/loaders/TagsLeftNavLoader.tsx @@ -10,7 +10,7 @@ const TagsLeftNavLoader = () => { >
-
+
))}
diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 37ddaad..f74ca12 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -1,4 +1,3 @@ -import Loader from "../components/loaders/Loader"; import MetaHead from "../components/MetaHead"; import PostForm from "../components/PostForm"; import PostCard from "../components/PostCard"; @@ -32,8 +31,6 @@ const Home: React.FC = () => { const { filterBoolean, handleTag } = useFilterTags(); - // if (isLoading) return ; - return ( <> diff --git a/src/pages/posts/index.tsx b/src/pages/posts/index.tsx index 50d1fbe..c5b415f 100644 --- a/src/pages/posts/index.tsx +++ b/src/pages/posts/index.tsx @@ -2,7 +2,7 @@ import { useSession } from "next-auth/react"; import React from "react"; import Container from "../../components/Container"; import Header from "../../components/Header"; -import Loader from "../../components/loaders/Loader"; +import PostCardLoader from "../../components/loaders/PostCardLoader"; import MetaHead from "../../components/MetaHead"; import PostButton from "../../components/PostButton"; import PostCard from "../../components/PostCard"; @@ -17,9 +17,7 @@ const MyPosts: React.FC = () => { const { open, setOpen } = useFormModal(); const { data: posts, isLoading } = trpc.useQuery(["post.get-my-posts"]); - const { data: session } = useSession(); - - if (isLoading) return ; + const { data: session, status } = useSession(); return ( <> @@ -38,7 +36,7 @@ const MyPosts: React.FC = () => {

My Posts

- {!session && ( + {status !== "loading" && !session && (

If you post as anonymous, your post might not appear here because of cookie changed. To get full control of your posts and @@ -46,14 +44,24 @@ const MyPosts: React.FC = () => {

)} - {posts?.length === 0 && ( -

- No Post Yet -

+ {isLoading ? ( + + ) : ( + <> + {posts?.length === 0 && ( +

+ No Post Yet +

+ )} + {posts?.map((post) => ( + + ))} + )} - {posts?.map((post) => ( - - ))}