@remit/web-client 0.0.327 → 0.0.329
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/components/calendar/CalendarEventEditor.d.ts +6 -0
- package/dist/src/components/calendar/CalendarEventEditor.js +321 -0
- package/dist/src/components/calendar/CalendarEventPopup.d.ts +10 -0
- package/dist/src/components/calendar/CalendarEventPopup.js +133 -0
- package/dist/src/components/calendar/CalendarLoadFailed.d.ts +8 -0
- package/dist/src/components/calendar/CalendarLoadFailed.js +11 -0
- package/dist/src/components/calendar/CalendarNavPane.d.ts +11 -0
- package/dist/src/components/calendar/CalendarNavPane.js +50 -0
- package/dist/src/components/calendar/CalendarQuickCreate.d.ts +22 -0
- package/dist/src/components/calendar/CalendarQuickCreate.js +131 -0
- package/dist/src/components/calendar/CalendarScreen.d.ts +11 -0
- package/dist/src/components/calendar/CalendarScreen.js +145 -0
- package/dist/src/components/calendar/CalendarSession.d.ts +21 -0
- package/dist/src/components/calendar/CalendarSession.js +12 -0
- package/dist/src/components/calendar/ChangeCalendarSuggestion.js +39 -5
- package/dist/src/components/calendar/EventMoves.d.ts +17 -0
- package/dist/src/components/calendar/EventMoves.js +103 -0
- package/dist/src/components/calendar/calendar-story-fixtures.js +8 -2
- package/dist/src/components/calendar/calendar-story-server.d.ts +2 -5
- package/dist/src/components/calendar/calendar-story-server.js +5 -6
- package/dist/src/components/layout/AppFrame.d.ts +11 -0
- package/dist/src/components/layout/AppFrame.js +16 -0
- package/dist/src/components/mail/MailSidebarAdapter.js +1 -1
- package/dist/src/components/settings/AccountFormPanel.js +1 -1
- package/dist/src/components/ui/SignedOutOverlay.d.ts +6 -0
- package/dist/src/components/ui/SignedOutOverlay.js +29 -0
- package/dist/src/hooks/calendar/draft-session.d.ts +77 -0
- package/dist/src/hooks/calendar/draft-session.js +109 -0
- package/dist/src/hooks/calendar/index.d.ts +2 -1
- package/dist/src/hooks/calendar/index.js +1 -0
- package/dist/src/hooks/calendar/useCalendarJump.d.ts +0 -2
- package/dist/src/hooks/calendar/useCalendarJump.js +3 -5
- package/dist/src/hooks/calendar/useCalendarWrites.d.ts +11 -1
- package/dist/src/hooks/calendar/useCalendarWrites.js +7 -2
- package/dist/src/hooks/calendar/useCalendars.d.ts +1 -0
- package/dist/src/hooks/calendar/useCalendars.js +5 -2
- package/dist/src/hooks/calendar/useDraftSession.d.ts +32 -0
- package/dist/src/hooks/calendar/useDraftSession.js +106 -0
- package/dist/src/hooks/calendar/useMoveEvent.d.ts +4 -0
- package/dist/src/hooks/calendar/useMoveEvent.js +61 -0
- package/dist/src/hooks/use-system-update.js +3 -5
- package/dist/src/hooks/useCalendarData.d.ts +2 -0
- package/dist/src/hooks/useCalendarData.js +6 -1
- package/dist/src/hooks/useCalendarSidePane.d.ts +14 -0
- package/dist/src/hooks/useCalendarSidePane.js +30 -0
- package/dist/src/hooks/useRefreshControl.js +4 -8
- package/dist/src/hooks/useStaleAccountSync.js +4 -4
- package/dist/src/hooks/useWarningsAttention.js +1 -3
- package/dist/src/lib/calendar-route.d.ts +8 -6
- package/dist/src/lib/calendar-route.js +18 -2
- package/dist/src/lib/calendar-side-pane-pref.d.ts +14 -0
- package/dist/src/lib/calendar-side-pane-pref.js +27 -0
- package/dist/src/lib/error-classifier.d.ts +5 -30
- package/dist/src/lib/error-classifier.js +7 -10
- package/dist/src/lib/escalate.d.ts +6 -0
- package/dist/src/lib/escalate.js +16 -0
- package/dist/src/lib/intelligence-pref.js +3 -2
- package/dist/src/lib/mail-search.d.ts +32 -74
- package/dist/src/lib/mail-search.js +11 -0
- package/dist/src/lib/new-event-range.d.ts +26 -0
- package/dist/src/lib/new-event-range.js +69 -0
- package/dist/src/lib/query-error-handler.d.ts +2 -6
- package/dist/src/lib/query-error-handler.js +5 -14
- package/dist/src/lib/signed-out.d.ts +13 -0
- package/dist/src/lib/signed-out.js +28 -0
- package/dist/src/routeTree.gen.d.ts +620 -821
- package/dist/src/routeTree.gen.js +25 -1
- package/dist/src/routes/__root.js +8 -2
- package/dist/src/routes/calendar/$view.$date/$calendarObjectId/$recurrenceId/edit.d.ts +5 -0
- package/dist/src/routes/calendar/$view.$date/$calendarObjectId/$recurrenceId/edit.js +11 -0
- package/dist/src/routes/calendar/$view.$date/$calendarObjectId/$recurrenceId/index.d.ts +5 -0
- package/dist/src/routes/calendar/$view.$date/$calendarObjectId/$recurrenceId/index.js +12 -0
- package/dist/src/routes/calendar/$view.$date/$calendarObjectId/$recurrenceId.d.ts +4 -12
- package/dist/src/routes/calendar/$view.$date/$calendarObjectId/$recurrenceId.js +4 -13
- package/dist/src/routes/calendar/$view.$date/$calendarObjectId/edit.d.ts +5 -0
- package/dist/src/routes/calendar/$view.$date/$calendarObjectId/edit.js +14 -0
- package/dist/src/routes/calendar/$view.$date/$calendarObjectId/index.d.ts +4 -12
- package/dist/src/routes/calendar/$view.$date/$calendarObjectId/index.js +4 -4
- package/dist/src/routes/calendar/$view.$date/$calendarObjectId.d.ts +4 -12
- package/dist/src/routes/calendar/$view.$date/index.d.ts +4 -17
- package/dist/src/routes/calendar/$view.$date/index.js +3 -10
- package/dist/src/routes/calendar/$view.$date/new.d.ts +8 -12
- package/dist/src/routes/calendar/$view.$date/new.js +8 -13
- package/dist/src/routes/calendar/$view.$date/suggestion.$suggestionId.d.ts +4 -12
- package/dist/src/routes/calendar/$view.$date/suggestion.$suggestionId.js +2 -2
- package/dist/src/routes/calendar/$view.$date.d.ts +4 -12
- package/dist/src/routes/calendar/$view.$date.js +14 -50
- package/dist/src/routes/calendar/index.d.ts +4 -12
- package/dist/src/routes/calendar/index.js +2 -1
- package/dist/src/routes/calendar.d.ts +4 -9
- package/dist/src/routes/calendar.js +10 -35
- package/dist/src/routes/mail/$mailboxId/$threadId/$messageId/$mode.{-$outboxMessageId}.d.ts +13 -24
- package/dist/src/routes/mail/$mailboxId/$threadId/$messageId.d.ts +12 -16
- package/dist/src/routes/mail/$mailboxId/$threadId/index.d.ts +12 -16
- package/dist/src/routes/mail/$mailboxId/$threadId.d.ts +12 -16
- package/dist/src/routes/mail/$mailboxId/compose.{-$outboxMessageId}.d.ts +12 -16
- package/dist/src/routes/mail/$mailboxId/index.d.ts +12 -16
- package/dist/src/routes/mail/$mailboxId.d.ts +12 -16
- package/dist/src/routes/mail/brief/$threadId/$messageId/$mode.{-$outboxMessageId}.d.ts +13 -24
- package/dist/src/routes/mail/brief/$threadId/$messageId.d.ts +12 -16
- package/dist/src/routes/mail/brief/$threadId/index.d.ts +12 -16
- package/dist/src/routes/mail/brief/$threadId.d.ts +12 -16
- package/dist/src/routes/mail/brief/compose.{-$outboxMessageId}.d.ts +12 -16
- package/dist/src/routes/mail/brief/index.d.ts +12 -16
- package/dist/src/routes/mail/brief.d.ts +12 -16
- package/dist/src/routes/mail/flagged/$threadId/$messageId/$mode.{-$outboxMessageId}.d.ts +13 -24
- package/dist/src/routes/mail/flagged/$threadId/$messageId.d.ts +12 -16
- package/dist/src/routes/mail/flagged/$threadId/index.d.ts +12 -16
- package/dist/src/routes/mail/flagged/$threadId.d.ts +12 -16
- package/dist/src/routes/mail/flagged/compose.{-$outboxMessageId}.d.ts +12 -16
- package/dist/src/routes/mail/flagged/index.d.ts +12 -16
- package/dist/src/routes/mail/flagged.d.ts +12 -16
- package/dist/src/routes/mail/index.d.ts +24 -32
- package/dist/src/routes/mail/index.js +7 -2
- package/dist/src/routes/mail/outbox/compose.{-$outboxMessageId}.d.ts +12 -16
- package/dist/src/routes/mail/outbox/draft/$outboxMessageId.d.ts +12 -16
- package/dist/src/routes/mail/outbox/index.d.ts +12 -16
- package/dist/src/routes/mail/outbox.d.ts +12 -16
- package/dist/src/routes/mail.d.ts +13 -14
- package/dist/src/routes/mail.js +8 -15
- package/dist/src/routes/settings/accounts.d.ts +1 -17
- package/dist/src/routing/app-switch.d.ts +11 -0
- package/dist/src/routing/app-switch.js +35 -0
- package/dist/src/routing/calendar.d.ts +41 -4
- package/dist/src/routing/calendar.js +121 -13
- package/dist/src/routing/fragment.d.ts +1 -1
- package/dist/src/routing/fragment.js +6 -1
- package/dist/src/routing/index.d.ts +3 -2
- package/dist/src/routing/index.js +3 -2
- package/dist/src/routing/wizard-history.d.ts +10 -4
- package/dist/src/routing/wizard-history.js +2 -10
- package/package.json +3 -3
- package/dist/src/components/calendar/CalendarComposePane.d.ts +0 -49
- package/dist/src/components/calendar/CalendarComposePane.js +0 -8
- package/dist/src/components/calendar/CalendarComposeSeed.d.ts +0 -7
- package/dist/src/components/calendar/CalendarComposeSeed.js +0 -19
- package/dist/src/components/calendar/CalendarEventPane.d.ts +0 -48
- package/dist/src/components/calendar/CalendarEventPane.js +0 -48
- package/dist/src/components/calendar/CalendarShell.d.ts +0 -43
- package/dist/src/components/calendar/CalendarShell.js +0 -35
- package/dist/src/components/calendar/CalendarViewPlaceholder.d.ts +0 -1
- package/dist/src/components/calendar/CalendarViewPlaceholder.js +0 -5
- package/dist/src/components/calendar/CalendarWorkspace.d.ts +0 -49
- package/dist/src/components/calendar/CalendarWorkspace.js +0 -65
- package/dist/src/components/calendar/OpenCalendarEvent.d.ts +0 -20
- package/dist/src/components/calendar/OpenCalendarEvent.js +0 -169
- package/dist/src/components/calendar/WriteCalendarEvent.d.ts +0 -13
- package/dist/src/components/calendar/WriteCalendarEvent.js +0 -59
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The signed-out notice every screen shares. It covers the screen so nothing
|
|
3
|
+
* behind it reads as empty data, stays until the reader signs in, and its sign
|
|
4
|
+
* in clears the dead session so the sign-in screen opens at the same address.
|
|
5
|
+
*/
|
|
6
|
+
export declare function SignedOutOverlay(): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useModalFocus, useOverlayScope } from "@remit/ui";
|
|
3
|
+
import { LogIn } from "lucide-react";
|
|
4
|
+
import { useEffect, useRef, useState } from "react";
|
|
5
|
+
import { useAuthProvider } from "../../auth/provider";
|
|
6
|
+
import { isSignedOut, resetSignedOut, subscribeSignedOut, } from "../../lib/signed-out";
|
|
7
|
+
const SIGN_IN_CLASS = "mt-6 inline-flex min-h-11 w-full items-center justify-center gap-2 rounded-md bg-accent px-4 text-sm font-medium text-accent-fg hover:bg-accent-hover focus-visible:ring-2 focus-visible:ring-ring";
|
|
8
|
+
/**
|
|
9
|
+
* The signed-out notice every screen shares. It covers the screen so nothing
|
|
10
|
+
* behind it reads as empty data, stays until the reader signs in, and its sign
|
|
11
|
+
* in clears the dead session so the sign-in screen opens at the same address.
|
|
12
|
+
*/
|
|
13
|
+
export function SignedOutOverlay() {
|
|
14
|
+
const [open, setOpen] = useState(isSignedOut);
|
|
15
|
+
const { Account } = useAuthProvider();
|
|
16
|
+
const dialogRef = useRef(null);
|
|
17
|
+
useEffect(() => subscribeSignedOut(setOpen), []);
|
|
18
|
+
useOverlayScope({ id: "signed-out", open });
|
|
19
|
+
useModalFocus(dialogRef, open);
|
|
20
|
+
if (!open)
|
|
21
|
+
return null;
|
|
22
|
+
return (_jsx("div", { className: "fixed inset-0 z-[70] flex items-center justify-center bg-canvas/80 p-4 backdrop-blur-sm", children: _jsxs("div", { ref: dialogRef, role: "alertdialog", "aria-modal": "true", "aria-labelledby": "signed-out-title", "aria-describedby": "signed-out-text", tabIndex: -1, className: "w-full max-w-sm rounded-lg border border-line bg-surface p-6 shadow-xl outline-none", children: [_jsx("h2", { id: "signed-out-title", className: "text-lg font-semibold text-fg", children: "You're signed out" }), _jsx("p", { id: "signed-out-text", className: "mt-2 text-sm text-fg-muted", children: "The server no longer accepts this session. Sign in again to carry on here; you will come back to this screen." }), _jsx(Account, { fallback: _jsxs("button", { type: "button", onClick: () => {
|
|
23
|
+
resetSignedOut();
|
|
24
|
+
window.location.reload();
|
|
25
|
+
}, className: SIGN_IN_CLASS, children: [_jsx(LogIn, { className: "size-4", "aria-hidden": "true" }), "Sign in"] }), children: ({ signOut }) => (_jsxs("button", { type: "button", onClick: () => {
|
|
26
|
+
resetSignedOut();
|
|
27
|
+
void signOut();
|
|
28
|
+
}, className: SIGN_IN_CLASS, children: [_jsx(LogIn, { className: "size-4", "aria-hidden": "true" }), "Sign in"] })) })] }) }));
|
|
29
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one draft the calendar holds, and every way it moves.
|
|
3
|
+
*
|
|
4
|
+
* The quick-create popup, the advanced sidebar and the block on the grid all
|
|
5
|
+
* show this one draft. A new selection moves it rather than opening a second.
|
|
6
|
+
* A click outside the popup removes it, typed or not, with nothing kept (M1).
|
|
7
|
+
* Nothing here reaches the API or the address: the screen reads the state and
|
|
8
|
+
* runs the save and the navigations itself.
|
|
9
|
+
*/
|
|
10
|
+
import type { CalendarSlotPick, GridGesture } from "@remit/ui";
|
|
11
|
+
export interface SessionDraft {
|
|
12
|
+
range: CalendarSlotPick;
|
|
13
|
+
title: string;
|
|
14
|
+
location: string;
|
|
15
|
+
calendarId: string;
|
|
16
|
+
}
|
|
17
|
+
export type DraftStatus = "editing" | "saving" | "failed";
|
|
18
|
+
export type DraftSession = {
|
|
19
|
+
mode: "idle";
|
|
20
|
+
dragging: CalendarSlotPick | null;
|
|
21
|
+
} | {
|
|
22
|
+
mode: "quick";
|
|
23
|
+
dragging: CalendarSlotPick | null;
|
|
24
|
+
draft: SessionDraft;
|
|
25
|
+
status: DraftStatus;
|
|
26
|
+
problem: string;
|
|
27
|
+
} | {
|
|
28
|
+
mode: "sidebar";
|
|
29
|
+
dragging: CalendarSlotPick | null;
|
|
30
|
+
draft: SessionDraft;
|
|
31
|
+
};
|
|
32
|
+
/** What else is up on the screen, which the session does not own but answers to. */
|
|
33
|
+
export interface SessionLayers {
|
|
34
|
+
/** An event popup is open over the grid. */
|
|
35
|
+
eventPopup: boolean;
|
|
36
|
+
/** The advanced sidebar is open, on a new event or a stored one. */
|
|
37
|
+
sidebar: boolean;
|
|
38
|
+
/** The nav slide-over is open on a phone. */
|
|
39
|
+
nav: boolean;
|
|
40
|
+
}
|
|
41
|
+
export type SessionAction = {
|
|
42
|
+
type: "gesture";
|
|
43
|
+
gesture: GridGesture;
|
|
44
|
+
layers: SessionLayers;
|
|
45
|
+
} | {
|
|
46
|
+
type: "new-event";
|
|
47
|
+
range: CalendarSlotPick;
|
|
48
|
+
} | {
|
|
49
|
+
type: "outside";
|
|
50
|
+
} | {
|
|
51
|
+
type: "escape";
|
|
52
|
+
layers: SessionLayers;
|
|
53
|
+
} | {
|
|
54
|
+
type: "change";
|
|
55
|
+
draft: SessionDraft;
|
|
56
|
+
} | {
|
|
57
|
+
type: "save";
|
|
58
|
+
} | {
|
|
59
|
+
type: "saved";
|
|
60
|
+
} | {
|
|
61
|
+
type: "save-failed";
|
|
62
|
+
problem: string;
|
|
63
|
+
} | {
|
|
64
|
+
type: "expand";
|
|
65
|
+
} | {
|
|
66
|
+
type: "sidebar-range";
|
|
67
|
+
range: CalendarSlotPick;
|
|
68
|
+
} | {
|
|
69
|
+
type: "sidebar-closed";
|
|
70
|
+
};
|
|
71
|
+
export declare const IDLE: DraftSession;
|
|
72
|
+
/** Which layer Esc closes: only the top one, a drag first. */
|
|
73
|
+
export type EscapeTarget = "drag" | "popup" | "event-popup" | "sidebar" | "nav";
|
|
74
|
+
export declare function escapeTarget(session: DraftSession, layers: SessionLayers): EscapeTarget | null;
|
|
75
|
+
export declare function draftSessionReducer(session: DraftSession, action: SessionAction): DraftSession;
|
|
76
|
+
/** The range the grid draws: the one being dragged, else the draft's. */
|
|
77
|
+
export declare function drawnRange(session: DraftSession): CalendarSlotPick | null;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
export const IDLE = { mode: "idle", dragging: null };
|
|
2
|
+
const quick = (draft) => ({
|
|
3
|
+
mode: "quick",
|
|
4
|
+
dragging: null,
|
|
5
|
+
draft,
|
|
6
|
+
status: "editing",
|
|
7
|
+
problem: "",
|
|
8
|
+
});
|
|
9
|
+
const blank = (range) => ({
|
|
10
|
+
range,
|
|
11
|
+
title: "",
|
|
12
|
+
location: "",
|
|
13
|
+
calendarId: "",
|
|
14
|
+
});
|
|
15
|
+
export function escapeTarget(session, layers) {
|
|
16
|
+
if (session.dragging)
|
|
17
|
+
return "drag";
|
|
18
|
+
if (session.mode === "quick")
|
|
19
|
+
return "popup";
|
|
20
|
+
if (layers.eventPopup)
|
|
21
|
+
return "event-popup";
|
|
22
|
+
if (layers.sidebar)
|
|
23
|
+
return "sidebar";
|
|
24
|
+
if (layers.nav)
|
|
25
|
+
return "nav";
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
/** A finished range: it opens the draft, or moves the one already open. */
|
|
29
|
+
function settleRange(session, range) {
|
|
30
|
+
if (session.mode === "quick")
|
|
31
|
+
return {
|
|
32
|
+
...session,
|
|
33
|
+
dragging: null,
|
|
34
|
+
draft: { ...session.draft, range },
|
|
35
|
+
status: session.status === "saving" ? "saving" : "editing",
|
|
36
|
+
};
|
|
37
|
+
if (session.mode === "sidebar")
|
|
38
|
+
return { ...session, dragging: null, draft: { ...session.draft, range } };
|
|
39
|
+
return quick(blank(range));
|
|
40
|
+
}
|
|
41
|
+
function onGesture(session, gesture, layers) {
|
|
42
|
+
switch (gesture.type) {
|
|
43
|
+
case "drag":
|
|
44
|
+
return { ...session, dragging: gesture.range };
|
|
45
|
+
case "drag-cancel":
|
|
46
|
+
return { ...session, dragging: null };
|
|
47
|
+
case "drag-end":
|
|
48
|
+
case "keyboard":
|
|
49
|
+
if (layers.sidebar && session.mode !== "sidebar")
|
|
50
|
+
return { mode: "sidebar", dragging: null, draft: blank(gesture.range) };
|
|
51
|
+
return settleRange(session, gesture.range);
|
|
52
|
+
case "click":
|
|
53
|
+
if (session.mode === "quick")
|
|
54
|
+
return IDLE;
|
|
55
|
+
if (session.mode === "sidebar" || layers.sidebar)
|
|
56
|
+
return { ...session, dragging: null };
|
|
57
|
+
if (layers.eventPopup)
|
|
58
|
+
return { ...session, dragging: null };
|
|
59
|
+
return quick(blank(gesture.range));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
export function draftSessionReducer(session, action) {
|
|
63
|
+
switch (action.type) {
|
|
64
|
+
case "gesture":
|
|
65
|
+
return onGesture(session, action.gesture, action.layers);
|
|
66
|
+
case "new-event":
|
|
67
|
+
return quick(blank(action.range));
|
|
68
|
+
case "outside":
|
|
69
|
+
return session.mode === "quick" ? IDLE : session;
|
|
70
|
+
case "escape": {
|
|
71
|
+
const target = escapeTarget(session, action.layers);
|
|
72
|
+
if (target === "drag")
|
|
73
|
+
return { ...session, dragging: null };
|
|
74
|
+
if (target === "popup")
|
|
75
|
+
return IDLE;
|
|
76
|
+
return session;
|
|
77
|
+
}
|
|
78
|
+
case "change":
|
|
79
|
+
if (session.mode === "idle")
|
|
80
|
+
return session;
|
|
81
|
+
return { ...session, draft: action.draft };
|
|
82
|
+
case "save":
|
|
83
|
+
if (session.mode !== "quick")
|
|
84
|
+
return session;
|
|
85
|
+
return { ...session, status: "saving", problem: "" };
|
|
86
|
+
case "saved":
|
|
87
|
+
return IDLE;
|
|
88
|
+
case "save-failed":
|
|
89
|
+
if (session.mode !== "quick")
|
|
90
|
+
return session;
|
|
91
|
+
return { ...session, status: "failed", problem: action.problem };
|
|
92
|
+
case "expand":
|
|
93
|
+
if (session.mode !== "quick")
|
|
94
|
+
return session;
|
|
95
|
+
return { mode: "sidebar", dragging: null, draft: session.draft };
|
|
96
|
+
case "sidebar-range":
|
|
97
|
+
if (session.mode === "sidebar")
|
|
98
|
+
return { ...session, draft: { ...session.draft, range: action.range } };
|
|
99
|
+
return { mode: "sidebar", dragging: null, draft: blank(action.range) };
|
|
100
|
+
case "sidebar-closed":
|
|
101
|
+
return session.mode === "sidebar" ? IDLE : session;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/** The range the grid draws: the one being dragged, else the draft's. */
|
|
105
|
+
export function drawnRange(session) {
|
|
106
|
+
if (session.dragging)
|
|
107
|
+
return session.dragging;
|
|
108
|
+
return session.mode === "idle" ? null : session.draft.range;
|
|
109
|
+
}
|
|
@@ -19,6 +19,7 @@ export { type CalendarFreeBusyResult, useCalendarFreeBusyWeeks, } from "./useCal
|
|
|
19
19
|
export { type CalendarJumpSearch, useCalendarJump } from "./useCalendarJump";
|
|
20
20
|
export { type CalendarSuggestionAnswers, type CalendarSuggestionsResult, type PendingCalendarSuggestionResult, type SuggestionAnswer, useCalendarSuggestionAnswers, useMessageCalendarSuggestions, usePendingCalendarSuggestion, usePendingCalendarSuggestions, } from "./useCalendarSuggestions";
|
|
21
21
|
export { type CalendarsResult, useCalendars } from "./useCalendars";
|
|
22
|
-
export { type CalendarWriteOutcome, type CalendarWrites, type ScopedWrite, useCalendarWrites, useInvalidateCalendarReads, } from "./useCalendarWrites";
|
|
22
|
+
export { type CalendarCreateOutcome, type CalendarWriteOutcome, type CalendarWrites, type ScopedWrite, useCalendarWrites, useInvalidateCalendarReads, } from "./useCalendarWrites";
|
|
23
23
|
export { useDraftClashes } from "./useDraftClashes";
|
|
24
|
+
export { type MoveEvent, useMoveEvent } from "./useMoveEvent";
|
|
24
25
|
export { addDays, type CalendarWindow, calendarWindow, calendarWindowOfDays, isoAt, isoAtInZone, isoOnClock, startOfDay, } from "./window";
|
|
@@ -21,4 +21,5 @@ export { useCalendarSuggestionAnswers, useMessageCalendarSuggestions, usePending
|
|
|
21
21
|
export { useCalendars } from "./useCalendars";
|
|
22
22
|
export { useCalendarWrites, useInvalidateCalendarReads, } from "./useCalendarWrites";
|
|
23
23
|
export { useDraftClashes } from "./useDraftClashes";
|
|
24
|
+
export { useMoveEvent } from "./useMoveEvent";
|
|
24
25
|
export { addDays, calendarWindow, calendarWindowOfDays, isoAt, isoAtInZone, isoOnClock, startOfDay, } from "./window";
|
|
@@ -5,8 +5,8 @@ import { getErrorStatus, softErrorStatuses } from "../../lib/error-classifier";
|
|
|
5
5
|
import { calendarJumpOf, deviceTimeZone } from "./instance";
|
|
6
6
|
const WINDOW_MS = 365 * 24 * 60 * 60_000;
|
|
7
7
|
const DAY_MS = 24 * 60 * 60_000;
|
|
8
|
-
const LISTING_META = softErrorStatuses(
|
|
9
|
-
const RESOURCE_META = softErrorStatuses(
|
|
8
|
+
const LISTING_META = softErrorStatuses();
|
|
9
|
+
const RESOURCE_META = softErrorStatuses(404);
|
|
10
10
|
const instant = (ms) => new Date(ms).toISOString().replace(/\.\d{3}Z$/, "+00:00");
|
|
11
11
|
const reasonOf = (error) => {
|
|
12
12
|
const message = error instanceof Error && error.message !== ""
|
|
@@ -78,9 +78,7 @@ export function useCalendarJump(calendarObjectId, enabled) {
|
|
|
78
78
|
first.error,
|
|
79
79
|
].find((error) => error !== null);
|
|
80
80
|
if (failure !== undefined) {
|
|
81
|
-
return
|
|
82
|
-
? { kind: "SignedOut" }
|
|
83
|
-
: { kind: "Failed", reason: reasonOf(failure) };
|
|
81
|
+
return { kind: "Failed", reason: reasonOf(failure) };
|
|
84
82
|
}
|
|
85
83
|
if (deleted)
|
|
86
84
|
return { kind: "Deleted" };
|
|
@@ -23,6 +23,16 @@ export type CalendarWriteOutcome = {
|
|
|
23
23
|
kind: "refused";
|
|
24
24
|
message: string;
|
|
25
25
|
};
|
|
26
|
+
/** A create that lands names the resource it made, so the grid can focus it. */
|
|
27
|
+
export type CalendarCreateOutcome = {
|
|
28
|
+
kind: "created";
|
|
29
|
+
calendarObjectId: string;
|
|
30
|
+
} | {
|
|
31
|
+
kind: "conflict";
|
|
32
|
+
} | {
|
|
33
|
+
kind: "refused";
|
|
34
|
+
message: string;
|
|
35
|
+
};
|
|
26
36
|
export interface ScopedWrite {
|
|
27
37
|
calendarObjectId: string;
|
|
28
38
|
calendarId: string;
|
|
@@ -34,7 +44,7 @@ export interface ScopedWrite {
|
|
|
34
44
|
etag: string;
|
|
35
45
|
}
|
|
36
46
|
export interface CalendarWrites {
|
|
37
|
-
createEvent: (input: RemitImapCreateCalendarEventInput) => Promise<
|
|
47
|
+
createEvent: (input: RemitImapCreateCalendarEventInput) => Promise<CalendarCreateOutcome>;
|
|
38
48
|
updateEvent: (write: ScopedWrite, patch: RemitImapUpdateCalendarEventInput) => Promise<CalendarWriteOutcome>;
|
|
39
49
|
deleteEvent: (write: ScopedWrite) => Promise<CalendarWriteOutcome>;
|
|
40
50
|
isWriting: boolean;
|
|
@@ -74,8 +74,13 @@ export function useCalendarWrites() {
|
|
|
74
74
|
});
|
|
75
75
|
const createEvent = useCallback((input) => create
|
|
76
76
|
.mutateAsync({ body: input })
|
|
77
|
-
.then(() =>
|
|
78
|
-
|
|
77
|
+
.then((created) => ({
|
|
78
|
+
kind: "created",
|
|
79
|
+
calendarObjectId: created.calendarObjectId,
|
|
80
|
+
}))
|
|
81
|
+
.catch((error) => getErrorStatus(error) === 412
|
|
82
|
+
? { kind: "conflict" }
|
|
83
|
+
: { kind: "refused", message: formatErrorMessage(error) }), [create]);
|
|
79
84
|
const updateEvent = useCallback((write, patch) => update
|
|
80
85
|
.mutateAsync({
|
|
81
86
|
path: { calendarObjectId: write.calendarObjectId },
|
|
@@ -12,7 +12,7 @@ import { useQuery } from "@tanstack/react-query";
|
|
|
12
12
|
import { useMemo } from "react";
|
|
13
13
|
import { toCalendarDescriptor } from "./instance";
|
|
14
14
|
export function useCalendars() {
|
|
15
|
-
const { data, isLoading, error } = useQuery(calendarOperationsListCalendarsOptions());
|
|
15
|
+
const { data, isLoading, error, refetch } = useQuery(calendarOperationsListCalendarsOptions());
|
|
16
16
|
return useMemo(() => {
|
|
17
17
|
const items = data?.items ?? [];
|
|
18
18
|
const calendars = items.map(toCalendarDescriptor);
|
|
@@ -25,6 +25,9 @@ export function useCalendars() {
|
|
|
25
25
|
?.calendarId ?? "",
|
|
26
26
|
isLoading,
|
|
27
27
|
error: error ?? null,
|
|
28
|
+
retry: () => {
|
|
29
|
+
void refetch();
|
|
30
|
+
},
|
|
28
31
|
};
|
|
29
|
-
}, [data, isLoading, error]);
|
|
32
|
+
}, [data, isLoading, error, refetch]);
|
|
30
33
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The calendar screen's draft session, with everything that answers to it: the
|
|
3
|
+
* grid's gestures, a press outside the popup, Esc, and where focus goes back
|
|
4
|
+
* to. The reducer in `draft-session.ts` decides; this binds it to the page.
|
|
5
|
+
*/
|
|
6
|
+
import type { GridGesture } from "@remit/ui";
|
|
7
|
+
import { type Dispatch, type MutableRefObject } from "react";
|
|
8
|
+
import { type DraftSession, type SessionAction, type SessionLayers } from "./draft-session";
|
|
9
|
+
export interface DraftSessionBindings {
|
|
10
|
+
layers: SessionLayers;
|
|
11
|
+
/** A finger's tap on an empty slot selects nothing; a hold does. */
|
|
12
|
+
isPhone: boolean;
|
|
13
|
+
/** Closes the event popup or the sidebar, back to the view. */
|
|
14
|
+
closeToView: () => void;
|
|
15
|
+
closeNav: () => void;
|
|
16
|
+
/** The events on the grid, so a saved event is focused once it is drawn. */
|
|
17
|
+
drawnEvents: readonly unknown[];
|
|
18
|
+
}
|
|
19
|
+
export interface DraftSessionHandle {
|
|
20
|
+
session: DraftSession;
|
|
21
|
+
dispatch: Dispatch<SessionAction>;
|
|
22
|
+
takeGesture: (gesture: GridGesture) => void;
|
|
23
|
+
/** The control focus returns to when quick-create closes unsaved. */
|
|
24
|
+
setOrigin: (element: HTMLElement | null) => void;
|
|
25
|
+
/** The sidebar's own close, asked by Esc; it confirms a touched draft. */
|
|
26
|
+
requestClose: MutableRefObject<(() => void) | null>;
|
|
27
|
+
/** The field quick-create had focus in when it expanded, by its label. */
|
|
28
|
+
carriedFocus: MutableRefObject<string>;
|
|
29
|
+
/** Focus the saved event once the grid draws it. */
|
|
30
|
+
focusSaved: (calendarObjectId: string) => void;
|
|
31
|
+
}
|
|
32
|
+
export declare function useDraftSession({ layers, isPhone, closeToView, closeNav, drawnEvents, }: DraftSessionBindings): DraftSessionHandle;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { useCallback, useEffect, useReducer, useRef, useState, } from "react";
|
|
2
|
+
import { draftSessionReducer, escapeTarget, IDLE, } from "./draft-session";
|
|
3
|
+
/** Presses the grid answers itself, and the popups they open. */
|
|
4
|
+
const GRID_OWNED = "[data-calendar-popover], [data-event-id], [data-time-columns], [data-all-day-row], [role='dialog']";
|
|
5
|
+
export function useDraftSession({ layers, isPhone, closeToView, closeNav, drawnEvents, }) {
|
|
6
|
+
const [session, dispatch] = useReducer(draftSessionReducer, IDLE);
|
|
7
|
+
const bound = useRef({ session, layers, isPhone, closeToView, closeNav });
|
|
8
|
+
bound.current = { session, layers, isPhone, closeToView, closeNav };
|
|
9
|
+
const origin = useRef(null);
|
|
10
|
+
const requestClose = useRef(null);
|
|
11
|
+
const carriedFocus = useRef("");
|
|
12
|
+
const saved = useRef(false);
|
|
13
|
+
const wasQuick = useRef(false);
|
|
14
|
+
const [focusAfterSave, setFocusAfterSave] = useState("");
|
|
15
|
+
const takeGesture = useCallback((gesture) => {
|
|
16
|
+
const current = bound.current;
|
|
17
|
+
const idle = current.session.mode === "idle";
|
|
18
|
+
if (current.isPhone &&
|
|
19
|
+
gesture.type === "click" &&
|
|
20
|
+
idle &&
|
|
21
|
+
!current.layers.eventPopup)
|
|
22
|
+
return;
|
|
23
|
+
const settles = gesture.type === "click" ||
|
|
24
|
+
gesture.type === "drag-end" ||
|
|
25
|
+
gesture.type === "keyboard";
|
|
26
|
+
if (settles && current.layers.eventPopup)
|
|
27
|
+
current.closeToView();
|
|
28
|
+
if (idle && (gesture.type === "click" || gesture.type === "keyboard"))
|
|
29
|
+
origin.current = gesture.origin;
|
|
30
|
+
if (idle && gesture.type === "drag-end")
|
|
31
|
+
origin.current = document.querySelector("[role='grid'][aria-label='Time grid']");
|
|
32
|
+
dispatch({ type: "gesture", gesture, layers: current.layers });
|
|
33
|
+
}, []);
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
const onPointerDown = (event) => {
|
|
36
|
+
if (!(event.target instanceof Element))
|
|
37
|
+
return;
|
|
38
|
+
if (event.target.closest(GRID_OWNED))
|
|
39
|
+
return;
|
|
40
|
+
if (bound.current.layers.eventPopup)
|
|
41
|
+
bound.current.closeToView();
|
|
42
|
+
dispatch({ type: "outside" });
|
|
43
|
+
};
|
|
44
|
+
const onKeyDown = (event) => {
|
|
45
|
+
if (event.key !== "Escape" || event.defaultPrevented)
|
|
46
|
+
return;
|
|
47
|
+
const { session: now, layers: up } = bound.current;
|
|
48
|
+
const target = escapeTarget(now, up);
|
|
49
|
+
if (target === null || target === "drag")
|
|
50
|
+
return;
|
|
51
|
+
event.preventDefault();
|
|
52
|
+
if (target === "event-popup")
|
|
53
|
+
bound.current.closeToView();
|
|
54
|
+
else if (target === "sidebar")
|
|
55
|
+
requestClose.current?.();
|
|
56
|
+
else if (target === "nav")
|
|
57
|
+
bound.current.closeNav();
|
|
58
|
+
else
|
|
59
|
+
dispatch({ type: "escape", layers: up });
|
|
60
|
+
};
|
|
61
|
+
document.addEventListener("pointerdown", onPointerDown, true);
|
|
62
|
+
window.addEventListener("keydown", onKeyDown);
|
|
63
|
+
return () => {
|
|
64
|
+
document.removeEventListener("pointerdown", onPointerDown, true);
|
|
65
|
+
window.removeEventListener("keydown", onKeyDown);
|
|
66
|
+
};
|
|
67
|
+
}, []);
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
const isQuick = session.mode === "quick";
|
|
70
|
+
if (wasQuick.current && session.mode === "idle" && !saved.current)
|
|
71
|
+
origin.current?.focus();
|
|
72
|
+
if (isQuick)
|
|
73
|
+
saved.current = false;
|
|
74
|
+
wasQuick.current = isQuick;
|
|
75
|
+
}, [session.mode]);
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
if (focusAfterSave === "" || drawnEvents.length === 0)
|
|
78
|
+
return;
|
|
79
|
+
const chip = document.querySelector(`[data-event-id^="${CSS.escape(focusAfterSave)}"]`);
|
|
80
|
+
if (!chip)
|
|
81
|
+
return;
|
|
82
|
+
chip.focus();
|
|
83
|
+
setFocusAfterSave("");
|
|
84
|
+
}, [focusAfterSave, drawnEvents]);
|
|
85
|
+
const sidebarOpen = layers.sidebar;
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
if (!sidebarOpen)
|
|
88
|
+
dispatch({ type: "sidebar-closed" });
|
|
89
|
+
}, [sidebarOpen]);
|
|
90
|
+
const setOrigin = useCallback((element) => {
|
|
91
|
+
origin.current = element;
|
|
92
|
+
}, []);
|
|
93
|
+
const focusSaved = useCallback((calendarObjectId) => {
|
|
94
|
+
saved.current = true;
|
|
95
|
+
setFocusAfterSave(calendarObjectId);
|
|
96
|
+
}, []);
|
|
97
|
+
return {
|
|
98
|
+
session,
|
|
99
|
+
dispatch,
|
|
100
|
+
takeGesture,
|
|
101
|
+
setOrigin,
|
|
102
|
+
requestClose,
|
|
103
|
+
carriedFocus,
|
|
104
|
+
focusSaved,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type CalendarEventData, type CalendarSlotPick, type RecurrenceScope } from "@remit/ui";
|
|
2
|
+
import { type CalendarWriteOutcome } from "./useCalendarWrites";
|
|
3
|
+
export type MoveEvent = (event: CalendarEventData, range: CalendarSlotPick, scope: RecurrenceScope | undefined, collectionZone: string) => Promise<CalendarWriteOutcome>;
|
|
4
|
+
export declare function useMoveEvent(): MoveEvent;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Moving or resizing a stored event by dragging it on the grid.
|
|
3
|
+
*
|
|
4
|
+
* The drop is a write like any other: it reads the stored version first, so
|
|
5
|
+
* the `If-Match` it sends is the one that is stored now, and a conflict comes
|
|
6
|
+
* back as an outcome the grid states.
|
|
7
|
+
*/
|
|
8
|
+
import { calendarEventDetailOperationsGetCalendarEventOptions } from "@remit/api-http-client/@tanstack/react-query.gen.ts";
|
|
9
|
+
import { formatErrorMessage, } from "@remit/ui";
|
|
10
|
+
import { useQueryClient } from "@tanstack/react-query";
|
|
11
|
+
import { useCallback } from "react";
|
|
12
|
+
import { softErrorStatuses } from "../../lib/error-classifier";
|
|
13
|
+
import { draftFromEvent, patchFromDrafts } from "./draft";
|
|
14
|
+
import { deviceTimeZone, readCalendarInstanceId, UNZONED_CALENDAR, } from "./instance";
|
|
15
|
+
import { storedAnchorZone } from "./resource";
|
|
16
|
+
import { useCalendarWrites, } from "./useCalendarWrites";
|
|
17
|
+
export function useMoveEvent() {
|
|
18
|
+
const queryClient = useQueryClient();
|
|
19
|
+
const { updateEvent } = useCalendarWrites();
|
|
20
|
+
return useCallback(async (event, range, scope, collectionZone) => {
|
|
21
|
+
const { calendarObjectId, recurrenceId } = readCalendarInstanceId(event.id);
|
|
22
|
+
const resource = await queryClient
|
|
23
|
+
.fetchQuery({
|
|
24
|
+
...calendarEventDetailOperationsGetCalendarEventOptions({
|
|
25
|
+
path: { calendarObjectId },
|
|
26
|
+
query: { calendarId: event.calendarId },
|
|
27
|
+
}),
|
|
28
|
+
meta: softErrorStatuses(404),
|
|
29
|
+
staleTime: 0,
|
|
30
|
+
})
|
|
31
|
+
.catch((error) => ({ unread: formatErrorMessage(error) }));
|
|
32
|
+
if ("unread" in resource)
|
|
33
|
+
return { kind: "refused", message: resource.unread };
|
|
34
|
+
const before = draftFromEvent(event, {
|
|
35
|
+
repeat: "",
|
|
36
|
+
location: "",
|
|
37
|
+
notes: "",
|
|
38
|
+
});
|
|
39
|
+
const after = {
|
|
40
|
+
...before,
|
|
41
|
+
date: range.date,
|
|
42
|
+
endDate: range.endDate,
|
|
43
|
+
startTime: range.startTime,
|
|
44
|
+
endTime: range.endTime,
|
|
45
|
+
allDay: range.allDay,
|
|
46
|
+
};
|
|
47
|
+
const patch = patchFromDrafts(before, after, {
|
|
48
|
+
clock: deviceTimeZone(),
|
|
49
|
+
anchor: storedAnchorZone(resource.icalData, collectionZone === "" ? UNZONED_CALENDAR : collectionZone),
|
|
50
|
+
});
|
|
51
|
+
if (!patch.ok)
|
|
52
|
+
return { kind: "refused", message: patch.problem };
|
|
53
|
+
return updateEvent({
|
|
54
|
+
calendarObjectId,
|
|
55
|
+
calendarId: event.calendarId,
|
|
56
|
+
recurrenceId,
|
|
57
|
+
scope,
|
|
58
|
+
etag: resource.etag,
|
|
59
|
+
}, patch.patch);
|
|
60
|
+
}, [queryClient, updateEvent]);
|
|
61
|
+
}
|
|
@@ -19,8 +19,8 @@ import { systemOperationsApplySystemUpdateMutation, systemOperationsGetSystemUpd
|
|
|
19
19
|
import { systemOperationsGetSystemUpdate } from "@remit/api-http-client/sdk.gen.ts";
|
|
20
20
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
21
21
|
import { createContext, createElement, useCallback, useContext, useEffect, useRef, useState, } from "react";
|
|
22
|
-
import { restartExpectedMeta,
|
|
23
|
-
import {
|
|
22
|
+
import { restartExpectedMeta, softErrorMeta } from "../lib/error-classifier";
|
|
23
|
+
import { escalate } from "../lib/escalate";
|
|
24
24
|
import { appliesSchemaMigration, checkAnswered, checkRequestFailureReason, deriveUpdateSurface, isSurfaceAbsent, mapUpdatePhase, releaseFromCheck, runInFlight, } from "../lib/self-update-state";
|
|
25
25
|
const IDLE_POLL_MS = 30_000;
|
|
26
26
|
const RUN_POLL_MS = 5_000;
|
|
@@ -158,9 +158,7 @@ export function useSystemUpdate() {
|
|
|
158
158
|
// This is a raw SDK call, outside the query cache that feeds the
|
|
159
159
|
// global sink, so the 5xx the seam answers when the control volume
|
|
160
160
|
// is unwritable escalates from here or from nowhere.
|
|
161
|
-
|
|
162
|
-
reportFatalError(error);
|
|
163
|
-
}
|
|
161
|
+
escalate(error, softErrorMeta);
|
|
164
162
|
setCheckPress(null);
|
|
165
163
|
setCheckFailure(checkRequestFailureReason(error));
|
|
166
164
|
});
|
|
@@ -33,5 +33,7 @@ export interface CalendarData {
|
|
|
33
33
|
retry: () => void;
|
|
34
34
|
/** The resource and occurrence behind an event the grid selected. */
|
|
35
35
|
instanceOf: (eventId: string) => CalendarInstanceRef;
|
|
36
|
+
/** The events that leave their time free rather than busy. */
|
|
37
|
+
freeIds: ReadonlySet<string>;
|
|
36
38
|
}
|
|
37
39
|
export declare function useCalendarData({ view, date, calendarIds, enabled, }: CalendarDataRequest): CalendarData;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { calendarInstanceId, calendarWindow, readCalendarInstanceId, useCalendarEventWindow, useCalendarSelection, useDrawnEvents, usePrefetchAdjacentWindows, } from "./calendar";
|
|
2
3
|
export function useCalendarData({ view, date, calendarIds, enabled = true, }) {
|
|
3
4
|
const { calendars, colorByCalendarId, timeZoneByCalendarId, shown, narrowed, resolved, isLoading, } = useCalendarSelection(calendarIds);
|
|
4
5
|
const window = calendarWindow(view, date);
|
|
@@ -10,6 +11,9 @@ export function useCalendarData({ view, date, calendarIds, enabled = true, }) {
|
|
|
10
11
|
});
|
|
11
12
|
usePrefetchAdjacentWindows(view, date, narrowed, active);
|
|
12
13
|
const eventData = useDrawnEvents(events.instances, timeZoneByCalendarId, shown);
|
|
14
|
+
const freeIds = useMemo(() => new Set(events.instances
|
|
15
|
+
.filter((instance) => instance.transparency === "Transparent")
|
|
16
|
+
.map((instance) => calendarInstanceId(instance.calendarObjectId, instance.recurrenceId))), [events.instances]);
|
|
13
17
|
return {
|
|
14
18
|
calendars,
|
|
15
19
|
events: eventData,
|
|
@@ -19,5 +23,6 @@ export function useCalendarData({ view, date, calendarIds, enabled = true, }) {
|
|
|
19
23
|
error: events.error,
|
|
20
24
|
retry: events.refetch,
|
|
21
25
|
instanceOf: readCalendarInstanceId,
|
|
26
|
+
freeIds,
|
|
22
27
|
};
|
|
23
28
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface CalendarSidePane {
|
|
2
|
+
/** The pane beside the grid on a wide tier. */
|
|
3
|
+
open: boolean;
|
|
4
|
+
toggle: () => void;
|
|
5
|
+
/** The slide-over that holds the same pane on a phone. */
|
|
6
|
+
navOpen: boolean;
|
|
7
|
+
setNavOpen: (open: boolean) => void;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The hamburger's state. On a wide tier it shows and hides the `sidebar` pane
|
|
11
|
+
* by replace and records the choice on this device; on a phone it raises the
|
|
12
|
+
* `nav` slide-over instead.
|
|
13
|
+
*/
|
|
14
|
+
export declare function useCalendarSidePane(isPhone: boolean): CalendarSidePane;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useCallback, useState } from "react";
|
|
2
|
+
import { readSidePanePref, resolveSidePaneOpen, writeSidePanePref, } from "../lib/calendar-side-pane-pref";
|
|
3
|
+
import { panelsWithOverlay, useOpenPanels, useSetOpenPanels } from "../routing";
|
|
4
|
+
/**
|
|
5
|
+
* The hamburger's state. On a wide tier it shows and hides the `sidebar` pane
|
|
6
|
+
* by replace and records the choice on this device; on a phone it raises the
|
|
7
|
+
* `nav` slide-over instead.
|
|
8
|
+
*/
|
|
9
|
+
export function useCalendarSidePane(isPhone) {
|
|
10
|
+
const panels = useOpenPanels();
|
|
11
|
+
const setOpenPanels = useSetOpenPanels();
|
|
12
|
+
const [prefersOpen, setPrefersOpen] = useState(readSidePanePref);
|
|
13
|
+
const open = !isPhone && resolveSidePaneOpen(panels, prefersOpen);
|
|
14
|
+
const navOpen = isPhone && panels.includes("nav");
|
|
15
|
+
const toggle = useCallback(() => {
|
|
16
|
+
if (isPhone) {
|
|
17
|
+
setOpenPanels(panelsWithOverlay(panels, navOpen ? undefined : "nav"));
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const next = !open;
|
|
21
|
+
writeSidePanePref(next);
|
|
22
|
+
setPrefersOpen(next);
|
|
23
|
+
const others = panels.filter((panel) => panel !== "sidebar");
|
|
24
|
+
setOpenPanels(next ? [...others, "sidebar"] : others);
|
|
25
|
+
}, [isPhone, navOpen, open, panels, setOpenPanels]);
|
|
26
|
+
const setNavOpen = useCallback((next) => {
|
|
27
|
+
setOpenPanels(panelsWithOverlay(panels, next ? "nav" : undefined));
|
|
28
|
+
}, [panels, setOpenPanels]);
|
|
29
|
+
return { open, toggle, navOpen, setNavOpen };
|
|
30
|
+
}
|