mirror of
https://github.com/Qortal/q-shop.git
synced 2025-01-30 06:42:21 +00:00
Merge pull request #3 from QuickMythril/remove-invalid
Filter invalid results from store list
This commit is contained in:
commit
0738e27367
@ -1,6 +1,7 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
import { addToHashMapStores } from "../state/features/storeSlice";
|
import { addToHashMapStores } from "../state/features/storeSlice";
|
||||||
|
import { removeFromHashMapStores } from "../state/features/storeSlice";
|
||||||
|
|
||||||
import { RootState } from "../state/store";
|
import { RootState } from "../state/store";
|
||||||
import { fetchAndEvaluateProducts } from "../utils/fetchPosts";
|
import { fetchAndEvaluateProducts } from "../utils/fetchPosts";
|
||||||
@ -22,9 +23,12 @@ export const useFetchStores = () => {
|
|||||||
storeId,
|
storeId,
|
||||||
content
|
content
|
||||||
});
|
});
|
||||||
|
if (res?.isValid) {
|
||||||
dispatch(addToHashMapStores(res));
|
dispatch(addToHashMapStores(res));
|
||||||
return res;
|
return res;
|
||||||
|
} else {
|
||||||
|
dispatch(removeFromHashMapStores(storeId));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const checkAndUpdateResource = React.useCallback(
|
const checkAndUpdateResource = React.useCallback(
|
||||||
|
@ -115,12 +115,10 @@ export const StoreList = () => {
|
|||||||
|
|
||||||
// Memoize the filtered stores to prevent rerenders
|
// Memoize the filtered stores to prevent rerenders
|
||||||
const filteredStores = useMemo(() => {
|
const filteredStores = useMemo(() => {
|
||||||
if (filterUserStores) {
|
let filtered = filterUserStores ? myStores : stores;
|
||||||
return myStores;
|
filtered = filtered.filter((store: Store) => hashMapStores[store.id]?.isValid);
|
||||||
} else {
|
return filtered;
|
||||||
return stores;
|
}, [filterUserStores, stores, myStores, user?.name, hashMapStores]);
|
||||||
}
|
|
||||||
}, [filterUserStores, stores, myStores, user?.name]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
@ -150,6 +150,10 @@ export const storeSlice = createSlice({
|
|||||||
const store = action.payload;
|
const store = action.payload;
|
||||||
state.hashMapStores[store?.id] = store;
|
state.hashMapStores[store?.id] = store;
|
||||||
},
|
},
|
||||||
|
removeFromHashMapStores: (state, action) => {
|
||||||
|
const storeId = action.payload;
|
||||||
|
delete state.hashMapStores[storeId];
|
||||||
|
},
|
||||||
addToHashMapStoreReviews: (state, action) => {
|
addToHashMapStoreReviews: (state, action) => {
|
||||||
const review = action.payload;
|
const review = action.payload;
|
||||||
state.hashMapStoreReviews[review.id] = review;
|
state.hashMapStoreReviews[review.id] = review;
|
||||||
@ -267,6 +271,7 @@ export const {
|
|||||||
upsertPostsBeginning,
|
upsertPostsBeginning,
|
||||||
upsertFilteredPosts,
|
upsertFilteredPosts,
|
||||||
addToHashMapStores,
|
addToHashMapStores,
|
||||||
|
removeFromHashMapStores,
|
||||||
setStoreId,
|
setStoreId,
|
||||||
setStoreOwner,
|
setStoreOwner,
|
||||||
upsertStores,
|
upsertStores,
|
||||||
|
Loading…
Reference in New Issue
Block a user