Added secondary stash button, centralized bookmark (heart) component.

This commit is contained in:
2024-03-27 02:28:21 +01:00
parent c018f54a12
commit b1e336381c
15 changed files with 426 additions and 552 deletions

View File

@@ -45,82 +45,102 @@ function showFeedback(isSuccess, options = {}, errorMessage) {
}
export async function get(path, query = {}, options = {}) {
const res = await fetch(`/api${path}${getQuery(query)}`);
const body = parse(await res.text());
try {
const res = await fetch(`/api${path}${getQuery(query)}`);
const body = parse(await res.text());
if (res.ok) {
showFeedback(true, options);
return body;
if (res.ok) {
showFeedback(true, options);
return body;
}
showFeedback(false, options, body.statusMessage);
throw new Error(body.statusMessage);
} catch (error) {
showFeedback(false, options, error.message);
throw error;
}
showFeedback(false, options, body.statusMessage);
throw new Error(body.statusMessage);
}
export async function post(path, data, options = {}) {
const res = await fetch(`/api${path}${getQuery(options.query)}`, {
method: 'POST',
body: JSON.stringify(data),
...postHeaders,
});
try {
const res = await fetch(`/api${path}${getQuery(options.query)}`, {
method: 'POST',
body: JSON.stringify(data),
...postHeaders,
});
if (res.status === 204) {
showFeedback(true, options);
return null;
if (res.status === 204) {
showFeedback(true, options);
return null;
}
const body = parse(await res.text());
if (res.ok) {
showFeedback(true, options);
return body;
}
showFeedback(false, options, body.statusMessage);
throw new Error(body.statusMessage);
} catch (error) {
showFeedback(false, options, error.message);
throw error;
}
const body = parse(await res.text());
if (res.ok) {
showFeedback(true, options);
return body;
}
showFeedback(false, options, body.statusMessage);
throw new Error(body.statusMessage);
}
export async function patch(path, data, options = {}) {
const res = await fetch(`/api${path}${getQuery(options.query)}`, {
method: 'PATCH',
body: JSON.stringify(data),
...postHeaders,
});
try {
const res = await fetch(`/api${path}${getQuery(options.query)}`, {
method: 'PATCH',
body: JSON.stringify(data),
...postHeaders,
});
if (res.status === 204) {
return null;
if (res.status === 204) {
return null;
}
const body = parse(await res.text());
if (res.ok) {
showFeedback(true, options);
return body;
}
showFeedback(false, options, body.statusMessage);
throw new Error(body.statusMessage);
} catch (error) {
showFeedback(false, options, error.message);
throw error;
}
const body = parse(await res.text());
if (res.ok) {
showFeedback(true, options);
return body;
}
showFeedback(false, options, body.statusMessage);
throw new Error(body.statusMessage);
}
export async function del(path, options = {}) {
const res = await fetch(`/api${path}${getQuery(options.query)}`, {
method: 'DELETE',
body: JSON.stringify(options.data),
...postHeaders,
});
try {
const res = await fetch(`/api${path}${getQuery(options.query)}`, {
method: 'DELETE',
body: JSON.stringify(options.data),
...postHeaders,
});
if (res.status === 204) {
showFeedback(true, options);
return null;
if (res.status === 204) {
showFeedback(true, options);
return null;
}
const body = parse(await res.text());
if (res.ok) {
showFeedback(true, options);
return body;
}
showFeedback(false, options, body.statusMessage);
throw new Error(body.statusMessage);
} catch (error) {
showFeedback(false, options, error.message);
throw error;
}
const body = parse(await res.text());
if (res.ok) {
showFeedback(true, options);
return body;
}
showFeedback(false, options, body.statusMessage);
throw new Error(body.statusMessage);
}