mirror of
https://github.com/block/buzz.git
synced 2026-11-02 15:31:27 +00:00
Signed-off-by: Wes <wesbillman@users.noreply.github.com> Co-authored-by: Pinky <44b8e82baa6e0e254e0208d68f335c283c94e7b78dd1fa10d5a49d3f13dd0435@sprout-oss.stage.blox.sqprod.co>
47 lines
1.7 KiB
TypeScript
47 lines
1.7 KiB
TypeScript
import { listen } from "@tauri-apps/api/event";
|
|
import { useEffect } from "react";
|
|
import { toast } from "sonner";
|
|
|
|
const MIGRATION_TOAST_KEY = "buzz-legacy-nest-migrated-notified";
|
|
|
|
/**
|
|
* Surface nest-related backend events as toasts.
|
|
*
|
|
* - `repos-dir-error`: a configured `repos_dir` failed to validate or its
|
|
* symlink could not be applied (invalid path, downgrade refused, external
|
|
* target gone). Emitted by `apply_workspace` on both the validate-reject
|
|
* and the runtime symlink-failure paths, so a bad `repos_dir` is always
|
|
* visibly surfaced rather than silently logged to console.
|
|
* - `legacy-nest-migrated`: the agent's knowledge was carried over from a
|
|
* legacy `~/.sprout` nest. Shown once per machine (deduped via
|
|
* localStorage); the backend re-emits each launch while `~/.sprout` exists,
|
|
* which also covers the event being emitted before this listener mounts.
|
|
*
|
|
* Mounted at the app root ahead of the community-init effect so the listener
|
|
* is registered before the first `apply_workspace` call.
|
|
*/
|
|
export function useNestNotifications(): void {
|
|
useEffect(() => {
|
|
const unlistenReposError = listen<string>("repos-dir-error", (event) => {
|
|
toast.error("Repos directory not applied", {
|
|
description: event.payload,
|
|
});
|
|
});
|
|
|
|
const unlistenMigrated = listen("legacy-nest-migrated", () => {
|
|
if (localStorage.getItem(MIGRATION_TOAST_KEY) === "true") {
|
|
return;
|
|
}
|
|
localStorage.setItem(MIGRATION_TOAST_KEY, "true");
|
|
toast.success("Migrated notes from ~/.sprout", {
|
|
description: "You can delete it to reclaim disk space.",
|
|
});
|
|
});
|
|
|
|
return () => {
|
|
void unlistenReposError.then((fn) => fn());
|
|
void unlistenMigrated.then((fn) => fn());
|
|
};
|
|
}, []);
|
|
}
|