mirror of
https://github.com/spacedriveapp/spacedrive
synced 2024-07-13 03:44:03 +00:00
* more translation keys * added i18n keys for future ObjectKindEnum translation * more keys * added more keys * synced all new translation keys with all languages, translated keys on Belarusian and Russian * added translation for objectkinds in overview * added translation function for objectkinds * added more keys to german locale * renamed 'asc' and 'desc' keys * rolled back changes * added missed key * there are much more keys, than you can imagine * fixed misspelling * removed console.log * removed function "pluralize", added required plural words keys for each language * fixed condition, which could've lead to undefined value * hide filter description for boolean filters
49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
import { useEffect, useRef } from 'react';
|
|
import { useRspcLibraryContext } from '@sd/client';
|
|
import { toast } from '@sd/ui';
|
|
import { explorerStore } from '~/app/$libraryId/Explorer/store';
|
|
|
|
import { useExplorerContext } from '../app/$libraryId/Explorer/Context';
|
|
import { useExplorerSearchParams } from '../app/$libraryId/Explorer/util';
|
|
import { useLocale } from './useLocale';
|
|
|
|
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 explorer = useExplorerContext({ suspense: false });
|
|
const [{ path }] = useExplorerSearchParams();
|
|
const { t } = useLocale();
|
|
|
|
const rescan = (id?: number) => {
|
|
const locationId =
|
|
id ?? (explorer?.parent?.type === 'Location' ? explorer.parent.location.id : undefined);
|
|
|
|
if (locationId === undefined) return;
|
|
if (Date.now() - explorerStore.quickRescanLastRun < 200) return;
|
|
|
|
explorerStore.quickRescanLastRun = Date.now();
|
|
|
|
quickRescanSubscription.current?.();
|
|
quickRescanSubscription.current = client.addSubscription(
|
|
[
|
|
'locations.quickRescan',
|
|
{
|
|
location_id: locationId,
|
|
sub_path: path ?? ''
|
|
}
|
|
],
|
|
{ onData() {} }
|
|
);
|
|
|
|
toast.success({
|
|
title: t('quick_rescan_started')
|
|
});
|
|
};
|
|
|
|
return rescan;
|
|
};
|