Skip to content

Commit 6b3bd28

Browse files
feat: option to show archived repos & archived tag (#679)
1 parent a354730 commit 6b3bd28

File tree

10 files changed

+59
-20
lines changed

10 files changed

+59
-20
lines changed

src/app.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ class App extends React.Component<{
103103
visual: {
104104
stars: JSON.parse(getLocalStorageDataFromKey("marketplace:stars", true)),
105105
tags: JSON.parse(getLocalStorageDataFromKey("marketplace:tags", true)),
106+
showArchived: JSON.parse(getLocalStorageDataFromKey("marketplace:showArchived", false)),
106107
hideInstalled: JSON.parse(getLocalStorageDataFromKey("marketplace:hideInstalled", false)),
107108
colorShift: JSON.parse(getLocalStorageDataFromKey("marketplace:colorShift", false)),
108109
themeDevTools: JSON.parse(getLocalStorageDataFromKey("marketplace:themeDevTools", false)),

src/components/Card/Card.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class Card extends React.Component<CardProps, {
7171
// Needs to be after Object.assign so an undefined 'tags' field doesn't overwrite the default []
7272
this.tags = props.item.tags || [];
7373
if (props.item.include) this.tags.push(t("grid.externalJS"));
74+
if (props.item.archived) this.tags.push(t("grid.archived"));
7475

7576
this.state = {
7677
// Initial value. Used to trigger a re-render.

src/components/Card/TagsDiv.tsx

+12-6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const TagsDiv = (props: {
1212
// Map of english names for tags so that the css can identify them for colouring
1313
const englishTagMap = {
1414
[t("grid.externalJS")]: "external JS",
15+
[t("grid.archived")]: "archived",
1516
[t("grid.dark")]: "dark",
1617
[t("grid.light")]: "light",
1718
};
@@ -26,8 +27,8 @@ const TagsDiv = (props: {
2627
"data-tag": string;
2728
}, HTMLElement>[]>((accum, tag) => {
2829
const englishTag = englishTagMap[tag] || tag;
29-
// Render tags if enabled. Always render external JS tag
30-
if (props.showTags || tag === t("grid.externalJS")) {
30+
// Render tags if enabled. Always render external JS and archived tags
31+
if (props.showTags || tag === t("grid.externalJS") || tag === t("grid.archived")) {
3132
accum.push(
3233
React.createElement("li", {
3334
className: "marketplace-card__tag",
@@ -40,20 +41,25 @@ const TagsDiv = (props: {
4041
}, []);
4142
};
4243

43-
const baseTags = props.tags.slice(0, MAX_TAGS);
44+
const baseTags = props.tags
45+
// Sort tags so that externalJS and archived tags come first
46+
.sort((a) =>
47+
a === t("grid.externalJS") || a === t("grid.archived") ? -1 : 1,
48+
)
49+
.slice(0, MAX_TAGS);
4450
const extraTags = props.tags.slice(MAX_TAGS);
4551

4652
// Render the tags list and add expand button if there are more tags
4753
return (
4854
<div className="marketplace-card__tags-container">
4955
<ul className="marketplace-card__tags">
50-
{ generateTags(baseTags) }
51-
{ extraTags.length && expanded
56+
{generateTags(baseTags)}
57+
{extraTags.length && expanded
5258
? generateTags(extraTags)
5359
: null
5460
}
5561
</ul>
56-
{ extraTags.length && !expanded
62+
{extraTags.length && !expanded
5763
? <button
5864
className="marketplace-card__tags-more-btn"
5965
onClick={(e) => {

src/components/Grid.tsx

+24-4
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,12 @@ class Grid extends React.Component<
190190
const activeTab = this.CONFIG.activeTab;
191191
switch (activeTab) {
192192
case "Extensions": {
193-
const pageOfRepos = await getTaggedRepos("spicetify-extensions", this.requestPage, this.BLACKLIST);
193+
const pageOfRepos = await getTaggedRepos(
194+
"spicetify-extensions",
195+
this.requestPage,
196+
this.BLACKLIST,
197+
this.CONFIG.visual.showArchived,
198+
);
194199
const extensions: CardItem[] = [];
195200
for (const repo of pageOfRepos.items) {
196201
const repoExtensions = await fetchExtensionManifest(
@@ -208,7 +213,10 @@ class Grid extends React.Component<
208213

209214
if (repoExtensions && repoExtensions.length) {
210215
extensions.push(...repoExtensions.map((extension) => ({
211-
...extension, lastUpdated: repo.pushed_at, created: repo.created_at,
216+
...extension,
217+
archived: repo.archived,
218+
lastUpdated: repo.pushed_at,
219+
created: repo.created_at,
212220
})));
213221
}
214222
}
@@ -266,7 +274,12 @@ class Grid extends React.Component<
266274
// Don't need to return a page number because
267275
// installed extension do them all in one go, since it's local
268276
} case "Themes": {
269-
const pageOfRepos = await getTaggedRepos("spicetify-themes", this.requestPage, this.BLACKLIST);
277+
const pageOfRepos = await getTaggedRepos(
278+
"spicetify-themes",
279+
this.requestPage,
280+
this.BLACKLIST,
281+
this.CONFIG.visual.showArchived,
282+
);
270283
const themes: CardItem[] = [];
271284
for (const repo of pageOfRepos.items) {
272285
const repoThemes = await fetchThemeManifest(
@@ -285,6 +298,7 @@ class Grid extends React.Component<
285298
themes.push(...repoThemes.map(
286299
(theme) => ({
287300
...theme,
301+
archived: repo.archived,
288302
lastUpdated: repo.pushed_at,
289303
created: repo.created_at,
290304
}),
@@ -311,7 +325,12 @@ class Grid extends React.Component<
311325
break;
312326
}
313327
case "Apps": {
314-
const pageOfRepos = await getTaggedRepos("spicetify-apps", this.requestPage, this.BLACKLIST);
328+
const pageOfRepos = await getTaggedRepos(
329+
"spicetify-apps",
330+
this.requestPage,
331+
this.BLACKLIST,
332+
this.CONFIG.visual.showArchived,
333+
);
315334
const apps: CardItem[] = [];
316335

317336
for (const repo of pageOfRepos.items) {
@@ -329,6 +348,7 @@ class Grid extends React.Component<
329348
if (repoApps && repoApps.length) {
330349
apps.push(...repoApps.map((app) => ({
331350
...app,
351+
archived: repo.archived,
332352
lastUpdated: repo.pushed_at,
333353
created: repo.created_at,
334354
})));

src/components/Modals/Settings/index.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import React from "react";
22
import { t } from "i18next";
3-
import { Config } from "../../../types/marketplace-types";
43

4+
import { Config } from "../../../types/marketplace-types";
55
import { getLocalStorageDataFromKey, resetMarketplace, sleep } from "../../../logic/Utils";
6-
76
import ConfigRow from "./ConfigRow";
87
import Button from "../../Button";
98
import TabRow from "./TabRow";
10-
119
import { openModal } from "../../../logic/LaunchModals";
1210
import { LOCALSTORAGE_KEYS, MARKETPLACE_VERSION } from "../../../constants";
1311

@@ -60,6 +58,7 @@ const SettingsModal = ({ CONFIG, updateAppConfig } : Props) => {
6058
<h2 className="settings-heading">{t("settings.optionsHeading")}</h2>
6159
<ConfigRow name={t("settings.starCountLabel")} storageKey='stars' modalConfig={modalConfig} updateConfig={updateConfig}/>
6260
<ConfigRow name={t("settings.tagsLabel")} storageKey='tags' modalConfig={modalConfig} updateConfig={updateConfig}/>
61+
<ConfigRow name={t("settings.showArchived")} storageKey='showArchived' modalConfig={modalConfig} updateConfig={updateConfig}/>
6362
<ConfigRow name={t("settings.devToolsLabel")} storageKey='themeDevTools' modalConfig={modalConfig} updateConfig={updateConfig}/>
6463
<ConfigRow name={t("settings.hideInstalledLabel")} storageKey='hideInstalled' modalConfig={modalConfig} updateConfig={updateConfig}/>
6564
<ConfigRow name={t("settings.colourShiftLabel")} storageKey='colorShift' modalConfig={modalConfig} updateConfig={updateConfig}/>

src/logic/FetchRemotes.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { t } from "i18next";
22

33
import { BLACKLIST_URL, ITEMS_PER_REQUEST } from "../constants";
4-
import { addToSessionStorage, processAuthors } from "./Utils";
54
import { RepoTopic, CardItem, Snippet } from "../types/marketplace-types";
5+
import { addToSessionStorage, processAuthors } from "./Utils";
66
import snippetsJSON from "../resources/snippets";
77

88
// TODO: add sort type, order, etc?
@@ -15,7 +15,7 @@ import snippetsJSON from "../resources/snippets";
1515
* @param page The query page number
1616
* @returns Array of search results (filtered through the blacklist)
1717
*/
18-
export async function getTaggedRepos(tag: RepoTopic, page = 1, BLACKLIST:string[] = []) {
18+
export async function getTaggedRepos(tag: RepoTopic, page = 1, BLACKLIST:string[] = [], showArchived = false) {
1919
// www is needed or it will block with "cross-origin" error.
2020
let url = `https://api.github.com/search/repositories?q=${encodeURIComponent(`topic:${tag}`)}&per_page=${ITEMS_PER_REQUEST}`;
2121

@@ -41,7 +41,7 @@ export async function getTaggedRepos(tag: RepoTopic, page = 1, BLACKLIST:string[
4141
// Include count of all items on the page, since we're filtering the blacklist below,
4242
// which can mess up the paging logic
4343
page_count: allRepos.items.length,
44-
items: allRepos.items.filter(item => !BLACKLIST.includes(item.html_url)),
44+
items: allRepos.items.filter(item => !BLACKLIST.includes(item.html_url) && (showArchived || !item.archived)),
4545
};
4646

4747
return filteredResults;
@@ -149,9 +149,14 @@ export async function fetchExtensionManifest(contents_url: string, branch: strin
149149
if (manifest && manifest.name && manifest.description && manifest.main
150150
) {
151151
// Add to list unless we're hiding installed items and it's installed
152-
if (!(hideInstalled
153-
&& localStorage.getItem("marketplace:installed:" + `${user}/${repo}/${manifest.main}`))
154-
) accum.push(item);
152+
if (
153+
!(
154+
hideInstalled &&
155+
localStorage.getItem("marketplace:installed:" + `${user}/${repo}/${manifest.main}`)
156+
)
157+
) {
158+
accum.push(item);
159+
}
155160
}
156161
// else {
157162
// console.error("Invalid manifest:", manifest);

src/resources/locales/en.json

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"optionsHeading": "Options",
66
"starCountLabel": "Stars count",
77
"tagsLabel": "Tags",
8+
"showArchived": "Show archived repos",
89
"devToolsLabel": "Theme developer tools",
910
"hideInstalledLabel": "Hide installed when browsing",
1011
"colourShiftLabel": "Shift colours every minute",
@@ -91,6 +92,7 @@
9192
"installed": "Installed",
9293
"lastUpdated": "Last updated {{val, datetime}}",
9394
"externalJS": "external JS",
95+
"archived": "archived",
9496
"dark": "dark",
9597
"light": "light",
9698
"sort": {

src/resources/locales/ru.json

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"optionsHeading": "Основные",
66
"starCountLabel": "Отображать количество звезд",
77
"tagsLabel": "Отображать теги",
8+
"showArchived": "Отображать архивные репозитории",
89
"devToolsLabel": "Включить инструменты разработчика тем",
910
"hideInstalledLabel": "Скрывать установленное в других вкладках",
1011
"colourShiftLabel": "Менять цвета каждую минуту",
@@ -91,6 +92,7 @@
9192
"installed": "Установлено",
9293
"lastUpdated": "Обновлено: {{val, datetime}}",
9394
"externalJS": "содержит JS",
95+
"archived": "архивировано",
9496
"dark": "темный",
9597
"light": "светлый",
9698
"sort": {

src/styles/components/_card.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
border-radius: 4px;
4040
padding: 0px 9px 2px;
4141

42-
&[data-tag='external JS'] {
42+
&[data-tag='external JS'], &[data-tag=archived] {
4343
background-color: hsl(0deg 70% 54%);
4444
color: #fff;
4545
}

src/types/marketplace-types.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export type Snippet = {
5858
user: undefined;
5959
repo: undefined;
6060
branch: undefined;
61+
archived: undefined;
6162
extensionURL: undefined;
6263
readmeURL: undefined;
6364
stars: undefined;
@@ -95,6 +96,7 @@ export type CardItem = {
9596
user: string;
9697
repo: string;
9798
branch: string;
99+
archived: boolean;
98100
imageURL: string;
99101
extensionURL: string;
100102
readmeURL: string;
@@ -126,6 +128,7 @@ export type CardItem = {
126128
export type VisualConfig = {
127129
stars: boolean;
128130
tags: boolean;
131+
showArchived: boolean;
129132
hideInstalled: boolean;
130133
colorShift: boolean;
131134
themeDevTools: boolean;

0 commit comments

Comments
 (0)