[ENG-989] Switch explorer views bug (#1433)

* Fix explorer switching bug

* tweaks
This commit is contained in:
ameer2468
2023-10-04 23:31:12 +03:00
committed by GitHub
parent f4cf2513c6
commit 1250f46596
2 changed files with 13 additions and 3 deletions

View File

@@ -81,20 +81,29 @@ export type UseExplorer<TOrder extends Ordering> = ReturnType<typeof useExplorer
export function useExplorerSettings<TOrder extends Ordering>({
settings,
onSettingsChanged,
orderingKeys
orderingKeys,
location
}: {
settings: ReturnType<typeof createDefaultExplorerSettings<TOrder>>;
onSettingsChanged?: (settings: ExplorerSettings<TOrder>) => any;
orderingKeys?: z.ZodUnion<
[z.ZodLiteral<OrderingKeys<TOrder>>, ...z.ZodLiteral<OrderingKeys<TOrder>>[]]
>;
location?: Location | null;
}) {
const [store] = useState(() => proxy(settings));
useEffect(() => {
Object.assign(store, settings);
Object.assign(store, {
...settings,
layoutMode: store.layoutMode
});
}, [store, settings]);
useEffect(() => {
store.layoutMode = settings.layoutMode;
}, [location])
useEffect(
() =>
subscribe(store, () => {

View File

@@ -74,7 +74,8 @@ export const Component = () => {
const explorerSettings = useExplorerSettings({
settings,
onSettingsChanged,
orderingKeys: filePathOrderingKeysSchema
orderingKeys: filePathOrderingKeysSchema,
location: location.data
});
const { items, count, loadMore, query } = useItems({ locationId, settings: explorerSettings });