Added secondary stash button, centralized bookmark (heart) component.
This commit is contained in:
142
src/api.js
142
src/api.js
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user