3
0
mirror of https://github.com/Qortal/q-shop.git synced 2025-01-28 22:02:21 +00:00

Merge pull request #3 from QuickMythril/remove-invalid

Filter invalid results from store list
This commit is contained in:
Qortal Dev 2024-04-17 08:05:18 -06:00 committed by GitHub
commit 0738e27367
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 9 deletions

View File

@ -1,6 +1,7 @@
import React from "react";
import { useDispatch, useSelector } from "react-redux";
import { addToHashMapStores } from "../state/features/storeSlice";
import { removeFromHashMapStores } from "../state/features/storeSlice";
import { RootState } from "../state/store";
import { fetchAndEvaluateProducts } from "../utils/fetchPosts";
@ -22,9 +23,12 @@ export const useFetchStores = () => {
storeId,
content
});
dispatch(addToHashMapStores(res));
return res;
if (res?.isValid) {
dispatch(addToHashMapStores(res));
return res;
} else {
dispatch(removeFromHashMapStores(storeId));
}
};
const checkAndUpdateResource = React.useCallback(

View File

@ -115,12 +115,10 @@ export const StoreList = () => {
// Memoize the filtered stores to prevent rerenders
const filteredStores = useMemo(() => {
if (filterUserStores) {
return myStores;
} else {
return stores;
}
}, [filterUserStores, stores, myStores, user?.name]);
let filtered = filterUserStores ? myStores : stores;
filtered = filtered.filter((store: Store) => hashMapStores[store.id]?.isValid);
return filtered;
}, [filterUserStores, stores, myStores, user?.name, hashMapStores]);
return (
<>

View File

@ -150,6 +150,10 @@ export const storeSlice = createSlice({
const store = action.payload;
state.hashMapStores[store?.id] = store;
},
removeFromHashMapStores: (state, action) => {
const storeId = action.payload;
delete state.hashMapStores[storeId];
},
addToHashMapStoreReviews: (state, action) => {
const review = action.payload;
state.hashMapStoreReviews[review.id] = review;
@ -267,6 +271,7 @@ export const {
upsertPostsBeginning,
upsertFilteredPosts,
addToHashMapStores,
removeFromHashMapStores,
setStoreId,
setStoreOwner,
upsertStores,