mirror of
https://github.com/spacedriveapp/spacedrive
synced 2024-07-05 09:13:28 +00:00
[ENG-343] Navigate to /
when library is switched (#574)
navigate to `/` when library is switched
This commit is contained in:
parent
4cc582e08c
commit
ac2f7a2cd2
|
@ -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(() => {
|
||||
|
|
Loading…
Reference in a new issue