Skip to content

Commit

Permalink
feat(snippets): hide installed snippets if option is enabled (#777)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhngharry authored Jun 17, 2024
1 parent 559caf8 commit bd618ad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/components/Grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
9 changes: 7 additions & 2 deletions src/logic/FetchRemotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand All @@ -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;
};

0 comments on commit bd618ad

Please sign in to comment.