-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
482 additions
and
246 deletions.
There are no files selected for viewing
431 changes: 218 additions & 213 deletions
431
client/src/app/components/modals/market/market.component.html
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { IMarketItemExpanded, IPagination } from '@interfaces'; | ||
|
||
export interface IMarketStore { | ||
version: number; | ||
marketData: IPagination<IMarketItemExpanded>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { IMarketItemExpanded, IPagination } from '@interfaces'; | ||
|
||
export class SetMarketItems { | ||
static type = '[Market] Set Items'; | ||
constructor(public marketData: IPagination<IMarketItemExpanded>) {} | ||
} | ||
|
||
export class RemoveMarketItem { | ||
static type = 'RemoveMarketItem'; | ||
constructor(public listingId: string) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { IAttachment } from '../../interfaces'; | ||
import { RemoveMarketItem, SetMarketItems } from './market.actions'; | ||
import { removeMarketItem, setMarketItems } from './market.functions'; | ||
|
||
export const attachments: IAttachment[] = [ | ||
{ action: SetMarketItems, handler: setMarketItems }, | ||
{ action: RemoveMarketItem, handler: removeMarketItem }, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { IMarketItemExpanded, IMarketStore } from '@interfaces'; | ||
import { StateContext } from '@ngxs/store'; | ||
import { patch, removeItem } from '@ngxs/store/operators'; | ||
import { RemoveMarketItem, SetMarketItems } from './market.actions'; | ||
|
||
export const defaultStore: () => IMarketStore = () => ({ | ||
version: 0, | ||
marketData: { | ||
lastPage: 0, | ||
page: 0, | ||
results: [], | ||
total: 0, | ||
limit: 25, | ||
}, | ||
}); | ||
|
||
export function setMarketItems( | ||
ctx: StateContext<IMarketStore>, | ||
{ marketData }: SetMarketItems, | ||
) { | ||
ctx.setState( | ||
patch({ | ||
marketData, | ||
}), | ||
); | ||
} | ||
|
||
export function removeMarketItem( | ||
ctx: StateContext<IMarketStore>, | ||
{ listingId }: RemoveMarketItem, | ||
) { | ||
ctx.setState( | ||
patch({ | ||
marketData: patch({ | ||
results: removeItem<IMarketItemExpanded>( | ||
(item) => item.id === listingId, | ||
), | ||
}), | ||
}), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { IMarketStore } from '@interfaces'; | ||
|
||
export const marketStoreMigrations = [ | ||
{ | ||
version: 0, | ||
migrate: (state: IMarketStore) => ({ | ||
...state, | ||
version: 1, | ||
}), | ||
}, | ||
].map((x) => ({ ...x, key: 'market' })); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Selector, State } from '@ngxs/store'; | ||
import { attachAction } from '@seiyria/ngxs-attach-action'; | ||
|
||
import { IMarketStore } from '@interfaces'; | ||
import { defaultStore } from './market.functions'; | ||
|
||
import { getStateHelpers } from '@helpers/store-context'; | ||
import { attachments } from './market.attachments'; | ||
|
||
@State<IMarketStore>({ | ||
name: 'market', | ||
defaults: defaultStore(), | ||
}) | ||
@Injectable() | ||
export class MarketStore { | ||
constructor() { | ||
const helpers = getStateHelpers(); | ||
attachments.forEach(({ action, handler }) => { | ||
attachAction(MarketStore, action, (ctx, action) => { | ||
handler(ctx, action, helpers); | ||
}); | ||
}); | ||
} | ||
|
||
@Selector() | ||
static marketData(state: IMarketStore) { | ||
return state.marketData; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.