mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-16 07:13:29 +00:00
feat(02-12): route scoped records to granted domains
- keep shared navigation independent of actor module preferences\n- open scoped records at their first allowed destination\n- announce record access and kind in doorway names
This commit is contained in:
1 parent
34073cf8dc
commit
6c4dd2d96b
6 files changed
+77
-15
No files matched your search
@@ -102,10 +102,13 @@ async function postSwitch(accountId: string | null): Promise<SwitchResponse> {
|
||||
* sequence. Two copies of "wipe, then reload" is one copy too many for a step
|
||||
* whose order is the safety property.
|
||||
*/
|
||||
async function landOnRecord(accountId: string | null): Promise<never> {
|
||||
async function landOnRecord(
|
||||
accountId: string | null,
|
||||
destination = "/",
|
||||
): Promise<never> {
|
||||
setRecordScope(accountId);
|
||||
await clearOfflineCachesForRecordSwitch();
|
||||
window.location.assign("/");
|
||||
window.location.assign(destination);
|
||||
// The document is being replaced. Nothing after this runs, and the promise
|
||||
// deliberately never settles so no caller paints a "done" state over a page
|
||||
// that is on its way out.
|
||||
@@ -124,15 +127,21 @@ export function useAccountSwitch() {
|
||||
const { t } = useTranslations();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
const mutation = useMutation({
|
||||
mutationKey: queryKeys.accountSwitchMutation(),
|
||||
mutationFn: async (accountId: string | null) => {
|
||||
mutationFn: async ({
|
||||
accountId,
|
||||
destination,
|
||||
}: {
|
||||
accountId: string | null;
|
||||
destination: string;
|
||||
}) => {
|
||||
await postSwitch(accountId);
|
||||
// The in-memory cache holds the record we are leaving. Clearing it here
|
||||
// as well as reloading costs nothing and closes the window in which a
|
||||
// failed navigation would leave the old entries reachable.
|
||||
queryClient.clear();
|
||||
return landOnRecord(accountId);
|
||||
return landOnRecord(accountId, destination);
|
||||
},
|
||||
onError: (error: unknown) => {
|
||||
toast.error(
|
||||
@@ -142,6 +151,16 @@ export function useAccountSwitch() {
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
...mutation,
|
||||
/** Preserve the established own-record and exit call sites. */
|
||||
mutate: (accountId: string | null) =>
|
||||
mutation.mutate({ accountId, destination: "/" }),
|
||||
/** Enter a scoped record directly at a server-presentable destination. */
|
||||
switchTo: (accountId: string, destination: string) =>
|
||||
mutation.mutate({ accountId, destination }),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user