mirror of
https://github.com/spacedriveapp/spacedrive
synced 2024-07-04 13:23:28 +00:00
Memoise useExplorerPreference props (#2363)
* memoise useExplorerPreference props * this is even faster --------- Co-authored-by: Utku Bakir <74243531+utkubakir@users.noreply.github.com>
This commit is contained in:
parent
e4dd2b73ec
commit
1a438c630e
|
@ -1,5 +1,5 @@
|
|||
import { ArrowClockwise, Info } from '@phosphor-icons/react';
|
||||
import { useEffect, useMemo } from 'react';
|
||||
import { useCallback, useEffect, useMemo } from 'react';
|
||||
import { stringify } from 'uuid';
|
||||
import {
|
||||
arraysEqual,
|
||||
|
@ -226,11 +226,17 @@ function getLastSectionOfPath(path: string): string | undefined {
|
|||
function useLocationExplorerSettings(location: Location) {
|
||||
const preferences = useExplorerPreferences({
|
||||
data: location,
|
||||
createDefaultSettings: () =>
|
||||
createDefaultExplorerSettings<FilePathOrder>({
|
||||
order: { field: 'name', value: 'Asc' }
|
||||
}),
|
||||
getSettings: (prefs) => prefs.location?.[stringify(location.pub_id)]?.explorer,
|
||||
createDefaultSettings: useCallback(
|
||||
() =>
|
||||
createDefaultExplorerSettings<FilePathOrder>({
|
||||
order: { field: 'name', value: 'Asc' }
|
||||
}),
|
||||
[]
|
||||
),
|
||||
getSettings: useCallback(
|
||||
(prefs) => prefs.location?.[stringify(location.pub_id)]?.explorer,
|
||||
[location.pub_id]
|
||||
),
|
||||
writeSettings: (settings) => ({
|
||||
location: { [stringify(location.pub_id)]: { explorer: settings } }
|
||||
})
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { useMemo } from 'react';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
import { ObjectOrder, Tag, useCache, useLibraryQuery, useNodes } from '@sd/client';
|
||||
import { LocationIdParamsSchema } from '~/app/route-schemas';
|
||||
import { Icon } from '~/components';
|
||||
|
@ -91,8 +91,14 @@ export function Component() {
|
|||
function useTagExplorerSettings(tag: Tag) {
|
||||
const preferences = useExplorerPreferences({
|
||||
data: tag,
|
||||
createDefaultSettings: () => createDefaultExplorerSettings<ObjectOrder>({ order: null }),
|
||||
getSettings: (prefs) => prefs.tag?.[stringify(tag.pub_id)]?.explorer,
|
||||
createDefaultSettings: useCallback(
|
||||
() => createDefaultExplorerSettings<ObjectOrder>({ order: null }),
|
||||
[]
|
||||
),
|
||||
getSettings: useCallback(
|
||||
(prefs) => prefs.tag?.[stringify(tag.pub_id)]?.explorer,
|
||||
[tag.pub_id]
|
||||
),
|
||||
writeSettings: (settings) => ({
|
||||
tag: { [stringify(tag.pub_id)]: { explorer: settings } }
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue