mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-18 23:44:12 +01:00
Better active workspace change notification
This commit is contained in:
30
src-web/hooks/useAtiveWorkspaceChangedToast.tsx
Normal file
30
src-web/hooks/useAtiveWorkspaceChangedToast.tsx
Normal file
@@ -0,0 +1,30 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { InlineCode } from '../components/core/InlineCode';
|
||||
import { useToast } from '../components/ToastContext';
|
||||
import { useActiveWorkspace } from './useActiveWorkspace';
|
||||
|
||||
export function useAtiveWorkspaceChangedToast() {
|
||||
const toast = useToast();
|
||||
const activeWorkspace = useActiveWorkspace();
|
||||
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 first load
|
||||
if (id === null) return;
|
||||
|
||||
toast.show({
|
||||
id: 'workspace-changed',
|
||||
timeout: 3000,
|
||||
message: (
|
||||
<>
|
||||
Switched workspace to <InlineCode>{activeWorkspace.name}</InlineCode>
|
||||
</>
|
||||
),
|
||||
});
|
||||
}, [activeWorkspace, id, toast]);
|
||||
}
|
||||
Reference in New Issue
Block a user