mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-21 08:21:19 +02:00
Refactor desktop app into separate client and proxy apps
This commit is contained in:
31
apps/yaak-client/hooks/useActiveWorkspaceChangedToast.tsx
Normal file
31
apps/yaak-client/hooks/useActiveWorkspaceChangedToast.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { InlineCode } from '../components/core/InlineCode';
|
||||
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]);
|
||||
}
|
||||
Reference in New Issue
Block a user