Skip to content

Commit

Permalink
feat(gluwave): 🎨 show skeleton before charts load
Browse files Browse the repository at this point in the history
  • Loading branch information
Kalhama committed Sep 26, 2024
1 parent 80797a1 commit 0f31031
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
14 changes: 11 additions & 3 deletions gluwave/src/app/(app-menu)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { validateRequest } from '@/auth'
import BloodGlucose from '@/components/blood-glucose'
import { CarbohydratesOnBoard } from '@/components/carbohydrates-on-board'
import { GraphSkeleton } from '@/components/graph-container'
import InsulinOnBoard from '@/components/insulin-on-board'
import { db } from '@/db'
import { glucose } from '@/schema'
import { addMinutes } from 'date-fns'
import { and, desc, eq, gte } from 'drizzle-orm'
import { Metadata } from 'next'
import { redirect } from 'next/navigation'
import { Suspense } from 'react'

const getLastGlucose = async (userId: string): Promise<number | undefined> => {
const [last] = await db
Expand Down Expand Up @@ -48,10 +50,16 @@ export async function generateMetadata(): Promise<Metadata> {
export default async function App() {
return (
<div className="mt-2 grid gap-2 mx-auto sm:grid-cols-2 max-w-5xl min-[420px]:px-2 md:px-4">
<BloodGlucose />
<InsulinOnBoard />
<Suspense fallback={<GraphSkeleton />}>
<BloodGlucose />
</Suspense>
<Suspense fallback={<GraphSkeleton />}>
<InsulinOnBoard />
</Suspense>
{/* <CarbsRate /> */}
<CarbohydratesOnBoard />
<Suspense fallback={<GraphSkeleton />}>
<CarbohydratesOnBoard />
</Suspense>
</div>
)
}
21 changes: 21 additions & 0 deletions gluwave/src/components/graph-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
VictoryZoomContainer,
} from 'victory'

import { Skeleton } from './ui/skeleton'
import { victoryTheme } from './victory-theme'

interface Props {
Expand Down Expand Up @@ -123,3 +124,23 @@ export const GraphContent = ({
}

export const padding = { top: 10, bottom: 25, left: 27, right: 15 }

interface GraphSkeletonProps {
height?: string
}

export const GraphSkeleton = ({ height }: GraphSkeletonProps) => {
return (
<GraphContainer>
<GraphTitle>
<div className="flex flex-col gap-2">
<Skeleton className="w-40 h-4" />
<Skeleton className="w-20 h-4" />
</div>
</GraphTitle>
<div className={cn('p-4')}>
<Skeleton className={cn('w-full h-[250px] rounded-xl', height)} />
</div>
</GraphContainer>
)
}
15 changes: 15 additions & 0 deletions gluwave/src/components/ui/skeleton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { cn } from '@/lib/utils'

function Skeleton({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) {
return (
<div
className={cn('animate-pulse rounded-md bg-muted', className)}
{...props}
/>
)
}

export { Skeleton }

0 comments on commit 0f31031

Please sign in to comment.