From 69fa008ea4e1a167e6076a69869388bf012d24b1 Mon Sep 17 00:00:00 2001 From: Sebastien Castiel Date: Mon, 11 Dec 2023 10:26:13 -0500 Subject: Tiny adjustments --- src/app/globals.css | 2 +- src/app/groups/actions.ts | 7 +++++++ src/app/groups/layout.tsx | 2 +- src/app/groups/page.tsx | 12 +++--------- src/app/groups/recent-group-list.tsx | 31 +++++++++++++++++++++++++------ src/lib/api.ts | 7 +++++-- 6 files changed, 42 insertions(+), 19 deletions(-) create mode 100644 src/app/groups/actions.ts (limited to 'src') diff --git a/src/app/globals.css b/src/app/globals.css index fd6f706..ddf9eee 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -11,7 +11,7 @@ --popover: 0 0% 100%; --popover-foreground: 240 10% 3.9%; --primary: 163 94% 24%; - --primary-foreground: 355.7 100% 97.3%; + --primary-foreground: 0 100% 100%; --secondary: 240 4.8% 95.9%; --secondary-foreground: 240 5.9% 10%; --muted: 240 4.8% 95.9%; diff --git a/src/app/groups/actions.ts b/src/app/groups/actions.ts new file mode 100644 index 0000000..2d07004 --- /dev/null +++ b/src/app/groups/actions.ts @@ -0,0 +1,7 @@ +'use server' +import { getGroups } from "@/lib/api" + +export async function getGroupsAction(groupIds: string[]) { + 'use server' + return getGroups(groupIds) +} diff --git a/src/app/groups/layout.tsx b/src/app/groups/layout.tsx index df7d39e..65aec0e 100644 --- a/src/app/groups/layout.tsx +++ b/src/app/groups/layout.tsx @@ -2,7 +2,7 @@ import { PropsWithChildren } from 'react' export default function GroupsLayout({ children }: PropsWithChildren<{}>) { return ( -
+
{children}
) diff --git a/src/app/groups/page.tsx b/src/app/groups/page.tsx index 0c46d99..4a0d286 100644 --- a/src/app/groups/page.tsx +++ b/src/app/groups/page.tsx @@ -1,6 +1,5 @@ import { RecentGroupList } from '@/app/groups/recent-group-list' import { Button } from '@/components/ui/button' -import { getGroups } from '@/lib/api' import { Plus } from 'lucide-react' import { Metadata } from 'next' import Link from 'next/link' @@ -10,13 +9,8 @@ export const metadata: Metadata = { } export default async function GroupsPage() { - async function getGroupsAction(groupIds: string[]) { - 'use server' - return getGroups(groupIds) - } - return ( -
+ <>

Recently visited groups @@ -28,7 +22,7 @@ export default async function GroupsPage() {

- -
+ + ) } diff --git a/src/app/groups/recent-group-list.tsx b/src/app/groups/recent-group-list.tsx index 92bc743..60e3922 100644 --- a/src/app/groups/recent-group-list.tsx +++ b/src/app/groups/recent-group-list.tsx @@ -1,4 +1,5 @@ 'use client' +import { getGroupsAction } from '@/app/groups/actions' import { getRecentGroups } from '@/app/groups/recent-groups-helpers' import { Button } from '@/components/ui/button' import { getGroups } from '@/lib/api' @@ -28,7 +29,7 @@ type Props = { getGroupsAction: (groupIds: string[]) => ReturnType } -export function RecentGroupList({ getGroupsAction }: Props) { +export function RecentGroupList() { const [state, setState] = useState({ status: 'pending' }) useEffect(() => { @@ -37,15 +38,30 @@ export function RecentGroupList({ getGroupsAction }: Props) { getGroupsAction(groupsInStorage.map((g) => g.id)).then((groupsDetails) => { setState({ status: 'complete', groups: groupsInStorage, groupsDetails }) }) - }, [getGroupsAction]) + }, []) - if (state.status === 'pending') + if (state.status === 'pending') { return (

Loading recent groups…

) + } + + if (state.groups.length === 0) { + return ( +
+

You have not visited any group recently.

+

+ {' '} + or ask a friend to send you the link to an existing one. +

+
+ ) + } return (
    @@ -70,9 +86,12 @@ export function RecentGroupList({ getGroupsAction }: Props) {
    - {details.createdAt.toLocaleDateString('en-US', { - dateStyle: 'medium', - })} + {new Date(details.createdAt).toLocaleDateString( + 'en-US', + { + dateStyle: 'medium', + }, + )}
    diff --git a/src/lib/api.ts b/src/lib/api.ts index b6a8d65..bde32e8 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -83,10 +83,13 @@ export async function getGroupExpensesParticipants(groupId: string) { export async function getGroups(groupIds: string[]) { const prisma = await getPrisma() - return prisma.group.findMany({ + return (await prisma.group.findMany({ where: { id: { in: groupIds } }, include: { _count: { select: { participants: true } } }, - }) + })).map(group => ({ + ...group, + createdAt: group.createdAt.toISOString() + })) } export async function updateExpense( -- cgit v1.3