querystrings, get, blah
This commit is contained in:
@ -53,28 +53,27 @@ const flash = ({ type, msg }) => {
|
||||
tags = res.tags.map(t => t.tag);
|
||||
renderTags(res.tags);
|
||||
};
|
||||
|
||||
const post = async (url, data) => fetch(url, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify(data)
|
||||
|
||||
const get = async (url, data) => {
|
||||
let s = [];
|
||||
for(const [ key, val ] of Object.entries(data))
|
||||
s.push(encodeURIComponent(key) + "=" + encodeURIComponent(val));
|
||||
return (await fetch(url + "?" + s.join("&"))).json();
|
||||
};
|
||||
|
||||
const deletePost = async postid => await get("/api/v2/admin/deletepost", {
|
||||
postid: postid
|
||||
});
|
||||
|
||||
const getTags = async postid => await (await fetch("/api/v2/admin/tags/get/" + postid)).json();
|
||||
|
||||
const deletePost = async postid => await (await fetch("/api/v2/admin/deletepost/" + postid)).json();
|
||||
|
||||
const addTag = async (postid, tag) => await (await post("/api/v2/admin/tags/add", {
|
||||
const addTag = async (postid, tag) => await get("/api/v2/admin/tags/add", {
|
||||
postid: postid,
|
||||
tag: tag
|
||||
})).json();
|
||||
});
|
||||
|
||||
const deleteTag = async (postid, tagid) => await (await post("/api/v2/admin/tags/delete", {
|
||||
const deleteTag = async (postid, tagid) => await get("/api/v2/admin/tags/delete", {
|
||||
postid: postid,
|
||||
tagid: tagid
|
||||
})).json();
|
||||
});
|
||||
|
||||
const renderTags = _tags => {
|
||||
[...document.querySelectorAll("#tags > .badge")].forEach(tag => tag.parentElement.removeChild(tag));
|
||||
@ -123,7 +122,7 @@ const flash = ({ type, msg }) => {
|
||||
|
||||
let tt = null;
|
||||
let lastInput = '';
|
||||
const testList = document.querySelector('#testList');
|
||||
const testList = document.querySelector('#testlist');
|
||||
|
||||
input.addEventListener("keyup", async e => {
|
||||
if(e.key === "Enter") {
|
||||
@ -161,9 +160,9 @@ const flash = ({ type, msg }) => {
|
||||
testList.innerText = "";
|
||||
lastInput = tmptag;
|
||||
|
||||
const res = await (await post("/api/v2/admin/tags/suggest", {
|
||||
searchString: tmptag
|
||||
})).json();
|
||||
const res = await get('/api/v2/admin/tags/suggest', {
|
||||
q: tmptag
|
||||
});
|
||||
|
||||
for(const entry of res.suggestions) {
|
||||
const option = document.createElement('option');
|
||||
@ -236,7 +235,9 @@ const flash = ({ type, msg }) => {
|
||||
};
|
||||
|
||||
const toggleFavEvent = async e => {
|
||||
const res = await (await fetch(`/api/v2/admin/togglefav/${postid}`)).json();
|
||||
const res = await get('/api/v2/admin/togglefav', {
|
||||
postid: postid
|
||||
});
|
||||
if(res.success) {
|
||||
const fav = document.querySelector("svg#a_favo > use").href;
|
||||
fav.baseVal = '/s/img/iconset.svg#heart_' + (fav.baseVal.match(/heart_(regular|solid)$/)[1] == "solid" ? "regular" : "solid");
|
||||
|
Reference in New Issue
Block a user