-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
29-feature/swearjar/[id]/view-page (#31)
* feat(rest pkg): Create `GetUserIdFromCookie` method and implemented in `GetSwearJarsByUserId` method * feat(backend): Add functionality to get a Swear Jar by it's ID via GET `/swearjar`, provided a query parameter is provided - rest pkg: Update `swearjar` route and add `GetSwearJarById` method in handler - swearjar pkg: Update Service and Repository interfaces to include `GetSwearJarById` method - mongodb pkg: Implement `GetSwearJarById` method in MongoRepository * feat(api): Update GET `api/swearJar` endpoint to handle requests dynamically based on the presence of a `swearJarId` query parameter - Previously, the endpoint did not check for an `id` query parameter. - Now, if an `id` is provided, the endpoint calls `/swearjar?id={id}` to retrieve a specific swear jar - If no `id` is provided, it calls `/swearjar` to retrieve swear jars by user ID - Corresponding backend logic differentiates handling based on the presence of `swearJarId` * refactor: Update endpoint used to get list of swearjars * style: Update style of Button's outline variant * chore: Install shadcn charts and move shadcn components to `ui/shadcn` * feat/fix: Add patch-package and postinstall-postinstall to apply a patch-fix to recharts resolve disappearing grid line issue * refactor: Update ErrorAlert to accept className prop * feat: Create SwearJarProp type and update `swearjar/list` to use it * feat: Update chart colours in globals.css * feat: Prefetch and render SwearJarData on `swearjar/[id]/view` page - Added error handling with `ErrorAlert` to display messages when data fetching fails * feat: Create SwearJarInfo and SwearJarTrends components * feat: Implement grid layout for `swearjar/[id]/view` mainContent and render BreadcrumbHeader, SwearJarTrends, and SwearJarInfo components * fix: Update POST endpoint to new `/api/swearjar` * feat: Add hoverOnlyWhenSupported to resolve sticky-hover issue * style: Add new "plain" variant to shadcn's button and update SwearJarInfo and SwearJarTrends buttons * style: Add mb-7 to swearjar/layout * style: Re-order components on `/swearjar/[id]/view` page * feat: Create SwearJarRecent component and update `swearjar/[id]/view` page to include it * style: add active state for SwearJarCard * feat: Update loading state for `swearjar/[id]/view`
- Loading branch information
1 parent
183a656
commit 995f8df
Showing
33 changed files
with
1,327 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"use client" | ||
import { fetcher } from "@/lib/utils"; | ||
import { useQuery } from "@tanstack/react-query"; | ||
|
||
import BreadcrumbHeader from "@/components/layout/header/breadcrumbHeader"; | ||
import { SwearJar } from "@/lib/types"; | ||
import SwearJarInfo from "@/components/app/swearjar/view/SwearJarInfo"; | ||
import SwearJarTrends from "@/components/app/swearjar/view/SwearJarTrends"; | ||
import SwearJarRecent from "@/components/app/swearjar/view/SwearJarRecent"; | ||
interface SwearJarApiResponse { | ||
msg: string; | ||
swearJar: SwearJar; | ||
} | ||
|
||
export default function MainContent({ swearJarId }: { swearJarId: string }) { | ||
const { data, isLoading } = useQuery<SwearJarApiResponse>({ | ||
queryKey: [`swearjar?id=${swearJarId}`], | ||
queryFn: () => fetcher<SwearJarApiResponse>(`/api/swearjar?id=${swearJarId}`), | ||
refetchOnWindowFocus: "always", | ||
}); | ||
if (isLoading) return <span className="daisy-loading daisy-loading-dots daisy-loading-lg text-primary"></span>; | ||
if (!data?.swearJar) return <p>Swear Jar does not exist</p>; | ||
return ( | ||
<div className="grid grid-cols-1 md:grid-cols-5 gap-y-3 gap-x-4"> | ||
<div className="col-span-1 md:col-span-5 order-1"> | ||
<BreadcrumbHeader title={data.swearJar.Name} subtitle={data.swearJar.Desc} /> | ||
</div> | ||
<div className="col-span-1 md:col-span-3 order-3 md:order-2"> | ||
<SwearJarTrends /> | ||
</div> | ||
<div className="col-span-1 md:col-span-2 order-2 md:order-3 space-y-2"> | ||
<SwearJarInfo {...data.swearJar} /> | ||
<span className="hidden md:block"> | ||
<SwearJarRecent /> | ||
</span> | ||
</div> | ||
{/* <div className="col-span-0 block md:hidden md:col-span-1 md:order-4"></div> */} | ||
<div className="col-span-1 block md:hidden order-4"> | ||
<SwearJarRecent /> | ||
</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { | ||
dehydrate, | ||
HydrationBoundary, | ||
QueryClient, | ||
} from '@tanstack/react-query' | ||
import { fetcher } from "@/lib/utils"; | ||
import { SwearJar } from '@/lib/types'; | ||
|
||
|
||
import DefaultContentLayout from "@/components/layout/content"; | ||
import MainContent from "./mainContent"; | ||
import ErrorAlert from '@/components/shared/ErrorAlert'; | ||
|
||
interface SwearJarApiResponse { | ||
msg: string; | ||
swearJar: SwearJar; | ||
} | ||
|
||
export default async function SwearJarPage({ params }: { params: { id: string } }) { | ||
const queryClient = new QueryClient() | ||
let errorMessage: string | null = null; | ||
try { | ||
await queryClient.prefetchQuery<SwearJarApiResponse>({ | ||
queryKey: [`swearjar?id=${params.id}`], | ||
queryFn: () => fetcher<SwearJarApiResponse>(`/api/swearjar?id=${params.id}`), | ||
}) | ||
} catch (error) { | ||
console.error("Error during prefetch:", error); | ||
errorMessage = "Error fetching Swear Jar data" | ||
} | ||
|
||
if (errorMessage) { | ||
return <ErrorAlert message={errorMessage} className='h-10' /> | ||
} | ||
return ( | ||
<HydrationBoundary state={dehydrate(queryClient)}> | ||
<section className="w-full md:w-[768px] lg:w-[864px]"> | ||
<DefaultContentLayout> | ||
<MainContent swearJarId={params.id} /> | ||
</DefaultContentLayout> | ||
</section> | ||
</HydrationBoundary> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.