Skip to content

Commit e2712ea

Browse files
committed
feat(plugins): filter marketplace lists to CodeMirror-compatible plugins
1 parent 896e552 commit e2712ea

File tree

2 files changed

+41
-11
lines changed

2 files changed

+41
-11
lines changed

src/pages/plugins/plugins.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ export default function PluginsInclude(updates) {
5252
let isSearching = false;
5353
let currentFilter = null;
5454
const LIMIT = 50;
55+
const SUPPORTED_EDITOR = "cm";
56+
57+
const withSupportedEditor = (url) => {
58+
const separator = url.includes("?") ? "&" : "?";
59+
return `${url}${separator}supported_editor=${SUPPORTED_EDITOR}`;
60+
};
5561

5662
Contextmenu({
5763
toggler: $add,
@@ -337,7 +343,7 @@ export default function PluginsInclude(updates) {
337343
if (!query) return [];
338344
try {
339345
const response = await fetch(
340-
`${constants.API_BASE}/plugins?name=${query}`,
346+
withSupportedEditor(`${constants.API_BASE}/plugins?name=${query}`),
341347
);
342348
const plugins = await response.json();
343349
// Map the plugins to Item elements and return
@@ -418,11 +424,15 @@ export default function PluginsInclude(updates) {
418424
let response;
419425
if (filterState.value === "top_rated") {
420426
response = await fetch(
421-
`${constants.API_BASE}/plugins?explore=random&page=${page}&limit=${LIMIT}`,
427+
withSupportedEditor(
428+
`${constants.API_BASE}/plugins?explore=random&page=${page}&limit=${LIMIT}`,
429+
),
422430
);
423431
} else {
424432
response = await fetch(
425-
`${constants.API_BASE}/plugin?orderBy=${filterState.value}&page=${page}&limit=${LIMIT}`,
433+
withSupportedEditor(
434+
`${constants.API_BASE}/plugin?orderBy=${filterState.value}&page=${page}&limit=${LIMIT}`,
435+
),
426436
);
427437
}
428438
const items = await response.json();
@@ -461,7 +471,7 @@ export default function PluginsInclude(updates) {
461471
try {
462472
const page = filterState.nextPage;
463473
const response = await fetch(
464-
`${constants.API_BASE}/plugins?page=${page}&limit=${LIMIT}`,
474+
withSupportedEditor(`${constants.API_BASE}/plugins?page=${page}&limit=${LIMIT}`),
465475
);
466476
const data = await response.json();
467477
filterState.nextPage = page + 1;
@@ -557,7 +567,9 @@ export default function PluginsInclude(updates) {
557567

558568
$list.all.setAttribute("empty-msg", strings["loading..."]);
559569

560-
const response = await fetch(`${constants.API_BASE}/plugins?page=${currentPage}&limit=${LIMIT}`);
570+
const response = await fetch(
571+
withSupportedEditor(`${constants.API_BASE}/plugins?page=${currentPage}&limit=${LIMIT}`),
572+
);
561573
const newPlugins = await response.json();
562574

563575
if (newPlugins.length < LIMIT) {

src/sidebarApps/extensions/index.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ let isLoading = false;
3333
let currentFilter = null;
3434
let filterHasMore = true;
3535
let isFilterLoading = false;
36+
const SUPPORTED_EDITOR = "cm";
37+
38+
function withSupportedEditor(url) {
39+
const separator = url.includes("?") ? "&" : "?";
40+
return `${url}${separator}supported_editor=${SUPPORTED_EDITOR}`;
41+
}
3642

3743
const $header = (
3844
<div className="header">
@@ -140,7 +146,9 @@ async function loadMorePlugins() {
140146
startLoading($explore);
141147

142148
const response = await fetch(
143-
`${constants.API_BASE}/plugins?page=${currentPage}&limit=${LIMIT}`,
149+
withSupportedEditor(
150+
`${constants.API_BASE}/plugins?page=${currentPage}&limit=${LIMIT}`,
151+
),
144152
);
145153
const newPlugins = await response.json();
146154

@@ -224,7 +232,9 @@ async function searchPlugin() {
224232
try {
225233
$searchResult.classList.add("loading");
226234
const plugins = await fsOperation(
227-
Url.join(constants.API_BASE, `plugins?name=${query}`),
235+
withSupportedEditor(
236+
Url.join(constants.API_BASE, `plugins?name=${query}`),
237+
),
228238
).readFile("json");
229239

230240
installedPlugins = await listInstalledPlugins();
@@ -411,7 +421,9 @@ async function loadExplore() {
411421
hasMore = true;
412422

413423
const response = await fetch(
414-
`${constants.API_BASE}/plugins?page=${currentPage}&limit=${LIMIT}`,
424+
withSupportedEditor(
425+
`${constants.API_BASE}/plugins?page=${currentPage}&limit=${LIMIT}`,
426+
),
415427
);
416428
const plugins = await response.json();
417429

@@ -454,11 +466,15 @@ async function getFilteredPlugins(filterState) {
454466
let response;
455467
if (filterState.value === "top_rated") {
456468
response = await fetch(
457-
`${constants.API_BASE}/plugins?explore=random&page=${page}&limit=${LIMIT}`,
469+
withSupportedEditor(
470+
`${constants.API_BASE}/plugins?explore=random&page=${page}&limit=${LIMIT}`,
471+
),
458472
);
459473
} else {
460474
response = await fetch(
461-
`${constants.API_BASE}/plugin?orderBy=${filterState.value}&page=${page}&limit=${LIMIT}`,
475+
withSupportedEditor(
476+
`${constants.API_BASE}/plugin?orderBy=${filterState.value}&page=${page}&limit=${LIMIT}`,
477+
),
462478
);
463479
}
464480
const items = await response.json();
@@ -497,7 +513,9 @@ async function getFilteredPlugins(filterState) {
497513
try {
498514
const page = filterState.nextPage;
499515
const response = await fetch(
500-
`${constants.API_BASE}/plugins?page=${page}&limit=${LIMIT}`,
516+
withSupportedEditor(
517+
`${constants.API_BASE}/plugins?page=${page}&limit=${LIMIT}`,
518+
),
501519
);
502520
const data = await response.json();
503521
filterState.nextPage = page + 1;

0 commit comments

Comments
 (0)