Fix interface state storage (#1064)

This commit is contained in:
InfiniteTF 2021-01-15 05:15:59 +01:00 committed by GitHub
parent defb23aaa2
commit 7bae990c67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 22 deletions

View File

@ -22,10 +22,7 @@ import {
FindImagesQueryResult,
SlimImageDataFragment,
} from "src/core/generated-graphql";
import {
useInterfaceLocalForage,
IInterfaceConfig,
} from "src/hooks/LocalForage";
import { useInterfaceLocalForage } from "src/hooks/LocalForage";
import { LoadingIndicator } from "src/components/Shared";
import { ListFilter } from "src/components/List/ListFilter";
import { Pagination, PaginationIndex } from "src/components/List/Pagination";
@ -431,16 +428,12 @@ const useList = <QueryResult extends IQueryResult, QueryData extends IDataItem>(
const updateInterfaceConfig = useCallback(
(updatedFilter: ListFilterModel) => {
setInterfaceState((config) => {
const data = { ...config } as IInterfaceConfig;
data.queries = {
[options.filterMode]: {
filter: updatedFilter.makeQueryParameters(),
itemsPerPage: updatedFilter.itemsPerPage,
currentPage: updatedFilter.currentPage,
},
};
return data;
setInterfaceState({
[options.filterMode]: {
filter: updatedFilter.makeQueryParameters(),
itemsPerPage: updatedFilter.itemsPerPage,
currentPage: updatedFilter.currentPage,
},
});
},
[options.filterMode, setInterfaceState]
@ -458,7 +451,7 @@ const useList = <QueryResult extends IQueryResult, QueryData extends IDataItem>(
if (!options.persistState) return;
const storedQuery = interfaceState.data?.queries?.[options.filterMode];
const storedQuery = interfaceState.data?.[options.filterMode];
if (!storedQuery) return;
const queryFilter = queryString.parse(history.location.search);

View File

@ -2,17 +2,13 @@ import localForage from "localforage";
import _ from "lodash";
import React, { Dispatch, SetStateAction, useEffect } from "react";
interface IInterfaceWallConfig {}
interface IInterfaceQueryConfig {
filter: string;
itemsPerPage: number;
currentPage: number;
}
export interface IInterfaceConfig {
wall?: IInterfaceWallConfig;
queries?: Record<string, IInterfaceQueryConfig>;
}
type IInterfaceConfig = Record<string, IInterfaceQueryConfig>;
export interface IChangelogConfig {
versions: Record<string, boolean>;
@ -66,10 +62,10 @@ export function useLocalForage<T>(
useEffect(() => {
if (!_.isEqual(Cache[key], data)) {
Cache[key] = _.merge({
Cache[key] = {
...Cache[key],
...data,
});
};
localForage.setItem(key, JSON.stringify(Cache[key]));
}
});