mirror of
https://github.com/lukevella/rallly.git
synced 2025-06-04 03:32:12 +02:00
✨ Self-Hosting Update (#842)
This commit is contained in:
parent
3e616d1e41
commit
7a5f9ae474
51 changed files with 945 additions and 781 deletions
|
@ -8,7 +8,7 @@ import { useWhoAmI } from "@/contexts/whoami";
|
|||
import { useRequiredContext } from "./use-required-context";
|
||||
|
||||
export const UserContext = React.createContext<{
|
||||
user: UserSession & { shortName: string };
|
||||
user: UserSession & { name: string };
|
||||
refresh: () => void;
|
||||
ownsObject: (obj: { userId: string | null }) => boolean;
|
||||
} | null>(null);
|
||||
|
@ -50,23 +50,22 @@ export const UserProvider = (props: { children?: React.ReactNode }) => {
|
|||
const queryClient = trpc.useContext();
|
||||
|
||||
const user = useWhoAmI();
|
||||
const subscriptionQuery = trpc.user.subscription.useQuery();
|
||||
const { data: userPreferences } = trpc.userPreferences.get.useQuery();
|
||||
|
||||
const shortName = user
|
||||
const name = user
|
||||
? user.isGuest === false
|
||||
? user.name.split(" ")[0]
|
||||
? user.name
|
||||
: user.id.substring(0, 10)
|
||||
: t("guest");
|
||||
|
||||
if (!user || userPreferences === undefined || !subscriptionQuery.isFetched) {
|
||||
if (!user || userPreferences === undefined) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<UserContext.Provider
|
||||
value={{
|
||||
user: { ...user, shortName },
|
||||
user: { ...user, name },
|
||||
refresh: () => {
|
||||
return queryClient.whoami.invalidate();
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue