@salla.sa/twilight-components 2.13.47 → 2.13.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/app-globals-0efa4587.js.map +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/salla-add-product-button_47.cjs.entry.js +2 -1
- package/dist/cjs/salla-add-product-button_47.cjs.entry.js.map +1 -1
- package/dist/cjs/twilight.cjs.js +1 -1
- package/dist/collection/components/salla-comments/salla-comments.js +20 -1
- package/dist/collection/components/salla-comments/salla-comments.js.map +1 -1
- package/dist/components/index.js.map +1 -1
- package/dist/components/salla-comments.js +3 -1
- package/dist/components/salla-comments.js.map +1 -1
- package/dist/components/salla-quick-buy2.js.map +1 -1
- package/dist/esm/app-globals-32c0b133.js.map +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/esm/salla-add-product-button_47.entry.js +2 -1
- package/dist/esm/salla-add-product-button_47.entry.js.map +1 -1
- package/dist/esm/twilight.js +1 -1
- package/dist/esm-es5/app-globals-32c0b133.js.map +1 -1
- package/dist/esm-es5/loader.js +1 -1
- package/dist/esm-es5/loader.js.map +1 -1
- package/dist/esm-es5/salla-add-product-button_47.entry.js +1 -1
- package/dist/esm-es5/salla-add-product-button_47.entry.js.map +1 -1
- package/dist/esm-es5/twilight.js +1 -1
- package/dist/esm-es5/twilight.js.map +1 -1
- package/dist/twilight/{p-66f25bdd.entry.js → p-00f68eb0.entry.js} +2 -2
- package/dist/twilight/p-00f68eb0.entry.js.map +1 -0
- package/dist/twilight/p-44a3fce3.system.js.map +1 -1
- package/dist/twilight/{p-af130e8a.system.entry.js → p-8a76175f.system.entry.js} +2 -2
- package/dist/twilight/p-8a76175f.system.entry.js.map +1 -0
- package/dist/twilight/p-93a162ca.js.map +1 -1
- package/dist/twilight/p-b9c7fc02.system.js +1 -1
- package/dist/twilight/p-b9c7fc02.system.js.map +1 -1
- package/dist/twilight/twilight.esm.js +1 -1
- package/dist/twilight/twilight.esm.js.map +1 -1
- package/dist/types/components/salla-comments/salla-comments.d.ts +4 -0
- package/dist/types/components.d.ts +8 -0
- package/package.json +5 -5
- package/dist/twilight/p-66f25bdd.entry.js.map +0 -1
- package/dist/twilight/p-af130e8a.system.entry.js.map +0 -1
|
@@ -27,6 +27,7 @@ const SallaComments$1 = /*@__PURE__*/ proxyCustomElement(class SallaComments ext
|
|
|
27
27
|
this.blockTitle = undefined;
|
|
28
28
|
this.hideTitle = undefined;
|
|
29
29
|
this.type = CommentType.PAGE;
|
|
30
|
+
this.showFormAvatar = false;
|
|
30
31
|
this.comments = undefined;
|
|
31
32
|
this.pagination = undefined;
|
|
32
33
|
this.total = undefined;
|
|
@@ -162,7 +163,7 @@ const SallaComments$1 = /*@__PURE__*/ proxyCustomElement(class SallaComments ext
|
|
|
162
163
|
render() {
|
|
163
164
|
// We should show a different placeholder for pages and products (WIP)
|
|
164
165
|
if (this.showPlaceholder) {
|
|
165
|
-
return (h("div", null, !!this.total && !this.hideTitle ? h("h2", { class: "s-comments-title" }, this.blockTitle ? this.blockTitle : this.comment_title) : '', !this.hideForm && h("salla-comment-form", { type: this.type, "item-id": this.itemId }), h("div", { class: "no-content-placeholder--comments" }, h("i", { class: "sicon-chat-bubbles text-5xl block mb-5 text-gray-400" }), h("p", { class: "text-sm" }, this.noComments))));
|
|
166
|
+
return (h("div", null, !!this.total && !this.hideTitle ? h("h2", { class: "s-comments-title" }, this.blockTitle ? this.blockTitle : this.comment_title) : '', !this.hideForm && h("salla-comment-form", { "show-avatar": this.showFormAvatar, type: this.type, "item-id": this.itemId }), h("div", { class: "no-content-placeholder--comments" }, h("i", { class: "sicon-chat-bubbles text-5xl block mb-5 text-gray-400" }), h("p", { class: "text-sm" }, this.noComments))));
|
|
166
167
|
}
|
|
167
168
|
return (h("div", { class: `s-comments s-comments-${this.type}` }, h("div", { class: `${this.type == CommentType.PAGE ? "s-comments-page-container" : "s-comments-container"}` }, !!this.total && !this.hideTitle ? h("h2", { class: "s-comments-title" }, this.blockTitle ? this.blockTitle : this.comment_title) : '', !this.hideForm && h("salla-comment-form", { type: this.type, "item-id": this.itemId }), !!this.total && h("h2", { class: "s-comments-count-label", innerHTML: this.pluralize(this.comment_name, this.total) }), h("div", { ref: wrapper => this.wrapper = wrapper }), this.nextPage && (h("div", { class: "s-infinite-scroll-wrapper", ref: status => this.status = status }, h("button", { onClick: () => this.loadMore(), class: "s-infinite-scroll-btn s-button-btn s-button-primary" }, h("span", { class: "s-button-text s-infinite-scroll-btn-text" }, this.loadMoreText ? this.loadMoreText : salla.lang.get('common.elements.load_more')), h("span", { class: "s-button-loader s-button-loader-center s-infinite-scroll-btn-loader", ref: btnLoader => this.btnLoader = btnLoader, style: { "display": "none" } })))))));
|
|
168
169
|
}
|
|
@@ -178,6 +179,7 @@ const SallaComments$1 = /*@__PURE__*/ proxyCustomElement(class SallaComments ext
|
|
|
178
179
|
"blockTitle": [1, "block-title"],
|
|
179
180
|
"hideTitle": [4, "hide-title"],
|
|
180
181
|
"type": [1],
|
|
182
|
+
"showFormAvatar": [4, "show-form-avatar"],
|
|
181
183
|
"comments": [32],
|
|
182
184
|
"pagination": [32],
|
|
183
185
|
"total": [32],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"file":"salla-comments.js","mappings":";;;;;;;;;;;AAAA,IAAY,WAGX;AAHD,WAAY,WAAW;EACnB,4BAAY,CAAA;EACZ,kCAAmB,CAAA;AACvB,CAAC,EAHW,WAAW,KAAX,WAAW;;ACAvB,MAAM,gBAAgB,GAAG,sBAAsB;;MCQlCA,eAAa;EAExB;;;;;;;;gBAoCuD,WAAW,CAAC,IAAI;;;;;;sBAgBzC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,6BAA6B,CAAC;yBAClD,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,uBAAuB,CAAC;wBACxC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,yBAAyB,CAAC;;IArD/D,KAAK,CAAC,IAAI,CA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AM,GAAG,EAAE,EACjI,CAAC,IAAI,CAAC,QAAQ,IAAI,0BAAoB,IAAI,EAAE,IAAI,CAAC,IAAI,aAAW,IAAI,CAAC,MAAM,GAAuB,EAElG,CAAC,CAAC,IAAI,CAAC,KAAK,IAAI,UAAI,KAAK,EAAC,wBAAwB,EAAC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,KAAK,CAAC,GAAO,EACnH,WAAK,GAAG,EAAE,OAAO,IAAI,IAAI,CAAC,OAAO,GAAG,OAAO,GAAQ,EAGlD,IAAI,CAAC,QAAQ,KACZ,WAAK,KAAK,EAAC,2BAA2B,EAAC,GAAG,EAAE,MAAM,IAAI,IAAI,CAAC,MAAM,GAAG,MAAM,IACxE,cAAQ,OAAO,EAAE,MAAM,IAAI,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAC,qDAAqD,IACjG,YAAM,KAAK,EAAC,0CAA0C,IAAE,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAQ,EACnJ,YAAM,KAAK,EAAC,qEAAqE,EAAC,GAAG,EAAE,SAAS,IAAI,IAAI,CAAC,SAAS,GAAG,SAAS,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,GAAS,CAC9J,CACL,CACP,CACG,CACF,EAEN;GACH;EAID,MAAM,iBAAiB;IACrB,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;GAC9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":["SallaComments"],"sources":["src/components/salla-comments/interfaces.ts","src/components/salla-comments/salla-comments.scss?tag=salla-comments","src/components/salla-comments/salla-comments.tsx"],"sourcesContent":["export enum CommentType {\n PAGE= \"page\",\n PRODUCT = \"product\"\n}\n\nexport interface Comment {\n id?: number;\n avatar?: string;\n name?: string;\n has_order?: boolean;\n date?: string;\n rating?: number;\n content?: string;\n is_pending?: boolean;\n replies?: Comment[];\n customer?: Customer;\n type?: string;\n created_at?: CreatedAt;\n}\nexport interface CreatedAt {\n date?: Date;\n timezone_type?: number;\n timezone?: string;\n}\nexport interface UserComments {\n id?: number;\n type?: string;\n next_page?: string;\n comments?: Comment[];\n}\n\n// Pagination\nexport interface Pagination {\n count?: number;\n total?: number;\n perPage?: number;\n currentPage?: number;\n totalPages?: number;\n links?: Links;\n}\nexport interface Customer {\n id?: number;\n name?: string;\n mobile?: string;\n email?: string;\n avatar?: string;\n country?: string;\n city?: string;\n}\nexport interface Links {\n next?: string;\n}\n",":host {\n display: block;\n}\n","import { Component, Prop, State, Element, h } from '@stencil/core';\nimport { CommentType, UserComments, Pagination } from './interfaces';\nimport anime from 'animejs';\nimport Helper from '../../Helpers/Helper';\n@Component({\n tag: 'salla-comments',\n styleUrl: 'salla-comments.scss',\n})\nexport class SallaComments {\n\n constructor() {\n salla.lang.onLoaded(() => {\n this.comment_title = salla.lang.get('blocks.comments.title')\n this.comment_name = salla.lang.get('blocks.comments.comment')\n this.noComments = salla.lang.get('pages.rating.no_ratings')\n })\n }\n\n /**\n * Page or product ID\n */\n @Prop() itemId!: number;\n\n /**\n * Load more text\n */\n @Prop() loadMoreText: string;\n\n /**\n * Load more text\n */\n @Prop() hideForm: boolean;\n\n /**\n * Block Title\n */\n @Prop() blockTitle: string;\n \n /**\n * Hide Title\n */\n @Prop() hideTitle: boolean;\n\n /**\n * Comment Type\n */\n @Prop() type: CommentType.PAGE | CommentType.PRODUCT = CommentType.PAGE;\n\n @State() comments: UserComments[];\n @State() pagination: Pagination;\n @State() total: number;\n @State() showPlaceholder: boolean;\n @State() nextPage: string;\n\n private status: any;\n private btnLoader: any;\n private infiniteScroll: any;\n private wrapper: any;\n\n @Element() host: HTMLElement;\n\n // Translations\n @State() noComments: string = salla.lang.get('blocks.comments.no_comments');\n @State() comment_title = salla.lang.get('blocks.comments.title')\n @State() comment_name = salla.lang.get('blocks.comments.comment')\n @State() placeholder_text: string;\n\n // TOOD: it's a good idea to move this into lang.js\n // Pluralize a string based on the count\n private pluralize(phrases: string, count: number): string {\n const options = phrases.split('|');\n\n const conditions = [\n { condition: count === 0, index: 0 },\n { condition: count === 1, index: 1 },\n { condition: count === 2, index: 2 },\n { condition: count > 2 && count <= 10, index: 3 },\n { condition: count >= 11, index: 4 }\n ];\n\n const { index } = conditions.find(({ condition }) => condition) || { index: options.length - 1 };\n\n const selectedOption = options[index];\n return selectedOption.replace(':count', salla.helpers.number(count.toString()))\n .replace(/\\{[0-9]+\\}/g, '')\n .replace(/\\[\\d+,\\d+\\]|\\[11,\\*\\]/g, '');\n }\n\n\n\n // Initiate infinite scroll\n private initiateInfiniteScroll() {\n if (!this.wrapper) {\n console.error('Wrapper is undefined. Cannot initiate infinite scroll.');\n return;\n }\n\n this.infiniteScroll = salla.infiniteScroll.initiate(this.wrapper, this.wrapper, {\n path: () => this.nextPage,\n history: true,\n nextPage: this.nextPage,\n scrollThreshold: false,\n }, true);\n\n this.infiniteScroll?.on('request', _response => {\n this.loading();\n });\n this.infiniteScroll?.on('load', response => {\n this.pagination = response.pagination;\n this.nextPage = typeof response.pagination.links == 'object' && !!response.pagination.links.next ? response.pagination.links.next : null;\n this.handleResponse(response).forEach(card => this.wrapper.append(card));\n\n let items = this.host.querySelectorAll('salla-comment-item:not(.animated):not(.s-comments-item-admin)');\n this.animateItems(items);\n this.loading(false);\n });\n this.infiniteScroll?.on('error', (e) => {\n salla.console.error('Error loading more comments:', e);\n });\n }\n\n // Show/hide loading\n private loading(isLoading = true) {\n let btnText = this.status?.querySelector('.s-button-text');\n if (btnText) {\n Helper.toggleElementClassIf(btnText, 's-button-hide', 's-button-show', () => isLoading);\n this.btnLoader.style.display = isLoading ? 'inherit' : 'none';\n }\n }\n\n // Animate newly added items\n private animateItems(items) {\n anime({\n targets: items,\n opacity: [0, 1],\n duration: 1200,\n translateY: [20, 0],\n delay: function (_el, i) {\n return i * 100;\n },\n easing: 'easeOutExpo',\n complete: function (_anim) {\n items.forEach(item => {\n item.classList.add('animated');\n })\n }\n\n })\n }\n\n // Get comment item HTML\n private getCommentHTML(comment) {\n const commentItem = document.createElement('salla-comment-item') as HTMLSallaCommentItemElement;\n commentItem.comment = comment;\n\n return commentItem;\n }\n\n\n\n // Parse response and return an array of comment items to be appended to the wrapper\n private handleResponse(response): Array<HTMLElement> {\n return response.data?.map(comment => this.getCommentHTML(comment)) || [];\n }\n\n\n\n // Load initial data\n private async loadInitialData() {\n this.loading();\n try {\n const resp = await (this.type == CommentType.PAGE\n ? salla.api.comment.getPageComments(this.itemId)\n : salla.api.comment.getProductComments(this.itemId));\n if (!resp.data || !resp.data.length) {\n this.showPlaceholder = false;\n this.loading(false);\n return;\n }\n this.comments = resp.data;\n this.pagination = resp.pagination;\n this.total = resp.pagination.total;\n this.nextPage = typeof resp.pagination.links == 'object' && !!resp.pagination.links.next ? resp.pagination.links.next : null;\n\n\n setTimeout(() => {\n this.handleResponse(resp).forEach(card => this.wrapper.append(card));\n this.initiateInfiniteScroll(); // Initiate infinite scroll after the initial data is loaded\n let items = this.wrapper.querySelectorAll('salla-comment-item:not(.animated)');\n this.animateItems(items);\n }, 100);\n } catch (error) {\n console.error('Error loading initial data:', error);\n this.showPlaceholder = true;\n this.loading(false);\n }\n }\n\n // Get next page\n async loadMore() {\n this.infiniteScroll?.loadNextPage();\n }\n\n render() {\n // We should show a different placeholder for pages and products (WIP)\n if (this.showPlaceholder) {\n return (\n <div>\n {!!this.total && !this.hideTitle ? <h2 class=\"s-comments-title\">{this.blockTitle ? this.blockTitle : this.comment_title}</h2> : ''}\n {!this.hideForm && <salla-comment-form type={this.type} item-id={this.itemId}></salla-comment-form>}\n <div class=\"no-content-placeholder--comments\">\n <i class=\"sicon-chat-bubbles text-5xl block mb-5 text-gray-400\"></i>\n <p class=\"text-sm\">{this.noComments}</p>\n </div>\n </div>\n )\n }\n return (\n <div class={`s-comments s-comments-${this.type}`}>\n <div class={`${this.type == CommentType.PAGE ? \"s-comments-page-container\" : \"s-comments-container\"}`} >\n {!!this.total && !this.hideTitle ? <h2 class=\"s-comments-title\">{this.blockTitle ? this.blockTitle : this.comment_title}</h2> : ''}\n {!this.hideForm && <salla-comment-form type={this.type} item-id={this.itemId}></salla-comment-form>}\n\n {!!this.total && <h2 class=\"s-comments-count-label\" innerHTML={this.pluralize(this.comment_name, this.total)}></h2>}\n <div ref={wrapper => this.wrapper = wrapper}></div>\n\n\n {this.nextPage && (\n <div class=\"s-infinite-scroll-wrapper\" ref={status => this.status = status}>\n <button onClick={() => this.loadMore()} class=\"s-infinite-scroll-btn s-button-btn s-button-primary\">\n <span class=\"s-button-text s-infinite-scroll-btn-text\">{this.loadMoreText ? this.loadMoreText : salla.lang.get('common.elements.load_more')}</span>\n <span class=\"s-button-loader s-button-loader-center s-infinite-scroll-btn-loader\" ref={btnLoader => this.btnLoader = btnLoader} style={{ \"display\": \"none\" }}></span>\n </button>\n </div>\n )}\n </div>\n </div>\n\n );\n }\n\n\n\n async componentWillLoad() {\n await this.loadInitialData(); // Load initial data before rendering the component\n }\n\n}\n"],"version":3}
|
|
1
|
+
{"file":"salla-comments.js","mappings":";;;;;;;;;;;AAAA,IAAY,WAGX;AAHD,WAAY,WAAW;EACnB,4BAAY,CAAA;EACZ,kCAAmB,CAAA;AACvB,CAAC,EAHW,WAAW,KAAX,WAAW;;ACAvB,MAAM,gBAAgB,GAAG,sBAAsB;;MCQlCA,eAAa;EAExB;;;;;;;;gBAoCuD,WAAW,CAAC,IAAI;0BAKrC,KAAK;;;;;;sBAgBT,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,6BAA6B,CAAC;yBAClD,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,uBAAuB,CAAC;wBACxC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,yBAAyB,CAAC;;IA1D/D,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC;MAClB,IAAI,CAA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,EAAE,EACjI,CAAC,IAAI,CAAC,QAAQ,IAAI,0BAAoB,IAAI,EAAE,IAAI,CAAC,IAAI,aAAW,IAAI,CAAC,MAAM,GAAuB,EAElG,CAAC,CAAC,IAAI,CAAC,KAAK,IAAI,UAAI,KAAK,EAAC,wBAAwB,EAAC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,KAAK,CAAC,GAAO,EACnH,WAAK,GAAG,EAAE,OAAO,IAAI,IAAI,CAAC,OAAO,GAAG,OAAO,GAAQ,EAGlD,IAAI,CAAC,QAAQ,KACZ,WAAK,KAAK,EAAC,2BAA2B,EAAC,GAAG,EAAE,MAAM,IAAI,IAAI,CAAC,MAAM,GAAG,MAAM,IACxE,cAAQ,OAAO,EAAE,MAAM,IAAI,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAC,qDAAqD,IACjG,YAAM,KAAK,EAAC,0CAA0C,IAAE,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAQ,EACnJ,YAAM,KAAK,EAAC,qEAAqE,EAAC,GAAG,EAAE,SAAS,IAAI,IAAI,CAAC,SAAS,GAAG,SAAS,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,GAAS,CAC9J,CACL,CACP,CACG,CACF,EAEN;GACH;EAID,MAAM,iBAAiB;IACrB,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;GAC9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":["SallaComments"],"sources":["src/components/salla-comments/interfaces.ts","src/components/salla-comments/salla-comments.scss?tag=salla-comments","src/components/salla-comments/salla-comments.tsx"],"sourcesContent":["export enum CommentType {\n PAGE= \"page\",\n PRODUCT = \"product\"\n}\n\nexport interface Comment {\n id?: number;\n avatar?: string;\n name?: string;\n has_order?: boolean;\n date?: string;\n rating?: number;\n content?: string;\n is_pending?: boolean;\n replies?: Comment[];\n customer?: Customer;\n type?: string;\n created_at?: CreatedAt;\n}\nexport interface CreatedAt {\n date?: Date;\n timezone_type?: number;\n timezone?: string;\n}\nexport interface UserComments {\n id?: number;\n type?: string;\n next_page?: string;\n comments?: Comment[];\n}\n\n// Pagination\nexport interface Pagination {\n count?: number;\n total?: number;\n perPage?: number;\n currentPage?: number;\n totalPages?: number;\n links?: Links;\n}\nexport interface Customer {\n id?: number;\n name?: string;\n mobile?: string;\n email?: string;\n avatar?: string;\n country?: string;\n city?: string;\n}\nexport interface Links {\n next?: string;\n}\n",":host {\n display: block;\n}\n","import { Component, Prop, State, Element, h } from '@stencil/core';\nimport { CommentType, UserComments, Pagination } from './interfaces';\nimport anime from 'animejs';\nimport Helper from '../../Helpers/Helper';\n@Component({\n tag: 'salla-comments',\n styleUrl: 'salla-comments.scss',\n})\nexport class SallaComments {\n\n constructor() {\n salla.lang.onLoaded(() => {\n this.comment_title = salla.lang.get('blocks.comments.title')\n this.comment_name = salla.lang.get('blocks.comments.comment')\n this.noComments = salla.lang.get('pages.rating.no_ratings')\n })\n }\n\n /**\n * Page or product ID\n */\n @Prop() itemId!: number;\n\n /**\n * Load more text\n */\n @Prop() loadMoreText: string;\n\n /**\n * Load more text\n */\n @Prop() hideForm: boolean;\n\n /**\n * Block Title\n */\n @Prop() blockTitle: string;\n \n /**\n * Hide Title\n */\n @Prop() hideTitle: boolean;\n\n /**\n * Comment Type\n */\n @Prop() type: CommentType.PAGE | CommentType.PRODUCT = CommentType.PAGE;\n\n /**\n * Show or hide avatar\n */\n @Prop() showFormAvatar: boolean = false;\n\n @State() comments: UserComments[];\n @State() pagination: Pagination;\n @State() total: number;\n @State() showPlaceholder: boolean;\n @State() nextPage: string;\n\n private status: any;\n private btnLoader: any;\n private infiniteScroll: any;\n private wrapper: any;\n\n @Element() host: HTMLElement;\n\n // Translations\n @State() noComments: string = salla.lang.get('blocks.comments.no_comments');\n @State() comment_title = salla.lang.get('blocks.comments.title')\n @State() comment_name = salla.lang.get('blocks.comments.comment')\n @State() placeholder_text: string;\n\n // TOOD: it's a good idea to move this into lang.js\n // Pluralize a string based on the count\n private pluralize(phrases: string, count: number): string {\n const options = phrases.split('|');\n\n const conditions = [\n { condition: count === 0, index: 0 },\n { condition: count === 1, index: 1 },\n { condition: count === 2, index: 2 },\n { condition: count > 2 && count <= 10, index: 3 },\n { condition: count >= 11, index: 4 }\n ];\n\n const { index } = conditions.find(({ condition }) => condition) || { index: options.length - 1 };\n\n const selectedOption = options[index];\n return selectedOption.replace(':count', salla.helpers.number(count.toString()))\n .replace(/\\{[0-9]+\\}/g, '')\n .replace(/\\[\\d+,\\d+\\]|\\[11,\\*\\]/g, '');\n }\n\n\n\n // Initiate infinite scroll\n private initiateInfiniteScroll() {\n if (!this.wrapper) {\n console.error('Wrapper is undefined. Cannot initiate infinite scroll.');\n return;\n }\n\n this.infiniteScroll = salla.infiniteScroll.initiate(this.wrapper, this.wrapper, {\n path: () => this.nextPage,\n history: true,\n nextPage: this.nextPage,\n scrollThreshold: false,\n }, true);\n\n this.infiniteScroll?.on('request', _response => {\n this.loading();\n });\n this.infiniteScroll?.on('load', response => {\n this.pagination = response.pagination;\n this.nextPage = typeof response.pagination.links == 'object' && !!response.pagination.links.next ? response.pagination.links.next : null;\n this.handleResponse(response).forEach(card => this.wrapper.append(card));\n\n let items = this.host.querySelectorAll('salla-comment-item:not(.animated):not(.s-comments-item-admin)');\n this.animateItems(items);\n this.loading(false);\n });\n this.infiniteScroll?.on('error', (e) => {\n salla.console.error('Error loading more comments:', e);\n });\n }\n\n // Show/hide loading\n private loading(isLoading = true) {\n let btnText = this.status?.querySelector('.s-button-text');\n if (btnText) {\n Helper.toggleElementClassIf(btnText, 's-button-hide', 's-button-show', () => isLoading);\n this.btnLoader.style.display = isLoading ? 'inherit' : 'none';\n }\n }\n\n // Animate newly added items\n private animateItems(items) {\n anime({\n targets: items,\n opacity: [0, 1],\n duration: 1200,\n translateY: [20, 0],\n delay: function (_el, i) {\n return i * 100;\n },\n easing: 'easeOutExpo',\n complete: function (_anim) {\n items.forEach(item => {\n item.classList.add('animated');\n })\n }\n\n })\n }\n\n // Get comment item HTML\n private getCommentHTML(comment) {\n const commentItem = document.createElement('salla-comment-item') as HTMLSallaCommentItemElement;\n commentItem.comment = comment;\n\n return commentItem;\n }\n\n\n\n // Parse response and return an array of comment items to be appended to the wrapper\n private handleResponse(response): Array<HTMLElement> {\n return response.data?.map(comment => this.getCommentHTML(comment)) || [];\n }\n\n\n\n // Load initial data\n private async loadInitialData() {\n this.loading();\n try {\n const resp = await (this.type == CommentType.PAGE\n ? salla.api.comment.getPageComments(this.itemId)\n : salla.api.comment.getProductComments(this.itemId));\n if (!resp.data || !resp.data.length) {\n this.showPlaceholder = false;\n this.loading(false);\n return;\n }\n this.comments = resp.data;\n this.pagination = resp.pagination;\n this.total = resp.pagination.total;\n this.nextPage = typeof resp.pagination.links == 'object' && !!resp.pagination.links.next ? resp.pagination.links.next : null;\n\n\n setTimeout(() => {\n this.handleResponse(resp).forEach(card => this.wrapper.append(card));\n this.initiateInfiniteScroll(); // Initiate infinite scroll after the initial data is loaded\n let items = this.wrapper.querySelectorAll('salla-comment-item:not(.animated)');\n this.animateItems(items);\n }, 100);\n } catch (error) {\n console.error('Error loading initial data:', error);\n this.showPlaceholder = true;\n this.loading(false);\n }\n }\n\n // Get next page\n async loadMore() {\n this.infiniteScroll?.loadNextPage();\n }\n\n render() {\n // We should show a different placeholder for pages and products (WIP)\n if (this.showPlaceholder) {\n return (\n <div>\n {!!this.total && !this.hideTitle ? <h2 class=\"s-comments-title\">{this.blockTitle ? this.blockTitle : this.comment_title}</h2> : ''}\n {!this.hideForm && <salla-comment-form show-avatar={this.showFormAvatar} type={this.type} item-id={this.itemId}></salla-comment-form>}\n <div class=\"no-content-placeholder--comments\">\n <i class=\"sicon-chat-bubbles text-5xl block mb-5 text-gray-400\"></i>\n <p class=\"text-sm\">{this.noComments}</p>\n </div>\n </div>\n )\n }\n return (\n <div class={`s-comments s-comments-${this.type}`}>\n <div class={`${this.type == CommentType.PAGE ? \"s-comments-page-container\" : \"s-comments-container\"}`} >\n {!!this.total && !this.hideTitle ? <h2 class=\"s-comments-title\">{this.blockTitle ? this.blockTitle : this.comment_title}</h2> : ''}\n {!this.hideForm && <salla-comment-form type={this.type} item-id={this.itemId}></salla-comment-form>}\n\n {!!this.total && <h2 class=\"s-comments-count-label\" innerHTML={this.pluralize(this.comment_name, this.total)}></h2>}\n <div ref={wrapper => this.wrapper = wrapper}></div>\n\n\n {this.nextPage && (\n <div class=\"s-infinite-scroll-wrapper\" ref={status => this.status = status}>\n <button onClick={() => this.loadMore()} class=\"s-infinite-scroll-btn s-button-btn s-button-primary\">\n <span class=\"s-button-text s-infinite-scroll-btn-text\">{this.loadMoreText ? this.loadMoreText : salla.lang.get('common.elements.load_more')}</span>\n <span class=\"s-button-loader s-button-loader-center s-infinite-scroll-btn-loader\" ref={btnLoader => this.btnLoader = btnLoader} style={{ \"display\": \"none\" }}></span>\n </button>\n </div>\n )}\n </div>\n </div>\n\n );\n }\n\n\n\n async componentWillLoad() {\n await this.loadInitialData(); // Load initial data before rendering the component\n }\n\n}\n"],"version":3}
|