preview pad

master
km0 2 years ago
parent aa56e70fc0
commit cf5aaf14ce

@ -1,3 +1,5 @@
import { PadStore } from "./PadStore.js";
export default { export default {
setup() { setup() {
const { ref, computed } = Vue; const { ref, computed } = Vue;
@ -25,16 +27,21 @@ export default {
link.value = newPad(); link.value = newPad();
} }
const pad = {
title: title.value.trim(),
link: link.value,
overview: overview.value,
categories: categories.value,
date: date.value,
};
PadStore.value.unshift(pad);
pad.categories.join(", ");
fetch("api", { fetch("api", {
method: "POST", method: "POST",
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
body: JSON.stringify({ body: JSON.stringify(pad),
title: title.value.trim(),
link: link.value,
overview: overview.value,
categories: categories.value.join(", "),
date: date.value,
}),
}); });
sent.value = true; sent.value = true;
@ -45,7 +52,18 @@ export default {
date.value = null; date.value = null;
}; };
return { title, link, overview, categories, date, submit, newPad, sent, disabled }; return {
title,
link,
overview,
categories,
date,
submit,
newPad,
sent,
disabled,
PadStore,
};
}, },
template: ` template: `
@ -61,6 +79,7 @@ export default {
<input class='date' type="date" v-model="date" placeholder="Date" /> <input class='date' type="date" v-model="date" placeholder="Date" />
<button @click="submit" class="submit">Insert</button> <button @click="submit" class="submit">Insert</button>
</div> </div>

@ -0,0 +1,3 @@
const { ref } = Vue;
export const PadStore = ref([]);

@ -1,3 +1,5 @@
import { PadStore } from "./PadStore.js";
export default { export default {
setup() { setup() {
const { ref, computed } = Vue; const { ref, computed } = Vue;
@ -61,13 +63,17 @@ export default {
}; };
const filteredPads = computed(() => { const filteredPads = computed(() => {
if (selected.value.size == 0) return pads.value; if (selected.value.size == 0) return storedPads.value;
else else
return pads.value.filter((pad) => { return storedPads.value.filter((pad) => {
return pad.categories.some((category) => selected.value.has(category)); return pad.categories.some((category) => selected.value.has(category));
}); });
}); });
const storedPads = computed(() => {
return [...PadStore.value, ...pads.value];
});
const formatDate = function (date) { const formatDate = function (date) {
return `${String(date.getDate()).padStart(2, "0")}-${String( return `${String(date.getDate()).padStart(2, "0")}-${String(
date.getMonth() + 1 date.getMonth() + 1
@ -88,6 +94,8 @@ export default {
toggle, toggle,
sort, sort,
formatDate, formatDate,
PadStore,
storedPads,
}; };
}, },
template: ` template: `
@ -112,6 +120,7 @@ export default {
</p> </p>
<table> <table>
<tr class="header"> <tr class="header">
<th v-for="column in columns" :class="column" @click='sort(column)'> <th v-for="column in columns" :class="column" @click='sort(column)'>

Loading…
Cancel
Save