mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2026-04-19 22:19:49 -04:00
[ENG-343] Navigate to / when library is switched (#574)
navigate to `/` when library is switched
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { PropsWithChildren, createContext, useCallback, useContext, useMemo } from 'react';
|
||||
import { useNavigate } from 'react-router';
|
||||
import { subscribe, useSnapshot } from 'valtio';
|
||||
import { useBridgeQuery } from '../rspc';
|
||||
import { valtioPersist } from '../stores';
|
||||
@@ -34,6 +35,8 @@ export function onLibraryChange(func: (newLibraryId: string | null) => void) {
|
||||
|
||||
// this is a hook to get the current library loaded into the UI. It takes care of a bunch of invariants under the hood.
|
||||
export const useCurrentLibrary = () => {
|
||||
const navigate = useNavigate();
|
||||
|
||||
const currentLibraryUuid = useSnapshot(currentLibraryUuidStore).id;
|
||||
const ctx = useContext(CringeContext);
|
||||
if (ctx === undefined)
|
||||
@@ -66,9 +69,13 @@ export const useCurrentLibrary = () => {
|
||||
}
|
||||
});
|
||||
|
||||
const switchLibrary = useCallback((libraryUuid: string) => {
|
||||
currentLibraryUuidStore.id = libraryUuid;
|
||||
}, []);
|
||||
const switchLibrary = useCallback(
|
||||
(libraryUuid: string) => {
|
||||
currentLibraryUuidStore.id = libraryUuid;
|
||||
navigate('/');
|
||||
},
|
||||
[navigate]
|
||||
);
|
||||
|
||||
// memorize library to avoid re-running find function
|
||||
const library = useMemo(() => {
|
||||
|
||||
Reference in New Issue
Block a user