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>
38 lines
1.4 KiB
TypeScript
38 lines
1.4 KiB
TypeScript
import * as React from "react";
|
|
|
|
import { useAppNavigation } from "@/app/navigation/useAppNavigation";
|
|
import { listenForMessageDeepLinks } from "@/shared/deep-link";
|
|
|
|
/**
|
|
* Subscribe to `buzz://message` deep links emitted by the Tauri backend
|
|
* and route them through the app's navigation helpers.
|
|
*
|
|
* Lives in a hook (not inline in `AppShell`) so it can be unit-tested
|
|
* without the entire shell, and so the shell file stays under its line cap.
|
|
*
|
|
* Mirrors the cold-start race handling of the `connect` listener in
|
|
* `App.tsx`: late-arriving payloads from a fresh launch are picked up the
|
|
* first time the listener mounts. Routing matches the in-app buzz://
|
|
* handler in `markdown.tsx`: always `goChannel` with `messageId` and let
|
|
* the channel route's existing scroll-into-view + getEventById backfill
|
|
* resolve the target (works for both stream replies and forum threads).
|
|
*/
|
|
export function useMessageDeepLinks() {
|
|
const { goChannel } = useAppNavigation();
|
|
|
|
React.useEffect(() => {
|
|
let cancelled = false;
|
|
const unlistenPromise = listenForMessageDeepLinks((payload) => {
|
|
if (cancelled) return;
|
|
void goChannel(payload.channelId, {
|
|
messageId: payload.messageId,
|
|
threadRootId: payload.threadRootId,
|
|
});
|
|
});
|
|
return () => {
|
|
cancelled = true;
|
|
void unlistenPromise.then((fn) => fn());
|
|
};
|
|
}, [goChannel]);
|
|
}
|