mirror of
https://github.com/block/buzz.git
synced 2026-08-18 06:50:31 +02:00
Signed-off-by: Wes <wesbillman@users.noreply.github.com> Co-authored-by: Pinky <44b8e82baa6e0e254e0208d68f335c283c94e7b78dd1fa10d5a49d3f13dd0435@sprout-oss.stage.blox.sqprod.co>
98 lines
2.3 KiB
TypeScript
98 lines
2.3 KiB
TypeScript
import { isThreadReply } from "@/features/messages/lib/threading";
|
|
import type { DesktopNotificationTarget } from "@/features/notifications/lib/desktop";
|
|
import type { SearchHit } from "@/shared/api/types";
|
|
|
|
export type AppView =
|
|
| "home"
|
|
| "channel"
|
|
| "agents"
|
|
| "workflows"
|
|
| "pulse"
|
|
| "projects";
|
|
|
|
const WINDOW_DRAG_HANDLE_HEIGHT = 44;
|
|
const WINDOW_DRAG_INTERACTIVE_SELECTOR =
|
|
'button, a, input, textarea, select, [role="button"], [contenteditable="true"]';
|
|
|
|
export function isWindowDragHandleEvent(event: MouseEvent | PointerEvent) {
|
|
if (event.clientY > WINDOW_DRAG_HANDLE_HEIGHT) {
|
|
return false;
|
|
}
|
|
|
|
const target = event.target;
|
|
return !(
|
|
target instanceof Element &&
|
|
target.closest(WINDOW_DRAG_INTERACTIVE_SELECTOR)
|
|
);
|
|
}
|
|
|
|
export function shouldBounceForChannelNotification(tags: string[][]): boolean {
|
|
return !isThreadReply(tags);
|
|
}
|
|
|
|
export function toSearchHit(
|
|
target: DesktopNotificationTarget,
|
|
): SearchHit | null {
|
|
if (!target.eventId) {
|
|
return null;
|
|
}
|
|
|
|
return {
|
|
eventId: target.eventId,
|
|
content: target.content ?? "",
|
|
kind: target.kind ?? 9,
|
|
pubkey: target.pubkey ?? "",
|
|
channelId: target.channelId,
|
|
channelName: target.channelName ?? null,
|
|
createdAt: target.createdAt ?? Math.floor(Date.now() / 1_000),
|
|
score: 0,
|
|
threadRootId: target.threadRootId ?? null,
|
|
};
|
|
}
|
|
|
|
export function deriveShellRoute(pathname: string): {
|
|
selectedChannelId: string | null;
|
|
selectedView: AppView;
|
|
} {
|
|
if (pathname.startsWith("/channels/")) {
|
|
const [, , rawChannelId] = pathname.split("/");
|
|
return {
|
|
selectedChannelId: rawChannelId ? decodeURIComponent(rawChannelId) : null,
|
|
selectedView: "channel",
|
|
};
|
|
}
|
|
|
|
if (pathname === "/agents") {
|
|
return {
|
|
selectedChannelId: null,
|
|
selectedView: "agents",
|
|
};
|
|
}
|
|
|
|
if (pathname === "/workflows" || pathname.startsWith("/workflows/")) {
|
|
return {
|
|
selectedChannelId: null,
|
|
selectedView: "workflows",
|
|
};
|
|
}
|
|
|
|
if (pathname === "/projects" || pathname.startsWith("/projects/")) {
|
|
return {
|
|
selectedChannelId: null,
|
|
selectedView: "projects",
|
|
};
|
|
}
|
|
|
|
if (pathname === "/pulse") {
|
|
return {
|
|
selectedChannelId: null,
|
|
selectedView: "pulse",
|
|
};
|
|
}
|
|
|
|
return {
|
|
selectedChannelId: null,
|
|
selectedView: "home",
|
|
};
|
|
}
|