From d374b79b86f61f06ec6b2074b926b206234d0eb8 Mon Sep 17 00:00:00 2001 From: CharlieS1103 Date: Wed, 5 Jul 2023 21:30:51 -0400 Subject: [PATCH 01/15] Begin implementing sortbox --- src/app.tsx | 1 + src/components/Grid.tsx | 7 ++++++- src/logic/Utils.ts | 9 +++++++++ src/types/marketplace-types.d.ts | 1 + 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/app.tsx b/src/app.tsx index 0deeae85..6833884c 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -133,6 +133,7 @@ class App extends React.Component<{ schemes, activeScheme, }, + sort: getLocalStorageDataFromKey(LOCALSTORAGE_KEYS.sortBy, "stars"), }; if (!this.CONFIG.activeTab || !this.CONFIG.tabs.filter(tab => tab.name === this.CONFIG.activeTab).length) { diff --git a/src/components/Grid.tsx b/src/components/Grid.tsx index 6180bd0a..b7d5563f 100644 --- a/src/components/Grid.tsx +++ b/src/components/Grid.tsx @@ -5,7 +5,7 @@ import { Option } from "react-dropdown"; const Spicetify = window.Spicetify; import { CardItem, CardType, Config, SchemeIni, Snippet, TabItemConfig } from "../types/marketplace-types"; -import { getLocalStorageDataFromKey, generateSchemesOptions, injectColourScheme } from "../logic/Utils"; +import { getLocalStorageDataFromKey, generateSchemesOptions, injectColourScheme, generateSortOptions } from "../logic/Utils"; import { LOCALSTORAGE_KEYS, ITEMS_PER_REQUEST, MARKETPLACE_VERSION, LATEST_RELEASE } from "../constants"; import { openModal } from "../logic/LaunchModals"; import { @@ -534,6 +534,11 @@ class Grid extends React.Component< this.setState({ searchValue: event.target.value }); }} /> + {/* Generate a new box for sorting options, the options should be newest, stars, a-z, oldest, and z-a*/} + this.updateSort(value)} + sortBoxOptions={generateSortOptions()} + sortBySelectedFn={(a) => a.key === this.CONFIG.sort} /> : null} + {/* Generate a new box for sorting options */} +

Sort by:

+ this.updateSort(value)} + sortBoxOptions={generateSortOptions()} + sortBySelectedFn={(a) => a.key === this.CONFIG.sort} />
{/* Show theme developer tools button if themeDevTools is enabled */} @@ -559,12 +564,6 @@ class Grid extends React.Component< this.setState({ searchValue: event.target.value }); }} />
- {/* Generate a new box for sorting options */} - this.updateSort(value)} - sortBoxOptions={generateSortOptions()} - sortBySelectedFn={(a) => a.key === this.CONFIG.sort} /> - : null} {/* Generate a new box for sorting options */} -

Sort by:

+

{t("grid.sort.label")}

this.updateSort(value)} - sortBoxOptions={generateSortOptions()} + sortBoxOptions={generateSortOptions(t)} sortBySelectedFn={(a) => a.key === this.CONFIG.sort} />
diff --git a/src/logic/Utils.ts b/src/logic/Utils.ts index 6da92a92..a117d978 100644 --- a/src/logic/Utils.ts +++ b/src/logic/Utils.ts @@ -191,7 +191,12 @@ export const generateSchemesOptions = (schemes: SchemeIni) => { )); }; -export const generateSortOptions = () => { +/** + * Generate a list of options for the sort dropdown + * @param t The string translation function + * @returns The sort options for the sort dropdown + */ +export const generateSortOptions = (t: (key: string) => string) => { // TODO: It would be great if I could disable the options that don't apply for snippets // But it looks like that's not supported by the library // https://github.com/fraserxu/react-dropdown/pull/176 @@ -199,11 +204,11 @@ export const generateSortOptions = () => { // but then the sort resets when you switch tabs and it's disruptive return [ - { key: "stars", value: "Stars" }, - { key: "newest", value: "Newest" }, - { key: "oldest", value: "Oldest" }, - { key: "a-z", value: "A-Z" }, - { key: "z-a", value: "Z-A" }, + { key: "stars", value: t("grid.sort.stars") }, + { key: "newest", value: t("grid.sort.newest") }, + { key: "oldest", value: t("grid.sort.oldest") }, + { key: "a-z", value: t("grid.sort.aToZ") }, + { key: "z-a", value: t("grid.sort.zToA") }, ]; }; /** diff --git a/src/resources/locales/en.json b/src/resources/locales/en.json index c08ac075..ee3be9fa 100644 --- a/src/resources/locales/en.json +++ b/src/resources/locales/en.json @@ -81,7 +81,15 @@ "lastUpdated": "Last updated {{val, datetime}}", "externalJS": "external JS", "dark": "dark", - "light": "light" + "light": "light", + "sort": { + "label": "Sort by:", + "stars": "Stars", + "newest": "Newest", + "oldest": "Oldest", + "aToZ": "A-Z", + "zToA": "Z-A" + } }, "readmePage": { "title": "$t(grid.spicetifyMarketplace) - Readme",