Skip to content

Commit

Permalink
loaders
Browse files Browse the repository at this point in the history
  • Loading branch information
omranjamal committed Aug 23, 2024
1 parent b37ff7f commit 1f46841
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 44 deletions.
10 changes: 8 additions & 2 deletions apps/jonogon-web-next/src/app/components/PetitionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ export default function PetitionCard(props: {
const totalVotes = props.upvotes + props.downvotes;

return (
<Card className={''}>
<Card
className={'cursor-pointer'}
onClick={() => {
router.push(`/petitions/${props.id}`);
}}>
<CardHeader className={''}>
{props.attachment && (
<img
Expand Down Expand Up @@ -77,7 +81,9 @@ export default function PetitionCard(props: {
<Button
size={'sm'}
variant={'outline'}
onClick={() => {
onClick={(ev) => {
ev.stopPropagation();

const href = `/petitions/${props.id}`;

isAuthenticated
Expand Down
68 changes: 44 additions & 24 deletions apps/jonogon-web-next/src/app/components/PetitionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ const PetitionList = () => {

const page = params.get('page') ? Number(params.get('page')) : 0;

const {data: petitionRequestListResponse} = trpc.petitions.list.useQuery({
filter: type,
page: page,
sort: params.get('sort') === 'latest' ? 'time' : 'votes',
});
const {data: petitionRequestListResponse, isLoading} =
trpc.petitions.list.useQuery({
filter: type,
page: page,
sort: params.get('sort') === 'latest' ? 'time' : 'votes',
});

const petitions = petitionRequestListResponse?.data ?? [];

Expand All @@ -48,25 +49,44 @@ const PetitionList = () => {
gridTemplateColumns: 'repeat(auto-fit, minmax(300px, 1fr))',
gap: '15px',
}}>
{petitions.slice(0, 32).map((p) => {
return (
<PetitionCard
id={p.data.id}
mode={type}
status={p.data.status}
name={p.extras.user.name ?? ''}
title={p.data.title ?? 'Untitled Petition'}
attachment={p.data.attachment ?? ''}
date={new Date(p.data.submitted_at ?? '1970-01-01')}
target={p.data.target ?? 'Some Ministry'}
key={p.data.id ?? 0}
upvotes={Number(p.data.petition_upvote_count) ?? 0}
downvotes={
Number(p.data.petition_downvote_count) ?? 0
}
/>
);
})}
{isLoading
? Array(4)
.fill(null)
.map((_, i) => {
return (
<div
className={
'w-full bg-border animate-pulse h-32'
}
key={i}></div>
);
})
: petitions.slice(0, 32).map((p) => {
return (
<PetitionCard
id={p.data.id}
mode={type}
status={p.data.status}
name={p.extras.user.name ?? ''}
title={p.data.title ?? 'Untitled Petition'}
attachment={p.data.attachment ?? ''}
date={
new Date(
p.data.submitted_at ?? '1970-01-01',
)
}
target={p.data.target ?? 'Some Ministry'}
key={p.data.id ?? 0}
upvotes={
Number(p.data.petition_upvote_count) ?? 0
}
downvotes={
Number(p.data.petition_downvote_count) ??
0
}
/>
);
})}
</div>
<div className={'py-4'}>
<Pagination>
Expand Down
12 changes: 10 additions & 2 deletions apps/jonogon-web-next/src/app/petitions/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use client';

import Loading from '@/app/petitions/[id]/loading';

export const runtime = 'edge';

import {useEffect, useState} from 'react';
Expand All @@ -23,7 +25,11 @@ export default function Petition() {

const {id: petition_id} = useParams<{id: string}>();

const {data: petition, refetch} = trpc.petitions.get.useQuery({
const {
data: petition,
refetch,
isLoading,
} = trpc.petitions.get.useQuery({
id: petition_id!!,
});

Expand Down Expand Up @@ -117,7 +123,9 @@ export default function Petition() {
},
});

return (
return isLoading ? (
<Loading />
) : (
<>
<div className="max-w-screen-sm mx-auto px-4 pt-12 mb-28 flex flex-col gap-4">
{isOwnPetition || isMod || isAdmin ? (
Expand Down
2 changes: 1 addition & 1 deletion apps/jonogon-web-next/src/components/custom/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const Navigation = () => {
<div className={'flex flex-col -space-y-2'}>
<span className="text-3xl font-black">জনগণ</span>
<span className="text-neutral-600">
আমাদের দাবির প্লাটফর্ম
সবার দাবির প্লাটফর্ম
</span>
</div>
</Link>
Expand Down
15 changes: 0 additions & 15 deletions apps/jonogon-web-next/src/components/custom/Preloader.tsx

This file was deleted.

0 comments on commit 1f46841

Please sign in to comment.