@kortix/ui 0.15.1 → 0.15.2
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/_vendor/shared/index.d.ts +0 -2
- package/dist/artifacts/artifact-frame.d.ts +0 -1
- package/dist/artifacts/artifact-frame.js +4 -10
- package/dist/artifacts/artifact-session.js +2 -6
- package/dist/artifacts/frame-policy.d.ts +1 -1
- package/dist/artifacts/frame-policy.js +2 -2
- package/dist/customize/sections/view/agent-editor-catalog.js +0 -5
- package/dist/customize/triggers/schedule/trigger-list.d.ts +2 -2
- package/dist/customize/triggers/schedule/trigger-list.js +12 -18
- package/dist/i18n/en.d.ts +8 -185
- package/dist/i18n/en.js +13 -190
- package/dist/internal/components/agent-mark.js +6 -0
- package/dist/internal/components/clickable-path.d.ts +3 -0
- package/dist/internal/components/clickable-path.js +4 -1
- package/dist/internal/lib/browser-noise/rules/injected-scripts.js +11 -0
- package/dist/internal/lib/trigger-clock.d.ts +5 -0
- package/dist/internal/lib/trigger-clock.js +15 -0
- package/dist/internal/lib/turn-broadcast.d.ts +0 -3
- package/dist/internal/lib/use-project-feature-flags.d.ts +2 -0
- package/dist/internal/lib/use-project-feature-flags.js +2 -4
- package/dist/internal/lib/web-notifications.d.ts +1 -8
- package/dist/internal/lib/web-notifications.js +12 -53
- package/dist/internal/notifications/notification-bell.d.ts +13 -33
- package/dist/internal/notifications/notification-bell.js +14 -117
- package/dist/internal/notifications/notification-inbox.d.ts +45 -0
- package/dist/internal/notifications/notification-inbox.js +119 -0
- package/dist/internal/notifications/notification-rows.d.ts +3 -4
- package/dist/internal/notifications/notification-rows.js +1 -4
- package/dist/internal/notifications/use-inbox-summary.d.ts +13 -0
- package/dist/internal/notifications/use-inbox-summary.js +22 -0
- package/dist/internal/notifications/web-push.d.ts +9 -10
- package/dist/internal/notifications/web-push.js +9 -10
- package/dist/internal/stores/web-notification-store.d.ts +6 -9
- package/dist/internal/stores/web-notification-store.js +0 -4
- package/dist/lib/routes.d.ts +8 -0
- package/dist/lib/routes.js +4 -1
- package/dist/markdown/doc-editor/doc-menus.d.ts +1 -10
- package/dist/markdown/doc-editor/doc-menus.js +6 -69
- package/dist/markdown/file-links.js +21 -0
- package/dist/primitives/button.d.ts +1 -1
- package/dist/session/header/reminder-parts.d.ts +1 -1
- package/dist/session/header/session-site-header.js +2 -6
- package/dist/session/panel/session-reminders-panel.js +4 -15
- package/dist/session/tool/tools/session-spawn-tool.js +7 -4
- package/dist/session/tool/tools/task-tool.js +18 -4
- package/dist/styles.css +1 -1
- package/dist/workspace/home/access-requests-bell.d.ts +6 -9
- package/dist/workspace/home/access-requests-bell.js +8 -10
- package/dist/workspace/layout/project-home.js +1 -2
- package/dist/workspace/sidebar/project-sidebar.js +2 -6
- package/package.json +11 -7
- package/skills/kortix-ui/references/custom-dashboard.md +1 -1
- package/dist/_vendor/shared/artifact-annotations.d.ts +0 -311
- package/dist/_vendor/shared/artifact-comments.d.ts +0 -155
- package/dist/internal/hooks/use-notification-center.d.ts +0 -50
- package/dist/internal/hooks/use-notification-center.js +0 -151
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
/** The longest text quote, in UTF-16 code units: a paragraph. A longer selection is refused, never cut. */
|
|
3
|
-
export declare const ARTIFACT_TEXT_QUOTE_MAX = 500;
|
|
4
|
-
/** The longest prefix and suffix, in UTF-16 code units. */
|
|
5
|
-
export declare const ARTIFACT_TEXT_CONTEXT_MAX = 32;
|
|
6
|
-
export declare const artifactCommentAnchorSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
7
|
-
type: z.ZodLiteral<"text">;
|
|
8
|
-
version: z.ZodString;
|
|
9
|
-
quote: z.ZodString;
|
|
10
|
-
prefix: z.ZodString;
|
|
11
|
-
suffix: z.ZodString;
|
|
12
|
-
}, z.core.$strict>, z.ZodObject<{
|
|
13
|
-
offset: z.ZodObject<{
|
|
14
|
-
x: z.ZodNumber;
|
|
15
|
-
y: z.ZodNumber;
|
|
16
|
-
}, z.core.$strict>;
|
|
17
|
-
version: z.ZodString;
|
|
18
|
-
selector: z.ZodString;
|
|
19
|
-
snippet: z.ZodString;
|
|
20
|
-
viewport_width: z.ZodNumber;
|
|
21
|
-
scroll: z.ZodObject<{
|
|
22
|
-
x: z.ZodNumber;
|
|
23
|
-
y: z.ZodNumber;
|
|
24
|
-
}, z.core.$strict>;
|
|
25
|
-
type: z.ZodLiteral<"point">;
|
|
26
|
-
}, z.core.$strict>, z.ZodObject<{
|
|
27
|
-
offset: z.ZodObject<{
|
|
28
|
-
x: z.ZodNumber;
|
|
29
|
-
y: z.ZodNumber;
|
|
30
|
-
width: z.ZodNumber;
|
|
31
|
-
height: z.ZodNumber;
|
|
32
|
-
}, z.core.$strict>;
|
|
33
|
-
version: z.ZodString;
|
|
34
|
-
selector: z.ZodString;
|
|
35
|
-
snippet: z.ZodString;
|
|
36
|
-
viewport_width: z.ZodNumber;
|
|
37
|
-
scroll: z.ZodObject<{
|
|
38
|
-
x: z.ZodNumber;
|
|
39
|
-
y: z.ZodNumber;
|
|
40
|
-
}, z.core.$strict>;
|
|
41
|
-
type: z.ZodLiteral<"region">;
|
|
42
|
-
}, z.core.$strict>, z.ZodObject<{
|
|
43
|
-
type: z.ZodLiteral<"none">;
|
|
44
|
-
version: z.ZodString;
|
|
45
|
-
}, z.core.$strict>], "type">;
|
|
46
|
-
export declare const artifactCommentMarkSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
47
|
-
points: z.ZodArray<z.ZodObject<{
|
|
48
|
-
x: z.ZodNumber;
|
|
49
|
-
y: z.ZodNumber;
|
|
50
|
-
}, z.core.$strict>>;
|
|
51
|
-
color: z.ZodEnum<{
|
|
52
|
-
red: "red";
|
|
53
|
-
blue: "blue";
|
|
54
|
-
black: "black";
|
|
55
|
-
}>;
|
|
56
|
-
width: z.ZodNumber;
|
|
57
|
-
tool: z.ZodLiteral<"pen">;
|
|
58
|
-
}, z.core.$strict>, z.ZodObject<{
|
|
59
|
-
points: z.ZodArray<z.ZodObject<{
|
|
60
|
-
x: z.ZodNumber;
|
|
61
|
-
y: z.ZodNumber;
|
|
62
|
-
}, z.core.$strict>>;
|
|
63
|
-
color: z.ZodEnum<{
|
|
64
|
-
red: "red";
|
|
65
|
-
blue: "blue";
|
|
66
|
-
black: "black";
|
|
67
|
-
}>;
|
|
68
|
-
width: z.ZodNumber;
|
|
69
|
-
tool: z.ZodLiteral<"arrow">;
|
|
70
|
-
}, z.core.$strict>, z.ZodObject<{
|
|
71
|
-
points: z.ZodArray<z.ZodObject<{
|
|
72
|
-
x: z.ZodNumber;
|
|
73
|
-
y: z.ZodNumber;
|
|
74
|
-
}, z.core.$strict>>;
|
|
75
|
-
color: z.ZodEnum<{
|
|
76
|
-
red: "red";
|
|
77
|
-
blue: "blue";
|
|
78
|
-
black: "black";
|
|
79
|
-
}>;
|
|
80
|
-
width: z.ZodNumber;
|
|
81
|
-
tool: z.ZodLiteral<"rectangle">;
|
|
82
|
-
}, z.core.$strict>], "tool">;
|
|
83
|
-
export declare const artifactCommentMarksSchema: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
84
|
-
points: z.ZodArray<z.ZodObject<{
|
|
85
|
-
x: z.ZodNumber;
|
|
86
|
-
y: z.ZodNumber;
|
|
87
|
-
}, z.core.$strict>>;
|
|
88
|
-
color: z.ZodEnum<{
|
|
89
|
-
red: "red";
|
|
90
|
-
blue: "blue";
|
|
91
|
-
black: "black";
|
|
92
|
-
}>;
|
|
93
|
-
width: z.ZodNumber;
|
|
94
|
-
tool: z.ZodLiteral<"pen">;
|
|
95
|
-
}, z.core.$strict>, z.ZodObject<{
|
|
96
|
-
points: z.ZodArray<z.ZodObject<{
|
|
97
|
-
x: z.ZodNumber;
|
|
98
|
-
y: z.ZodNumber;
|
|
99
|
-
}, z.core.$strict>>;
|
|
100
|
-
color: z.ZodEnum<{
|
|
101
|
-
red: "red";
|
|
102
|
-
blue: "blue";
|
|
103
|
-
black: "black";
|
|
104
|
-
}>;
|
|
105
|
-
width: z.ZodNumber;
|
|
106
|
-
tool: z.ZodLiteral<"arrow">;
|
|
107
|
-
}, z.core.$strict>, z.ZodObject<{
|
|
108
|
-
points: z.ZodArray<z.ZodObject<{
|
|
109
|
-
x: z.ZodNumber;
|
|
110
|
-
y: z.ZodNumber;
|
|
111
|
-
}, z.core.$strict>>;
|
|
112
|
-
color: z.ZodEnum<{
|
|
113
|
-
red: "red";
|
|
114
|
-
blue: "blue";
|
|
115
|
-
black: "black";
|
|
116
|
-
}>;
|
|
117
|
-
width: z.ZodNumber;
|
|
118
|
-
tool: z.ZodLiteral<"rectangle">;
|
|
119
|
-
}, z.core.$strict>], "tool">>;
|
|
120
|
-
export type ArtifactCommentMark = z.infer<typeof artifactCommentMarkSchema>;
|
|
121
|
-
export type ArtifactCommentAnchor = z.infer<typeof artifactCommentAnchorSchema>;
|
|
122
|
-
export type ArtifactTextAnchor = Extract<ArtifactCommentAnchor, {
|
|
123
|
-
type: 'text';
|
|
124
|
-
}>;
|
|
125
|
-
export type ArtifactTextPosition = {
|
|
126
|
-
start: number | null;
|
|
127
|
-
end: number | null;
|
|
128
|
-
outdated: boolean;
|
|
129
|
-
};
|
|
130
|
-
/**
|
|
131
|
-
* The re-anchoring work one read may spend across all its threads (about 100 ms):
|
|
132
|
-
* fuzzy-scanned code units plus alignment cells, and an eighth of a code unit
|
|
133
|
-
* per natively exact-scanned one. A list re-anchors every stored thread, and a
|
|
134
|
-
* commenter can store many unmatched quotes, so the cost of one read must not
|
|
135
|
-
* grow with the thread count. A thread past the budget is outdated for that read.
|
|
136
|
-
*/
|
|
137
|
-
export declare const ARTIFACT_REANCHOR_READ_UNITS: number;
|
|
138
|
-
export interface ArtifactReanchorBudget {
|
|
139
|
-
remaining: number;
|
|
140
|
-
}
|
|
141
|
-
/** One budget per read: pass the same object to every reanchorArtifactText call of that read. */
|
|
142
|
-
export declare function createArtifactReanchorBudget(): ArtifactReanchorBudget;
|
|
143
|
-
/**
|
|
144
|
-
* The read budget split into equal shares, one per thread author (a person or an
|
|
145
|
-
* agent session). A commenter whose quotes match nothing spends only their own
|
|
146
|
-
* share, so other people's threads still re-anchor; the read's total stays at
|
|
147
|
-
* ARTIFACT_REANCHOR_READ_UNITS. Name every author of the read up front.
|
|
148
|
-
*/
|
|
149
|
-
export declare function createArtifactReanchorBudgets(authors: Iterable<string>): (author: string) => ArtifactReanchorBudget;
|
|
150
|
-
/**
|
|
151
|
-
* Where a text anchor sits in `text` now. Every scan spends `budget`; a caller
|
|
152
|
-
* that re-anchors many threads in one read passes one shared budget
|
|
153
|
-
* (createArtifactReanchorBudget), so the read's cost is bounded.
|
|
154
|
-
*/
|
|
155
|
-
export declare function reanchorArtifactText(text: string, anchor: ArtifactTextAnchor, budget?: ArtifactReanchorBudget): ArtifactTextPosition;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/** @internal Kortix apps only. No semver: it may change in any release. */
|
|
2
|
-
/**
|
|
3
|
-
* The strict `notification_center` gate controls session mute/watch actions.
|
|
4
|
-
* Inbox surfaces also work when artifacts and artifact_comments are both on.
|
|
5
|
-
*
|
|
6
|
-
* - With a project id: `useFeatureFlag`, fail-closed, on the shared bare
|
|
7
|
-
* project row (`qk.project.summary(id)`) that the project shell reads.
|
|
8
|
-
* - Without one (`/projects`, `/new`, standalone `/settings`): on when any
|
|
9
|
-
* project already in this client's query cache has the flag on. The scan
|
|
10
|
-
* reads the cached project rows, project details and project lists. It sends no request,
|
|
11
|
-
* so a cold load of such a page with nothing cached reads off.
|
|
12
|
-
* - `NotificationHost` uses `useNotificationHostGate`: while a project's
|
|
13
|
-
* row loads, a cached detail, a cached project list or its previous answer
|
|
14
|
-
* decides.
|
|
15
|
-
*/
|
|
16
|
-
import type { KortixProject } from '@kortix/sdk';
|
|
17
|
-
import { type QueryClient } from '@tanstack/react-query';
|
|
18
|
-
export declare const NOTIFICATION_CENTER_FLAG = "notification_center";
|
|
19
|
-
type FlagHolder = {
|
|
20
|
-
experimental?: Partial<NonNullable<KortixProject['experimental']>>;
|
|
21
|
-
} | null | undefined;
|
|
22
|
-
/** The predicate of `useFeatureFlag`: the server said exactly `true`. */
|
|
23
|
-
export declare function notificationCenterOn(project: FlagHolder): boolean;
|
|
24
|
-
export declare function notificationInboxOn(project: FlagHolder): boolean;
|
|
25
|
-
/**
|
|
26
|
-
* The flag for one project from the query cache: its row, else its detail,
|
|
27
|
-
* else a cached project list that holds it. Undefined when none holds it.
|
|
28
|
-
* Sends no request.
|
|
29
|
-
*/
|
|
30
|
-
export declare function cachedNotificationCenterAnswer(client: QueryClient | null, projectId: string | null | undefined): boolean | undefined;
|
|
31
|
-
export declare function cachedNotificationInboxAnswer(client: QueryClient | null, projectId: string | null | undefined): boolean | undefined;
|
|
32
|
-
/** The flag for one project from the query cache. False when nothing cached holds it. */
|
|
33
|
-
export declare function cachedNotificationCenter(client: QueryClient | null, projectId: string | null | undefined): boolean;
|
|
34
|
-
/** True when any project in the query cache has the flag on. */
|
|
35
|
-
export declare function anyCachedNotificationCenter(client: QueryClient): boolean;
|
|
36
|
-
export declare function anyCachedNotificationInbox(client: QueryClient): boolean;
|
|
37
|
-
/** Is the notification center on for `projectId`, or, without one, for any cached project. */
|
|
38
|
-
export declare function useNotificationCenter(projectId?: string | null): boolean;
|
|
39
|
-
export declare function useNotificationInboxEnabled(projectId?: string | null): boolean;
|
|
40
|
-
/**
|
|
41
|
-
* The inbox gate of `NotificationHost`, except while the
|
|
42
|
-
* project's row loads. Then a cached detail or project list answers, else the
|
|
43
|
-
* previous answer stays. So entering a flag-on project from `/projects` or
|
|
44
|
-
* from another flag-on project does not unmount the host and subscribe Web
|
|
45
|
-
* Push again. Only a loaded detail without the flag turns it off. A cold
|
|
46
|
-
* load of a project page starts off. Only a loaded row (or, before it, a
|
|
47
|
-
* loaded detail) without the flag turns it off.
|
|
48
|
-
*/
|
|
49
|
-
export declare function useNotificationHostGate(projectId?: string | null): boolean;
|
|
50
|
-
export {};
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { qk, useFeatureFlag } from '@kortix/sdk/react';
|
|
3
|
-
import { useQueryClient } from '@tanstack/react-query';
|
|
4
|
-
import { useCallback, useState, useSyncExternalStore } from 'react';
|
|
5
|
-
export const NOTIFICATION_CENTER_FLAG = 'notification_center';
|
|
6
|
-
/** The predicate of `useFeatureFlag`: the server said exactly `true`. */
|
|
7
|
-
export function notificationCenterOn(project) {
|
|
8
|
-
return project?.experimental?.[NOTIFICATION_CENTER_FLAG] === true;
|
|
9
|
-
}
|
|
10
|
-
export function notificationInboxOn(project) {
|
|
11
|
-
return notificationCenterOn(project) || (project?.experimental?.artifacts === true && project.experimental.artifact_comments === true);
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* The flag for one project from the query cache: its row, else its detail,
|
|
15
|
-
* else a cached project list that holds it. Undefined when none holds it.
|
|
16
|
-
* Sends no request.
|
|
17
|
-
*/
|
|
18
|
-
export function cachedNotificationCenterAnswer(client, projectId) {
|
|
19
|
-
return cachedFlagAnswer(client, projectId, notificationCenterOn);
|
|
20
|
-
}
|
|
21
|
-
function cachedFlagAnswer(client, projectId, enabled) {
|
|
22
|
-
if (!client || !projectId)
|
|
23
|
-
return undefined;
|
|
24
|
-
const row = client.getQueryData(qk.project.summary(projectId));
|
|
25
|
-
if (row)
|
|
26
|
-
return enabled(row);
|
|
27
|
-
const detail = client.getQueryData(qk.project.detail(projectId));
|
|
28
|
-
if (detail?.project)
|
|
29
|
-
return enabled(detail.project);
|
|
30
|
-
for (const [, data] of client.getQueriesData({ queryKey: qk.projects.scope() })) {
|
|
31
|
-
if (!Array.isArray(data))
|
|
32
|
-
continue;
|
|
33
|
-
const project = data.find((row) => row?.project_id === projectId);
|
|
34
|
-
if (project)
|
|
35
|
-
return enabled(project);
|
|
36
|
-
}
|
|
37
|
-
return undefined;
|
|
38
|
-
}
|
|
39
|
-
export function cachedNotificationInboxAnswer(client, projectId) {
|
|
40
|
-
return cachedFlagAnswer(client, projectId, notificationInboxOn);
|
|
41
|
-
}
|
|
42
|
-
/** The flag for one project from the query cache. False when nothing cached holds it. */
|
|
43
|
-
export function cachedNotificationCenter(client, projectId) {
|
|
44
|
-
return cachedNotificationCenterAnswer(client, projectId) === true;
|
|
45
|
-
}
|
|
46
|
-
const [ROOT, LIST_SCOPE] = qk.projects.scope();
|
|
47
|
-
const [, DETAIL_SCOPE, , DETAIL] = qk.project.detail('');
|
|
48
|
-
const [, , , SUMMARY] = qk.project.summary('');
|
|
49
|
-
/** A project-list, project-row or project-detail entry that holds a project with the flag on. */
|
|
50
|
-
function holdsFlagOn(query, enabled) {
|
|
51
|
-
const key = query.queryKey;
|
|
52
|
-
const data = query.state.data;
|
|
53
|
-
if (key[0] !== ROOT)
|
|
54
|
-
return false;
|
|
55
|
-
if (key[1] === LIST_SCOPE)
|
|
56
|
-
return Array.isArray(data) && data.some(enabled);
|
|
57
|
-
if (key[1] === DETAIL_SCOPE && key.length === 4 && key[3] === DETAIL) {
|
|
58
|
-
return enabled(data?.project);
|
|
59
|
-
}
|
|
60
|
-
if (key[1] === DETAIL_SCOPE && key.length === 4 && key[3] === SUMMARY)
|
|
61
|
-
return enabled(data);
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
/** True when any project in the query cache has the flag on. */
|
|
65
|
-
export function anyCachedNotificationCenter(client) {
|
|
66
|
-
return client.getQueryCache().getAll().some((query) => holdsFlagOn(query, notificationCenterOn));
|
|
67
|
-
}
|
|
68
|
-
export function anyCachedNotificationInbox(client) {
|
|
69
|
-
return client.getQueryCache().getAll().some((query) => holdsFlagOn(query, notificationInboxOn));
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* A `useSyncExternalStore` subscription to the query cache, live only while
|
|
73
|
-
* `active`. The cache reports synchronously, also when another component's
|
|
74
|
-
* `useQuery` builds its query during render; the re-check waits for a
|
|
75
|
-
* microtask so this component never updates in the middle of that render.
|
|
76
|
-
*/
|
|
77
|
-
function useCacheSubscription(client, active) {
|
|
78
|
-
return useCallback((onChange) => {
|
|
79
|
-
if (!active)
|
|
80
|
-
return () => { };
|
|
81
|
-
let live = true;
|
|
82
|
-
const unsubscribe = client.getQueryCache().subscribe(() => {
|
|
83
|
-
queueMicrotask(() => {
|
|
84
|
-
if (live)
|
|
85
|
-
onChange();
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
return () => {
|
|
89
|
-
live = false;
|
|
90
|
-
unsubscribe();
|
|
91
|
-
};
|
|
92
|
-
}, [client, active]);
|
|
93
|
-
}
|
|
94
|
-
/** `anyCachedNotificationCenter`, reactive. Subscribes to the cache only while `scan`. */
|
|
95
|
-
function useAnyCachedNotificationCenter(client, scan) {
|
|
96
|
-
return useSyncExternalStore(useCacheSubscription(client, scan), () => scan && anyCachedNotificationCenter(client), () => false);
|
|
97
|
-
}
|
|
98
|
-
function useAnyCachedNotificationInbox(client, scan) {
|
|
99
|
-
return useSyncExternalStore(useCacheSubscription(client, scan), () => scan && anyCachedNotificationInbox(client), () => false);
|
|
100
|
-
}
|
|
101
|
-
/** Is the notification center on for `projectId`, or, without one, for any cached project. */
|
|
102
|
-
export function useNotificationCenter(projectId) {
|
|
103
|
-
const project = useFeatureFlag(projectId, NOTIFICATION_CENTER_FLAG).enabled;
|
|
104
|
-
const anyProject = useAnyCachedNotificationCenter(useQueryClient(), !projectId);
|
|
105
|
-
return projectId ? project : anyProject;
|
|
106
|
-
}
|
|
107
|
-
export function useNotificationInboxEnabled(projectId) {
|
|
108
|
-
const center = useFeatureFlag(projectId, NOTIFICATION_CENTER_FLAG).enabled;
|
|
109
|
-
const artifacts = useFeatureFlag(projectId, 'artifacts').enabled;
|
|
110
|
-
const comments = useFeatureFlag(projectId, 'artifact_comments').enabled;
|
|
111
|
-
const anyProject = useAnyCachedNotificationInbox(useQueryClient(), !projectId);
|
|
112
|
-
return projectId ? center || (artifacts && comments) : anyProject;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* The inbox gate of `NotificationHost`, except while the
|
|
116
|
-
* project's row loads. Then a cached detail or project list answers, else the
|
|
117
|
-
* previous answer stays. So entering a flag-on project from `/projects` or
|
|
118
|
-
* from another flag-on project does not unmount the host and subscribe Web
|
|
119
|
-
* Push again. Only a loaded detail without the flag turns it off. A cold
|
|
120
|
-
* load of a project page starts off. Only a loaded row (or, before it, a
|
|
121
|
-
* loaded detail) without the flag turns it off.
|
|
122
|
-
*/
|
|
123
|
-
export function useNotificationHostGate(projectId) {
|
|
124
|
-
const client = useQueryClient();
|
|
125
|
-
// The global host sits outside the access boundary. Read the shell's project
|
|
126
|
-
// row from the cache (the detail when no row is cached): no request for a potentially revoked project, and no
|
|
127
|
-
// observer. An observer added a detail query without a queryFn (also for the
|
|
128
|
-
// empty id of a page outside any project), and every refetch of it logged
|
|
129
|
-
// "No queryFn was passed".
|
|
130
|
-
const subscribe = useCacheSubscription(client, !!projectId);
|
|
131
|
-
const row = useSyncExternalStore(subscribe, () => (projectId ? client.getQueryState(qk.project.summary(projectId)) : undefined), () => undefined);
|
|
132
|
-
const detail = useSyncExternalStore(subscribe, () => (projectId ? client.getQueryState(qk.project.detail(projectId)) : undefined), () => undefined);
|
|
133
|
-
const rowLoaded = !!row && row.status !== 'pending';
|
|
134
|
-
const detailLoaded = !!detail && detail.status !== 'pending';
|
|
135
|
-
const flag = {
|
|
136
|
-
isLoading: !rowLoaded && !detailLoaded,
|
|
137
|
-
enabled: notificationInboxOn(rowLoaded ? row?.data : detail?.data?.project),
|
|
138
|
-
};
|
|
139
|
-
const anyProject = useAnyCachedNotificationInbox(client, !projectId);
|
|
140
|
-
const [previous, setPrevious] = useState(false);
|
|
141
|
-
let answer = anyProject;
|
|
142
|
-
if (projectId) {
|
|
143
|
-
answer = flag.isLoading
|
|
144
|
-
? (cachedNotificationInboxAnswer(client, projectId) ?? previous)
|
|
145
|
-
: flag.enabled;
|
|
146
|
-
}
|
|
147
|
-
// The answer from an earlier render: React's derived-state pattern.
|
|
148
|
-
if (answer !== previous)
|
|
149
|
-
setPrevious(answer);
|
|
150
|
-
return answer;
|
|
151
|
-
}
|