Skip to content

Commit

Permalink
fix: hide item
Browse files Browse the repository at this point in the history
  • Loading branch information
AlefrankM committed Jan 30, 2023
1 parent 60802be commit c667abf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 56 deletions.
6 changes: 3 additions & 3 deletions src/components/item-details/hide-item-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export const HideItemButton = () => {
const dispatch = useAppDispatch();
const [isModalOpen, setIsModalOpen] = useState(false);
const {
selectedItem: { itemId, status, isHidden },
isLoading,
selectedItem: { itemId, isHidden },
isHiding,
} = useAppSelector((state) => state.marketplace);

const handleModal = () => {
Expand Down Expand Up @@ -55,7 +55,7 @@ export const HideItemButton = () => {
<div className="placebid-form-box">
<div className="bit-continue-button">
<ActionLoaderComponent
isLoading={isLoading}
isLoading={isHiding}
onClick={onSubmit}
buttonSize="medium"
type="submit"
Expand Down
50 changes: 2 additions & 48 deletions src/features/marketplace/store/marketplace.slice.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { AnyAction } from '@reduxjs/toolkit';
import { History } from '../../../types/history';
import { ICollection } from '../../../types/ICollection';
import { Item } from '../../../types/item';
import { FilterType } from '../../../types/item-filter-types';
import { findFilteredItems, findPagedItems, getNewest, listItem } from './marketplace.actions';
import {
initialMarketplaceState,
marketplaceReducer,
MarketplaceState,
resetFilters,
Expand All @@ -15,52 +14,7 @@ describe('Marketplace slice', () => {
let initialState: MarketplaceState;

beforeEach(() => {
initialState = {
isUploadingImage: false,
items: [],
itemsCount: 0,
likedItems: [],
collections: [],
collectionsCount: 0,
collectionsWithoutItems: [],
selectedItem: {} as Item,
newestItems: [],
filters: {
likesDirection: '',
search: '',
priceRange: {
from: '',
to: '',
},
cheapest: '',
mostExpensive: '',
page: 1,
limit: 3,
},
history: [] as History[],
historyCount: 0,
newestCollections: [] as ICollection[],
selectedCollection: {} as ICollection,
isLoadingCollections: false,
collectionsFilters: {
search: '',
popularityOrder: '',
creationOrder: '',
mintType: '',
page: 1,
limit: 3,
},
isLoading: false,
isDelisting: false,
isListing: false,
isPagingLoading: false,
isLoadingHistory: false,
isLoadingNewest: false,
isLoadingCollection: false,
isModalOpen: false,
isCompleted: false,
isOpenPreviewProductModal: false,
};
initialState = initialMarketplaceState;
});

describe('When newestItems function is called', () => {
Expand Down
15 changes: 10 additions & 5 deletions src/features/marketplace/store/marketplace.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ export type MarketplaceState = {
isListing: boolean;
isModalOpen: boolean;
isCompleted: boolean;
isHiding: boolean;
isBuying: boolean;
isOpenPreviewProductModal: boolean;
};

Expand All @@ -79,7 +81,7 @@ export const initialFormState = {
properties: [],
};

const initialState: MarketplaceState = {
export const initialMarketplaceState: MarketplaceState = {
items: [],
itemsCount: 0,
likedItems: [],
Expand Down Expand Up @@ -124,19 +126,21 @@ const initialState: MarketplaceState = {
isModalOpen: false,
isCompleted: false,
isOpenPreviewProductModal: false,
isHiding: false,
isBuying: false,
};

const marketplaceSlice = createSlice({
name: 'marketplace',
initialState,
initialState: initialMarketplaceState,
reducers: {
setFilters: (state, { payload }) => {
state.filters = payload;
},
resetFilters: (state) => {
state.filters = initialState.filters;
state.items = initialState.items;
state.history = initialState.history;
state.filters = initialMarketplaceState.filters;
state.items = initialMarketplaceState.items;
state.history = initialMarketplaceState.history;
},
setSelectedItem: (state, { payload }) => {
state.selectedItem = payload;
Expand Down Expand Up @@ -335,6 +339,7 @@ const marketplaceSlice = createSlice({
builder.addCase(hideItem.fulfilled, (state, { payload }) => {
const index = state.items.findIndex((i) => i.itemId === payload.itemId);
state.items[index] = payload;
state.isHiding = false;

if (state.selectedItem.itemId === payload.itemId) state.selectedItem = payload;
});
Expand Down

0 comments on commit c667abf

Please sign in to comment.