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:
commit
0738e27367
@ -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(
|
||||
|
@ -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 (
|
||||
<>
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user