Browse Source

Merge pull request #3 from QuickMythril/remove-invalid

Filter invalid results from store list
main
Qortal Dev 5 months ago committed by GitHub
parent
commit
0738e27367
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 6
      src/hooks/useFetchStores.tsx
  2. 10
      src/pages/StoreList/StoreList.tsx
  3. 5
      src/state/features/storeSlice.ts

6
src/hooks/useFetchStores.tsx

@ -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
});
if (res?.isValid) {
dispatch(addToHashMapStores(res));
return res;
} else {
dispatch(removeFromHashMapStores(storeId));
}
};
const checkAndUpdateResource = React.useCallback(

10
src/pages/StoreList/StoreList.tsx

@ -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 (
<>

5
src/state/features/storeSlice.ts

@ -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…
Cancel
Save