-
-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use tRPC for recent groups page (#253)
* Use tRPC for recent groups page * Use tRPC for adding group by URL * Use tRPC for saving visited group * Group context
- Loading branch information
Showing
31 changed files
with
314 additions
and
262 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,10 @@ | ||
import { cached } from '@/app/cached-functions' | ||
import BalancesAndReimbursements from '@/app/groups/[groupId]/balances/balances-and-reimbursements' | ||
import { Metadata } from 'next' | ||
import { notFound } from 'next/navigation' | ||
|
||
export const metadata: Metadata = { | ||
title: 'Balances', | ||
} | ||
|
||
export default async function GroupPage({ | ||
params: { groupId }, | ||
}: { | ||
params: { groupId: string } | ||
}) { | ||
const group = await cached.getGroup(groupId) | ||
if (!group) notFound() | ||
|
||
return <BalancesAndReimbursements groupId={groupId} /> | ||
export default async function GroupPage() { | ||
return <BalancesAndReimbursements /> | ||
} |
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,30 @@ | ||
import { AppRouterOutput } from '@/trpc/routers/_app' | ||
import { PropsWithChildren, createContext, useContext } from 'react' | ||
|
||
type Group = NonNullable<AppRouterOutput['groups']['get']['group']> | ||
|
||
type GroupContext = | ||
| { isLoading: false; groupId: string; group: Group } | ||
| { isLoading: true; groupId: string; group: undefined } | ||
|
||
const CurrentGroupContext = createContext<GroupContext | null>(null) | ||
|
||
export const useCurrentGroup = () => { | ||
const context = useContext(CurrentGroupContext) | ||
if (!context) | ||
throw new Error( | ||
'Missing context. Should be called inside a CurrentGroupProvider.', | ||
) | ||
return context | ||
} | ||
|
||
export const CurrentGroupProvider = ({ | ||
children, | ||
...props | ||
}: PropsWithChildren<GroupContext>) => { | ||
return ( | ||
<CurrentGroupContext.Provider value={props}> | ||
{children} | ||
</CurrentGroupContext.Provider> | ||
) | ||
} |
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
Oops, something went wrong.