Skip to content

Commit

Permalink
loading handling My Posts page and Header
Browse files Browse the repository at this point in the history
  • Loading branch information
amirfakhrullah committed Jun 17, 2022
1 parent 650dbf2 commit 0566670
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -18,7 +18,7 @@ const Header: React.FC<{
BloqDown
</h1>
</Link>
{displayButtons && (
{displayButtons && status !== "loading" && (
<div className="flex flex-row items-center pl-1">
{session && session.user ? (
<div className="md:flex hidden flex-row items-center">
Expand Down
2 changes: 1 addition & 1 deletion src/components/loaders/TagsLeftNavLoader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const TagsLeftNavLoader = () => {
>
<div className="h-3 w-3 bg-gray-700 rounded-sm" />

<div className="ml-2 h-3 flex-1 bg-gray-700 rounded-sm" />
<div className="ml-2 h-4 flex-1 bg-gray-700 rounded-sm" />
</div>
))}
</div>
Expand Down
3 changes: 0 additions & 3 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -32,8 +31,6 @@ const Home: React.FC = () => {

const { filterBoolean, handleTag } = useFilterTags();

// if (isLoading) return <Loader />;

return (
<>
<MetaHead title="BloqDown" />
Expand Down
32 changes: 20 additions & 12 deletions src/pages/posts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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 <Loader />;
const { data: session, status } = useSession();

return (
<>
Expand All @@ -38,22 +36,32 @@ const MyPosts: React.FC = () => {

<h1 className="mt-5 text-2xl font-black text-gray-300">My Posts</h1>

{!session && (
{status !== "loading" && !session && (
<p className="text-sm my-1">
If you post as anonymous, your post might not appear here
because of cookie changed. To get full control of your posts and
comments, please login.
</p>
)}

{posts?.length === 0 && (
<h3 className="text-center font-bold text-lg text-gray-500 my-10">
No Post Yet
</h3>
{isLoading ? (
<PostCardLoader />
) : (
<>
{posts?.length === 0 && (
<h3 className="text-center font-bold text-lg text-gray-500 my-10">
No Post Yet
</h3>
)}
{posts?.map((post) => (
<PostCard
key={post.id}
{...(post as GetPostType)}
page="myPage"
/>
))}
</>
)}
{posts?.map((post) => (
<PostCard key={post.id} {...(post as GetPostType)} page="myPage" />
))}
</div>

<RightNav />
Expand Down

0 comments on commit 0566670

Please sign in to comment.