mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2026-04-22 07:28:43 -04:00
* folder * wrote function * Abstracting duplicate on file name * Spliting between ephemeral and indexed * Now with more type safety * Forgot to prep * location + path based * bruh * link frontend + error toast * strip main separator * dumb * bruh * create directory Co-authored-by: Brendan Allan <Brendonovich@users.noreply.github.com> * make some reactivity happen --------- Co-authored-by: Ericson Fogo Soares <ericson.ds999@gmail.com> Co-authored-by: Brendan Allan <brendonovich@outlook.com> Co-authored-by: Brendan Allan <Brendonovich@users.noreply.github.com>
39 lines
1.0 KiB
TypeScript
39 lines
1.0 KiB
TypeScript
import { useEffect, useRef } from 'react';
|
|
import { useRspcLibraryContext } from '@sd/client';
|
|
|
|
import { useExplorerContext } from '../app/$libraryId/Explorer/Context';
|
|
import { useExplorerSearchParams } from '../app/$libraryId/Explorer/util';
|
|
import { useOperatingSystem } from './useOperatingSystem';
|
|
|
|
export const useQuickRescan = () => {
|
|
// subscription so that we can cancel it if in progress
|
|
const quickRescanSubscription = useRef<() => void | undefined>();
|
|
|
|
// gotta clean up any rescan subscriptions if the exist
|
|
useEffect(() => () => quickRescanSubscription.current?.(), []);
|
|
|
|
const { client } = useRspcLibraryContext();
|
|
|
|
const { parent } = useExplorerContext();
|
|
|
|
const [{ path }] = useExplorerSearchParams();
|
|
|
|
const rescan = () => {
|
|
if (parent?.type === 'Location') {
|
|
quickRescanSubscription.current?.();
|
|
quickRescanSubscription.current = client.addSubscription(
|
|
[
|
|
'locations.quickRescan',
|
|
{
|
|
location_id: parent.location.id,
|
|
sub_path: path ?? ''
|
|
}
|
|
],
|
|
{ onData() {} }
|
|
);
|
|
}
|
|
};
|
|
|
|
return rescan;
|
|
};
|