{"version":3,"file":"social-wall-list-DxSABSEU.js","sources":["../../src/project/AramcoLife/social-wall/social-wall-list.ts"],"sourcesContent":["import { type Module } from \"~/foundation/Bootstrapper/types\";\r\nimport { isRtl } from \"~/foundation/Helpers/isRtl\";\r\nimport { addLoader } from \"~/foundation/Loaders/loader\";\r\nimport { type DistinctSocialWallElements, type SocialWallListData } from \"../generated-types\";\r\nimport { socialWallService } from \"../services/socialWallService\";\r\nimport { addVideoEventListeners, removeLoader, renderSocialWallItem } from \"./markup/socialWallMarkup\";\r\nimport \"./social-wall.scss\";\r\n\r\nconst socialWallList: Module = async (element, props) => {\r\n\tconst pageSize = props.listLength || 11;\r\n\tconst socialWallListElement = element.querySelector(\".social-wall__list\");\r\n\tconst loadMoreBtn = element.querySelector(\".social-wall__load-more\");\r\n\tconst minutesToCacheInMilliseconds = (props.minutesToCache || 5) * 1000 * 60;\r\n\tlet currentIndex = pageSize;\r\n\r\n\tlet firstItem: DistinctSocialWallElements | null = null;\r\n\tlet socialWallItems: DistinctSocialWallElements[] = [];\r\n\tlet socialWallItemsCount = 0;\r\n\r\n\tconst loadMoreItems = async (addFocus: boolean) => {\r\n\t\tloadMoreBtn?.classList.add(\"social-wall__load-more--hide\");\r\n\t\taddLoader(element);\r\n\r\n\t\tif (currentIndex === 0) {\r\n\t\t\tcurrentIndex = pageSize;\r\n\t\t}\r\n\r\n\t\tconst nextIndex = Math.min(currentIndex + pageSize, socialWallItems.length);\r\n\t\tconst gridElement = socialWallListElement?.querySelector(\".social-wall__item-grid\");\r\n\t\tif (gridElement) {\r\n\t\t\tconst newItems = socialWallItems.slice(currentIndex, nextIndex);\r\n\t\t\tconst loaditems = newItems.map(x => renderSocialWallItem(x, props.dictionary));\r\n\t\t\tconst items = await Promise.all(loaditems);\r\n\r\n\t\t\titems.forEach((element, i) => {\r\n\t\t\t\tgridElement.appendChild(element!);\r\n\r\n\t\t\t\tif (i === 0 && addFocus) {\r\n\t\t\t\t\telement.setAttribute(\"tabindex\", \"0\");\r\n\t\t\t\t\telement.focus({ preventScroll: true });\r\n\t\t\t\t}\r\n\t\t\t});\r\n\t\t}\r\n\r\n\t\tcurrentIndex = nextIndex;\r\n\r\n\t\tconst newMediaWrappers = gridElement?.querySelectorAll(\".media-wrapper\");\r\n\t\tif (newMediaWrappers) {\r\n\t\t\taddVideoEventListeners(newMediaWrappers);\r\n\t\t}\r\n\r\n\t\tif (currentIndex >= socialWallItems.length) {\r\n\t\t\tloadMoreBtn?.setAttribute(\"disabled\", \"true\");\r\n\t\t\tloadMoreBtn?.classList.add(\"social-wall__load-more--hide\");\r\n\t\t} else {\r\n\t\t\tloadMoreBtn?.classList.remove(\"social-wall__load-more--hide\");\r\n\t\t}\r\n\r\n\t\tremoveLoader(element);\r\n\t};\r\n\r\n\tconst renderInitialLoad = async (intervalReload: boolean) => {\r\n\t\tif (!intervalReload) {\r\n\t\t\taddLoader(element);\r\n\t\t}\r\n\r\n\t\tconst response = await socialWallService.feed({ language: props.language! });\r\n\r\n\t\tif (!intervalReload) {\r\n\t\t\tremoveLoader(element);\r\n\t\t}\r\n\r\n\t\tlet reloadHtml = false;\r\n\r\n\t\t[firstItem, ...socialWallItems] = response.data || [];\r\n\t\tsocialWallItems = socialWallItems.filter(x => x.text);\r\n\t\tif (socialWallItems.length > socialWallItemsCount) {\r\n\t\t\tsocialWallItemsCount = socialWallItems.length;\r\n\t\t\treloadHtml = true;\r\n\t\t}\r\n\r\n\t\tif (response.error || response.data?.length === 0) {\r\n\t\t\tconsole.error(\"Error fetching social wall data:\", response.error);\r\n\t\t\tif (element) {\r\n\t\t\t\telement.innerHTML = `${isRtl\r\n\t\t\t\t\t? `يبدو أن هناك مشكلة في الحصول على الأخبار. الرجاء المحاولة في وقت لاحق `\r\n\t\t\t\t\t: `Looks like there was a problem getting the social news. Please try again later.`\r\n\t\t\t\t\t}`;\r\n\t\t\t}\r\n\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tif (reloadHtml) {\r\n\t\t\tif (socialWallListElement && socialWallItems.length > 0) {\r\n\t\t\t\tconst firstElement = await renderSocialWallItem(firstItem, props.dictionary);\r\n\t\t\t\tconst firstItemHTML = firstElement!.outerHTML;\r\n\r\n\t\t\t\tsocialWallListElement.innerHTML = `\r\n\t\t\t\t\t\r\n\t\t\t\t\t\r\n\t\t\t\t`;\r\n\r\n\t\t\t\tcurrentIndex = 0;\r\n\r\n\t\t\t\tconst newMediaWrappers = socialWallListElement?.querySelectorAll(\".media-wrapper\");\r\n\t\t\t\tif (newMediaWrappers) {\r\n\t\t\t\t\taddVideoEventListeners(newMediaWrappers);\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (currentIndex >= socialWallItems.length) {\r\n\t\t\t\t\tloadMoreBtn?.classList.add(\"social-wall__load-more--hide\");\r\n\t\t\t\t} else {\r\n\t\t\t\t\tloadMoreBtn?.classList.remove(\"social-wall__load-more--hide\");\r\n\t\t\t\t}\r\n\r\n\t\t\t\tconst gridElement = socialWallListElement?.querySelector(\".social-wall__item-grid\");\r\n\t\t\t\tif (gridElement) {\r\n\t\t\t\t\tconst newItems = socialWallItems.slice(currentIndex, pageSize);\r\n\t\t\t\t\tconst loaditems = newItems.map(x => renderSocialWallItem(x, props.dictionary));\r\n\t\t\t\t\tconst items = await Promise.all(loaditems);\r\n\r\n\t\t\t\t\tconst itemsHtml: string[] = [];\r\n\r\n\t\t\t\t\titems.forEach((element, i) => {\r\n\t\t\t\t\t\tif (i === 0) {\r\n\t\t\t\t\t\t\telement.setAttribute(\"tabindex\", \"0\");\r\n\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\titemsHtml.push(element.outerHTML);\r\n\r\n\t\t\t\t\t\t// gridElement.appendChild(element!);\r\n\t\t\t\t\t\t// element.setAttribute(\"tabindex\", \"0\");\r\n\t\t\t\t\t\t// element.focus();\r\n\t\t\t\t\t});\r\n\r\n\t\t\t\t\tgridElement.innerHTML = itemsHtml.join(\"\");\r\n\t\t\t\t\tconst mediaWrappers = gridElement?.querySelectorAll(\".media-wrapper\");\r\n\t\t\t\t\tif (mediaWrappers) {\r\n\t\t\t\t\t\taddVideoEventListeners(mediaWrappers);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t};\r\n\r\n\tawait renderInitialLoad(false);\r\n\r\n\tconst reloadInterval = setInterval(() => renderInitialLoad(true), minutesToCacheInMilliseconds);\r\n\r\n\tloadMoreBtn?.addEventListener(\"click\", async () => {\r\n\t\tloadMoreBtn?.setAttribute(\"disabled\", \"true\");\r\n\t\tloadMoreBtn?.setAttribute(\"aria-disabled\", \"true\");\r\n\t\tclearInterval(reloadInterval);\r\n\t\tawait loadMoreItems(true);\r\n\r\n\t\tloadMoreBtn?.removeAttribute(\"disabled\");\r\n\t\tloadMoreBtn?.setAttribute(\"aria-disabled\", \"false\");\r\n\t});\r\n};\r\n\r\nexport default socialWallList;"],"names":["socialWallList","element","props","pageSize","socialWallListElement","loadMoreBtn","minutesToCacheInMilliseconds","currentIndex","firstItem","socialWallItems","socialWallItemsCount","loadMoreItems","addFocus","addLoader","nextIndex","gridElement","loaditems","x","renderSocialWallItem","i","newMediaWrappers","addVideoEventListeners","removeLoader","renderInitialLoad","intervalReload","response","socialWallService","reloadHtml","_a","isRtl","firstItemHTML","items","itemsHtml","mediaWrappers","reloadInterval"],"mappings":"mKAQM,MAAAA,EAA6C,MAAOC,EAASC,IAAU,CACtE,MAAAC,EAAWD,EAAM,YAAc,GAC/BE,EAAwBH,EAAQ,cAAc,oBAAoB,EAClEI,EAAcJ,EAAQ,cAAc,yBAAyB,EAC7DK,GAAgCJ,EAAM,gBAAkB,GAAK,IAAO,GAC1E,IAAIK,EAAeJ,EAEfK,EAA+C,KAC/CC,EAAgD,CAAA,EAChDC,EAAuB,EAErB,MAAAC,EAAgB,MAAOC,GAAsB,CACrCP,GAAA,MAAAA,EAAA,UAAU,IAAI,gCAC3BQ,EAAUZ,CAAO,EAEbM,IAAiB,IACLA,EAAAJ,GAGhB,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