mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 12:24:38 +03:00
Fix interface state storage (#1064)
This commit is contained in:
@@ -22,10 +22,7 @@ import {
|
|||||||
FindImagesQueryResult,
|
FindImagesQueryResult,
|
||||||
SlimImageDataFragment,
|
SlimImageDataFragment,
|
||||||
} from "src/core/generated-graphql";
|
} from "src/core/generated-graphql";
|
||||||
import {
|
import { useInterfaceLocalForage } from "src/hooks/LocalForage";
|
||||||
useInterfaceLocalForage,
|
|
||||||
IInterfaceConfig,
|
|
||||||
} from "src/hooks/LocalForage";
|
|
||||||
import { LoadingIndicator } from "src/components/Shared";
|
import { LoadingIndicator } from "src/components/Shared";
|
||||||
import { ListFilter } from "src/components/List/ListFilter";
|
import { ListFilter } from "src/components/List/ListFilter";
|
||||||
import { Pagination, PaginationIndex } from "src/components/List/Pagination";
|
import { Pagination, PaginationIndex } from "src/components/List/Pagination";
|
||||||
@@ -431,16 +428,12 @@ const useList = <QueryResult extends IQueryResult, QueryData extends IDataItem>(
|
|||||||
|
|
||||||
const updateInterfaceConfig = useCallback(
|
const updateInterfaceConfig = useCallback(
|
||||||
(updatedFilter: ListFilterModel) => {
|
(updatedFilter: ListFilterModel) => {
|
||||||
setInterfaceState((config) => {
|
setInterfaceState({
|
||||||
const data = { ...config } as IInterfaceConfig;
|
[options.filterMode]: {
|
||||||
data.queries = {
|
filter: updatedFilter.makeQueryParameters(),
|
||||||
[options.filterMode]: {
|
itemsPerPage: updatedFilter.itemsPerPage,
|
||||||
filter: updatedFilter.makeQueryParameters(),
|
currentPage: updatedFilter.currentPage,
|
||||||
itemsPerPage: updatedFilter.itemsPerPage,
|
},
|
||||||
currentPage: updatedFilter.currentPage,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
return data;
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
[options.filterMode, setInterfaceState]
|
[options.filterMode, setInterfaceState]
|
||||||
@@ -458,7 +451,7 @@ const useList = <QueryResult extends IQueryResult, QueryData extends IDataItem>(
|
|||||||
|
|
||||||
if (!options.persistState) return;
|
if (!options.persistState) return;
|
||||||
|
|
||||||
const storedQuery = interfaceState.data?.queries?.[options.filterMode];
|
const storedQuery = interfaceState.data?.[options.filterMode];
|
||||||
if (!storedQuery) return;
|
if (!storedQuery) return;
|
||||||
|
|
||||||
const queryFilter = queryString.parse(history.location.search);
|
const queryFilter = queryString.parse(history.location.search);
|
||||||
|
|||||||
@@ -2,17 +2,13 @@ import localForage from "localforage";
|
|||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import React, { Dispatch, SetStateAction, useEffect } from "react";
|
import React, { Dispatch, SetStateAction, useEffect } from "react";
|
||||||
|
|
||||||
interface IInterfaceWallConfig {}
|
|
||||||
interface IInterfaceQueryConfig {
|
interface IInterfaceQueryConfig {
|
||||||
filter: string;
|
filter: string;
|
||||||
itemsPerPage: number;
|
itemsPerPage: number;
|
||||||
currentPage: number;
|
currentPage: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IInterfaceConfig {
|
type IInterfaceConfig = Record<string, IInterfaceQueryConfig>;
|
||||||
wall?: IInterfaceWallConfig;
|
|
||||||
queries?: Record<string, IInterfaceQueryConfig>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IChangelogConfig {
|
export interface IChangelogConfig {
|
||||||
versions: Record<string, boolean>;
|
versions: Record<string, boolean>;
|
||||||
@@ -66,10 +62,10 @@ export function useLocalForage<T>(
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!_.isEqual(Cache[key], data)) {
|
if (!_.isEqual(Cache[key], data)) {
|
||||||
Cache[key] = _.merge({
|
Cache[key] = {
|
||||||
...Cache[key],
|
...Cache[key],
|
||||||
...data,
|
...data,
|
||||||
});
|
};
|
||||||
localForage.setItem(key, JSON.stringify(Cache[key]));
|
localForage.setItem(key, JSON.stringify(Cache[key]));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user