From 3f66b6a0664f6060a4b9f9a5d989dc56660c13c7 Mon Sep 17 00:00:00 2001 From: ge95can Date: Fri, 7 Jun 2024 19:37:06 +0200 Subject: [PATCH] Hide installed --- src/components/Grid.tsx | 2 +- src/logic/FetchRemotes.ts | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/components/Grid.tsx b/src/components/Grid.tsx index 5eba1fcd..47a72f7d 100644 --- a/src/components/Grid.tsx +++ b/src/components/Grid.tsx @@ -489,7 +489,7 @@ class Grid extends React.Component< // Load blacklist and snippets this.BLACKLIST = await getBlacklist(); - this.SNIPPETS = await fetchCssSnippets(); + this.SNIPPETS = await fetchCssSnippets(this.CONFIG.visual.hideInstalled); this.newRequest(ITEMS_PER_REQUEST); } diff --git a/src/logic/FetchRemotes.ts b/src/logic/FetchRemotes.ts index 6e8e65a7..201807d6 100644 --- a/src/logic/FetchRemotes.ts +++ b/src/logic/FetchRemotes.ts @@ -303,7 +303,7 @@ export const getBlacklist = async () => { * It fetches the snippets.json file from the Github repository and returns it as an array of snippets. * @returns Array of snippets */ -export const fetchCssSnippets = async () => { +export const fetchCssSnippets = async (hideInstalled = false) => { const snippetsJSON = (await fetch(SNIPPETS_URL) .then((res) => res.json()) .catch(() => [])) as Snippet[]; @@ -318,8 +318,13 @@ export const fetchCssSnippets = async () => { snip.preview = undefined; } - accum.push(snip); + // Hide installed snippets if option is set and it's installed + if (!(hideInstalled && localStorage.getItem(`marketplace:installed:snippet:${snip.title.replaceAll(" ", "-")}`))) { + accum.push(snip); + } + return accum; }, []); + return snippets; };