diff --git a/src/components/app-pagination/AppPaginationElement.ts b/src/components/app-pagination/AppPaginationElement.ts index a4360d4..1357fea 100644 --- a/src/components/app-pagination/AppPaginationElement.ts +++ b/src/components/app-pagination/AppPaginationElement.ts @@ -9,6 +9,9 @@ class AppPaginationElement extends BaseComponentElement { @attr rpp: number; @attr totalItems: number; @attr autoInit: string; + + private customRenderItems: () => TemplateResult; + private customRenderItem: (item: any) => TemplateResult; fetchFunc: Function = () => {}; constructor() { super(); @@ -36,6 +39,16 @@ class AppPaginationElement extends BaseComponentElement { } }; + setCustomRenderItems = (customRenderItems: () => TemplateResult) => { + this.customRenderItems = customRenderItems; + this.update(); + }; + + setCustomRenderItem = (customRenderItem: (item: any) => TemplateResult) => { + this.customRenderItem = customRenderItem; + this.update(); + }; + executeFetch = async (options?): Promise => { if (!options) { options = { @@ -75,19 +88,23 @@ class AppPaginationElement extends BaseComponentElement { render = (): TemplateResult => { const { rpp, totalItems, page, items } = this; - const renderItem = (item) => html` - ${item.description} - ${item.amount} - `; + const renderItem = this.customRenderItem + ? this.customRenderItem + : (item) => html` + ${item.description} + ${item.amount} + `; - const renderItems = () => { - if (items?.length > 0) { - return html` - ${items?.map((item) => renderItem(item))} - `; - } - return html``; - }; + const renderItems = this.customRenderItems + ? this.customRenderItems + : () => { + if (items?.length > 0) { + return html` + ${items?.map((item) => renderItem(item))} + `; + } + return html``; + }; const renderPagination = () => { if (totalItems > items?.length) { diff --git a/src/pages/history-page/HistoryPageElement.ts b/src/pages/history-page/HistoryPageElement.ts index 006449c..2430032 100644 --- a/src/pages/history-page/HistoryPageElement.ts +++ b/src/pages/history-page/HistoryPageElement.ts @@ -27,6 +27,12 @@ class HistoryPageElement extends BasePageElement { getTransactions = async (options): Promise => { try { + if (this?.routerService?.routerState?.data) { + const { walletId } = this?.routerService?.routerState?.data; + if (walletId) { + options["walletId"] = walletId; + } + } const response = await this.transactionsService.getAll(options); return response; } catch (err) { @@ -35,11 +41,20 @@ class HistoryPageElement extends BasePageElement { }; render = (): TemplateResult => { - return html` + const renderWallet = () => { + if (this.routerService?.routerState?.data?.walletId) { + return html`${this.routerService?.routerState?.data?.walletId}`; + } + return html``; + }; + return html`
+ ${renderWallet()} - `; +
`; }; } diff --git a/src/pages/index.ts b/src/pages/index.ts index 54953c9..bf0f0cf 100644 --- a/src/pages/index.ts +++ b/src/pages/index.ts @@ -4,3 +4,4 @@ export * from "./register-page/RegisterPageElement"; export * from "./login-page/LoginPageElement"; export * from "./not-found/NotFoundElement"; export * from "./history-page/HistoryPageElement"; +export * from "./wallet-list/WalletListElement"; diff --git a/src/pages/wallet-list/WalletListElement.ts b/src/pages/wallet-list/WalletListElement.ts new file mode 100644 index 0000000..c73965c --- /dev/null +++ b/src/pages/wallet-list/WalletListElement.ts @@ -0,0 +1,48 @@ +import { targets, controller, target } from "@github/catalyst"; +import { html, TemplateResult } from "@github/jtml"; +import { AuthService, WalletService } from "services/"; +import { AppPaginationElement, InputFieldElement } from "components/"; +import { BasePageElement } from "common/"; + +@controller +class WalletListElement extends BasePageElement { + @targets inputs: Array; + private walletService: WalletService; + @target pagination: AppPaginationElement; + authService: AuthService; + errorMessage: string; + constructor() { + super(); + } + elementConnected = (): void => { + this.walletService = new WalletService(this.appMain?.appService); + this.authService = new AuthService(this.appMain.appService); + this.update(); + this.pagination?.setCustomRenderItem(this.renderItem); + this.pagination?.setFetchFunc?.(this.getWallets, true)!; + }; + + getWallets = async (options): Promise => { + try { + const response = await this.walletService.getAll(options); + return response; + } catch (err) { + throw err; + } + }; + + renderItem = (item): TemplateResult => html` + ${item.name} + `; + + render = (): TemplateResult => { + return html` +
Wallets
+ + `; + }; +} + +export type { WalletListElement };