From 0e7b879aa8d771b58fc5783f78f981cb29432361 Mon Sep 17 00:00:00 2001 From: Sebastien Castiel Date: Thu, 7 Dec 2023 20:54:11 -0500 Subject: Redesign the groups page --- src/app/groups/recent-group-list.tsx | 72 ++++++++++++++++++++++++++++-------- 1 file changed, 56 insertions(+), 16 deletions(-) (limited to 'src/app/groups/recent-group-list.tsx') diff --git a/src/app/groups/recent-group-list.tsx b/src/app/groups/recent-group-list.tsx index e728193..ef43372 100644 --- a/src/app/groups/recent-group-list.tsx +++ b/src/app/groups/recent-group-list.tsx @@ -1,6 +1,8 @@ 'use client' import { getRecentGroups } from '@/app/groups/recent-groups-helpers' import { Button } from '@/components/ui/button' +import { getGroups } from '@/lib/api' +import { Loader2 } from 'lucide-react' import Link from 'next/link' import { useEffect, useState } from 'react' import { z } from 'zod' @@ -13,31 +15,69 @@ const recentGroupsSchema = z.array( ) type RecentGroups = z.infer -type State = { status: 'pending' } | { status: 'success'; groups: RecentGroups } +type State = + | { status: 'pending' } + | { status: 'partial'; groups: RecentGroups } + | { + status: 'complete' + groups: RecentGroups + groupsDetails: Awaited> + } -export function RecentGroupList() { +type Props = { + getGroupsAction: (groupIds: string[]) => ReturnType +} + +export function RecentGroupList({ getGroupsAction }: Props) { const [state, setState] = useState({ status: 'pending' }) useEffect(() => { const groupsInStorage = getRecentGroups() - setState({ status: 'success', groups: groupsInStorage }) - }, []) + setState({ status: 'partial', groups: groupsInStorage }) + getGroupsAction(groupsInStorage.map((g) => g.id)).then((groupsDetails) => { + setState({ status: 'complete', groups: groupsInStorage, groupsDetails }) + }) + }, [getGroupsAction]) + + if (state.status === 'pending') + return ( +

+ Loading recent + groups… +

+ ) return ( -
    - {state.status === 'pending' ? ( -
  • - Loading recent groups… -
  • - ) : ( - state.groups.map(({ id, name }) => ( -
  • -
  • - )) - )} + ) + })}
) } -- cgit v1.3