9b12016428
* Pass subscription status into the usage bar * Page navigation spinner is now blue (was a bit subtle before) * Better logging of db queries, this will be commented out before the PR is merged * Select only the required fields * We don’t need the member count for each org * WIP redirecting with projectId in session * Switching projects is now working, without duplicating the project query * Removed logs in revalidate function * Removes some unused imports * ProjectPresenter: removed lots of unused db selects * Root use defaultShouldRevalidate, not just true * Simplified the job list query and separated the deleting job modal query * Use requireUserId instead of requireUser wherever possible * EventListPresenter query simplified * Simplified the RunListPresenter query * Disable query logging * Use the latest updated version for the job list table * We need to use the org presenter on the select plan page
29 lines
855 B
TypeScript
29 lines
855 B
TypeScript
import { UIMatch } from "@remix-run/react";
|
|
import type { User } from "~/models/user.server";
|
|
import { loader } from "~/root";
|
|
import { useChanged } from "./useChanged";
|
|
import { useTypedMatchesData } from "./useTypedMatchData";
|
|
|
|
export function useOptionalUser(matches?: UIMatch[]): User | undefined {
|
|
const routeMatch = useTypedMatchesData<typeof loader>({
|
|
id: "root",
|
|
matches,
|
|
});
|
|
|
|
return routeMatch?.user ?? undefined;
|
|
}
|
|
|
|
export function useUser(matches?: UIMatch[]): User {
|
|
const maybeUser = useOptionalUser(matches);
|
|
if (!maybeUser) {
|
|
throw new Error(
|
|
"No user found in root loader, but user is required by useUser. If user is optional, try useOptionalUser instead."
|
|
);
|
|
}
|
|
return maybeUser;
|
|
}
|
|
|
|
export function useUserChanged(callback: (user: User | undefined) => void) {
|
|
useChanged(useOptionalUser, callback);
|
|
}
|