Tiny adjustments

This commit is contained in:
Sebastien Castiel
2023-12-11 10:26:13 -05:00
parent c504a77338
commit 69fa008ea4
6 changed files with 42 additions and 19 deletions

View File

@@ -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%;

View File

@@ -0,0 +1,7 @@
'use server'
import { getGroups } from "@/lib/api"
export async function getGroupsAction(groupIds: string[]) {
'use server'
return getGroups(groupIds)
}

View File

@@ -2,7 +2,7 @@ import { PropsWithChildren } from 'react'
export default function GroupsLayout({ children }: PropsWithChildren<{}>) {
return (
<main className="flex-1 max-w-screen-md w-full mx-auto p-4">
<main className="flex-1 max-w-screen-md w-full mx-auto p-4 flex flex-col gap-2">
{children}
</main>
)

View File

@@ -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 (
<main>
<>
<div className="flex flex-col sm:flex-row sm:justify-between sm:items-baseline mb-2">
<h1 className="font-bold text-2xl mb-4">
<Link href="/groups">Recently visited groups</Link>
@@ -28,7 +22,7 @@ export default async function GroupsPage() {
</Link>
</Button>
</div>
<RecentGroupList getGroupsAction={getGroupsAction} />
</main>
<RecentGroupList />
</>
)
}

View File

@@ -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<typeof getGroups>
}
export function RecentGroupList({ getGroupsAction }: Props) {
export function RecentGroupList() {
const [state, setState] = useState<State>({ 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 (
<p>
<Loader2 className="w-4 m-4 mr-2 inline animate-spin" /> Loading recent
groups
</p>
)
}
if (state.groups.length === 0) {
return (
<div className="text-sm space-y-2">
<p>You have not visited any group recently.</p>
<p>
<Button variant="link" asChild className="-m-4">
<Link href={`/groups/create`}>Create one</Link>
</Button>{' '}
or ask a friend to send you the link to an existing one.
</p>
</div>
)
}
return (
<ul className="grid grid-cols-1 gap-2 mt-2 sm:grid-cols-3">
@@ -70,9 +86,12 @@ export function RecentGroupList({ getGroupsAction }: Props) {
<div className="flex items-center">
<Calendar className="w-3 h-3 inline mx-1" />
<span>
{details.createdAt.toLocaleDateString('en-US', {
dateStyle: 'medium',
})}
{new Date(details.createdAt).toLocaleDateString(
'en-US',
{
dateStyle: 'medium',
},
)}
</span>
</div>
</div>

View File

@@ -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(