Files
upstream-yaak/apps/yaak-client/hooks/useActiveWorkspaceChangedToast.tsx
upstream-mirror 906fb231cc
Some checks failed
Lint and Test / Lint/Test (push) Has been cancelled
Generate Sponsors README / deploy (push) Has been skipped
snapshot of https://github.com/mountain-loop/yaak.git (main, 2026-09-23; blobs > 131072B omitted)
2026-09-23 17:39:41 +05:00

32 lines
984 B
TypeScript

import { useAtomValue } from "jotai";
import { useEffect, useState } from "react";
import { InlineCode } from "@yaakapp-internal/ui";
import { showToast } from "../lib/toast";
import { activeWorkspaceAtom } from "./useActiveWorkspace";
export function useActiveWorkspaceChangedToast() {
const activeWorkspace = useAtomValue(activeWorkspaceAtom);
const [id, setId] = useState<string | null>(activeWorkspace?.id ?? null);
useEffect(() => {
// Early return if same or invalid active workspace
if (id === activeWorkspace?.id || activeWorkspace == null) return;
setId(activeWorkspace?.id ?? null);
// Don't notify on the first load
if (id === null) return;
showToast({
id: `workspace-changed-${activeWorkspace.id}`,
timeout: 3000,
message: (
<>
Activated workspace{" "}
<InlineCode className="whitespace-nowrap">{activeWorkspace.name}</InlineCode>
</>
),
});
}, [activeWorkspace, id]);
}