mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-01 06:53:11 +02:00
Fix active workspace deletion
This commit is contained in:
@@ -10,7 +10,7 @@ import { useFastMutation } from './useFastMutation';
|
||||
import { removeModelById } from './useSyncModelStores';
|
||||
import { workspacesAtom } from './useWorkspaces';
|
||||
|
||||
export function useDeleteWorkspace() {
|
||||
export function useDeleteActiveWorkspace() {
|
||||
const confirm = useConfirm();
|
||||
const setWorkspaces = useSetAtom(workspacesAtom);
|
||||
const navigate = useNavigate();
|
||||
@@ -39,11 +39,7 @@ export function useDeleteWorkspace() {
|
||||
// Optimistic update
|
||||
setWorkspaces(removeModelById(workspace));
|
||||
|
||||
const { id: workspaceId } = workspace;
|
||||
const activeWorkspace = getActiveWorkspace();
|
||||
if (workspaceId === activeWorkspace?.id) {
|
||||
await navigate({ to: '/workspaces' });
|
||||
}
|
||||
await navigate({ to: '/workspaces' });
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -18,8 +18,6 @@ export function useRecentWorkspaces() {
|
||||
[value, workspaces],
|
||||
);
|
||||
|
||||
|
||||
console.log("HELLO", {isLoading, value})
|
||||
if (isLoading) return null;
|
||||
|
||||
return onlyValidIds;
|
||||
@@ -29,18 +27,15 @@ export function useSubscribeRecentWorkspaces() {
|
||||
useEffect(() => {
|
||||
return jotaiStore.sub(activeWorkspaceIdAtom, async () => {
|
||||
const activeWorkspaceId = jotaiStore.get(activeWorkspaceIdAtom);
|
||||
console.log("AAA");
|
||||
if (activeWorkspaceId == null) return;
|
||||
|
||||
const key = kvKey();
|
||||
|
||||
const recentIds = await getKeyValue<string[]>({ namespace, key, fallback });
|
||||
console.log("BBB", recentIds, activeWorkspaceId);
|
||||
if (recentIds[0] === activeWorkspaceId) return; // Short-circuit
|
||||
|
||||
const withoutActiveId = recentIds.filter((id) => id !== activeWorkspaceId);
|
||||
const value = [activeWorkspaceId, ...withoutActiveId];
|
||||
console.log("SET ACTIVE WORCENT", value);
|
||||
await setKeyValue({ namespace, key, value });
|
||||
});
|
||||
}, []);
|
||||
|
||||
Reference in New Issue
Block a user