Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 15 additions & 14 deletions src/pages/plugins/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,17 +341,21 @@ export default function PluginsInclude(updates) {

async function searchRemotely(query) {
if (!query) return [];
const encodedQuery = encodeURIComponent(query);
const searchUrl = withSupportedEditor(
`${constants.API_BASE}/plugins?name=${encodedQuery}`,
);
try {
const response = await fetch(
withSupportedEditor(`${constants.API_BASE}/plugins?name=${query}`),
);
const plugins = await response.json();
const plugins = await helpers.requestJson(searchUrl);
// Map the plugins to Item elements and return
return plugins.map((plugin) => <Item {...plugin} />);
} catch (error) {
$list.all.setAttribute("empty-msg", strings["error"]);
window.log("error", "Failed to search remotely:");
window.log("error", error);
window.log(
"error",
`Remote plugin search failed for query "${query}" at URL "${searchUrl}"`,
error,
);
return [];
}
}
Expand Down Expand Up @@ -421,21 +425,20 @@ export default function PluginsInclude(updates) {
if (filterState.type === "orderBy") {
const page = filterState.nextPage || 1;
try {
let response;
let items;
if (filterState.value === "top_rated") {
response = await fetch(
items = await helpers.requestJson(
withSupportedEditor(
`${constants.API_BASE}/plugins?explore=random&page=${page}&limit=${LIMIT}`,
),
);
} else {
response = await fetch(
items = await helpers.requestJson(
withSupportedEditor(
`${constants.API_BASE}/plugin?orderBy=${filterState.value}&page=${page}&limit=${LIMIT}`,
),
);
}
const items = await response.json();
if (!Array.isArray(items)) {
return { items: [], hasMore: false };
}
Expand Down Expand Up @@ -470,10 +473,9 @@ export default function PluginsInclude(updates) {

try {
const page = filterState.nextPage;
const response = await fetch(
const data = await helpers.requestJson(
withSupportedEditor(`${constants.API_BASE}/plugins?page=${page}&limit=${LIMIT}`),
);
const data = await response.json();
filterState.nextPage = page + 1;

if (!Array.isArray(data) || !data.length) {
Expand Down Expand Up @@ -567,10 +569,9 @@ export default function PluginsInclude(updates) {

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

const response = await fetch(
const newPlugins = await helpers.requestJson(
withSupportedEditor(`${constants.API_BASE}/plugins?page=${currentPage}&limit=${LIMIT}`),
);
const newPlugins = await response.json();

if (newPlugins.length < LIMIT) {
hasMore = false;
Expand Down
27 changes: 12 additions & 15 deletions src/sidebarApps/extensions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,11 @@ async function loadMorePlugins() {
isLoading = true;
startLoading($explore);

const response = await fetch(
const newPlugins = await helpers.requestJson(
withSupportedEditor(
`${constants.API_BASE}/plugins?page=${currentPage}&limit=${LIMIT}`,
),
);
const newPlugins = await response.json();

if (newPlugins.length < LIMIT) {
hasMore = false;
Expand Down Expand Up @@ -218,7 +217,7 @@ async function searchPlugin() {
$searchResult.onscroll = null;

$searchResult.content = "";
const status = helpers.checkAPIStatus();
const status = await helpers.checkAPIStatus();
if (!status) {
$searchResult.content = (
<span className="error">{strings.api_error}</span>
Expand All @@ -228,14 +227,15 @@ async function searchPlugin() {

const query = this.value;
if (!query) return;
const encodedQuery = encodeURIComponent(query);

try {
$searchResult.classList.add("loading");
const plugins = await fsOperation(
const plugins = await helpers.requestJson(
withSupportedEditor(
Url.join(constants.API_BASE, `plugins?name=${query}`),
Url.join(constants.API_BASE, `plugins?name=${encodedQuery}`),
),
).readFile("json");
);

installedPlugins = await listInstalledPlugins();
$searchResult.content = plugins.map(ListItem);
Expand Down Expand Up @@ -409,7 +409,7 @@ async function loadInstalled() {
async function loadExplore() {
if (this.collapsed) return;

const status = helpers.checkAPIStatus();
const status = await helpers.checkAPIStatus();
if (!status) {
$explore.$ul.content = <span className="error">{strings.api_error}</span>;
return;
Expand All @@ -420,12 +420,11 @@ async function loadExplore() {
currentPage = 1;
hasMore = true;

const response = await fetch(
const plugins = await helpers.requestJson(
withSupportedEditor(
`${constants.API_BASE}/plugins?page=${currentPage}&limit=${LIMIT}`,
),
);
const plugins = await response.json();

if (plugins.length < LIMIT) {
hasMore = false;
Expand Down Expand Up @@ -463,21 +462,20 @@ async function getFilteredPlugins(filterState) {
if (filterState.type === "orderBy") {
const page = filterState.nextPage || 1;
try {
let response;
let items;
if (filterState.value === "top_rated") {
response = await fetch(
items = await helpers.requestJson(
withSupportedEditor(
`${constants.API_BASE}/plugins?explore=random&page=${page}&limit=${LIMIT}`,
),
);
} else {
response = await fetch(
items = await helpers.requestJson(
withSupportedEditor(
`${constants.API_BASE}/plugin?orderBy=${filterState.value}&page=${page}&limit=${LIMIT}`,
),
);
}
const items = await response.json();
if (!Array.isArray(items)) {
return { items: [], hasMore: false };
}
Expand Down Expand Up @@ -512,12 +510,11 @@ async function getFilteredPlugins(filterState) {

try {
const page = filterState.nextPage;
const response = await fetch(
const data = await helpers.requestJson(
withSupportedEditor(
`${constants.API_BASE}/plugins?page=${page}&limit=${LIMIT}`,
),
);
const data = await response.json();
filterState.nextPage = page + 1;

if (!Array.isArray(data) || !data.length) {
Expand Down
Loading