JezK
Edit File: sc-dashboard-downloads-list.entry.js.map
{"file":"sc-dashboard-downloads-list.entry.js","mappings":";;;;;;;AAAA,MAAM,2BAA2B,GAAG,sDAAsD,CAAC;AAC3F,uCAAe,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8ECwDT,UAAE;;;;;;;;;;;;;;;;8EAeF,UAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ifA+Ca,UAAE;;;;;;;;","names":[],"sources":["src/components/controllers/dashboard/dashboard-downloads-list/sc-dashboard-downloads-list.scss?tag=sc-dashboard-downloads-list&encapsulation=shadow","src/components/controllers/dashboard/dashboard-downloads-list/sc-dashboard-downloads-list.tsx"],"sourcesContent":[":host {\n display: block;\n}\n\n.download__details {\n opacity: 0.75;\n}\n","import { Component, Element, h, Prop, State } from '@stencil/core';\nimport { __, _n } from '@wordpress/i18n';\nimport { addQueryArgs } from '@wordpress/url';\n\nimport apiFetch from '../../../../functions/fetch';\nimport { onFirstVisible } from '../../../../functions/lazy';\nimport { Purchase } from '../../../../types';\n\n@Component({\n tag: 'sc-dashboard-downloads-list',\n styleUrl: 'sc-dashboard-downloads-list.scss',\n shadow: true,\n})\nexport class ScDownloadsList {\n @Element() el: HTMLScDownloadsListElement;\n /** Customer id to fetch subscriptions */\n @Prop({ mutable: true }) query: any = {\n page: 1,\n per_page: 10,\n };\n @Prop() allLink: string;\n @Prop() heading: string;\n @Prop() isCustomer: boolean;\n @Prop() requestNonce: string;\n\n @State() purchases: Array<Purchase> = [];\n\n /** Loading state */\n @State() loading: boolean;\n @State() busy: boolean;\n\n /** Error message */\n @State() error: string;\n\n @State() pagination: {\n total: number;\n total_pages: number;\n } = {\n total: 0,\n total_pages: 0,\n };\n\n componentWillLoad() {\n onFirstVisible(this.el, () => {\n this.initialFetch();\n });\n }\n\n async initialFetch() {\n if (!this.isCustomer) {\n return;\n }\n try {\n this.loading = true;\n await this.getItems();\n } catch (e) {\n console.error(this.error);\n this.error = e?.message || __('Something went wrong', 'surecart');\n } finally {\n this.loading = false;\n }\n }\n\n async fetchItems() {\n if (!this.isCustomer) {\n return;\n }\n try {\n this.busy = true;\n await this.getItems();\n } catch (e) {\n console.error(this.error);\n this.error = e?.message || __('Something went wrong', 'surecart');\n } finally {\n this.busy = false;\n }\n }\n\n /** Get all subscriptions */\n async getItems() {\n const response = (await await apiFetch({\n path: addQueryArgs(`surecart/v1/purchases/`, {\n expand: ['product', 'product.downloads', 'download.media', 'variant', 'variant.downloads'],\n downloadable: true,\n revoked: false,\n ...this.query,\n }),\n parse: false,\n })) as Response;\n this.pagination = {\n total: parseInt(response.headers.get('X-WP-Total')),\n total_pages: parseInt(response.headers.get('X-WP-TotalPages')),\n };\n this.purchases = (await response.json()) as Purchase[];\n return this.purchases;\n }\n\n nextPage() {\n this.query.page = this.query.page + 1;\n this.fetchItems();\n }\n\n prevPage() {\n this.query.page = this.query.page - 1;\n this.fetchItems();\n }\n\n render() {\n return (\n <sc-purchase-downloads-list\n heading={this.heading}\n allLink={this.allLink && this.pagination.total_pages > 1 ? this.allLink : ''}\n loading={this.loading}\n busy={this.busy}\n requestNonce={this.requestNonce}\n error={this.error}\n purchases={this.purchases}\n >\n <span slot=\"heading\">\n <slot name=\"heading\">{this.heading || __('Downloads', 'surecart')}</slot>\n </span>\n\n <sc-pagination\n slot=\"after\"\n page={this.query.page}\n perPage={this.query.per_page}\n total={this.pagination.total}\n totalPages={this.pagination.total_pages}\n totalShowing={this?.purchases?.length}\n onScNextPage={() => this.nextPage()}\n onScPrevPage={() => this.prevPage()}\n ></sc-pagination>\n </sc-purchase-downloads-list>\n );\n }\n}\n"],"version":3}