You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
2.1 KiB
JavaScript

2 years ago
import padliographyStore from "./PadStore.js";
2 years ago
3 years ago
export default {
setup() {
const { ref, computed } = Vue;
const title = ref("");
const link = ref("");
const overview = ref("");
const categories = ref([""]);
const date = ref(null);
2 years ago
const { padStore, currentPage, baseUrl } = padliographyStore();
2 years ago
3 years ago
const sent = ref(false);
const disabled = computed(() => {
return [title, overview, overview, categories].some((input) => input.value == "");
});
2 years ago
const newPad = function () {
let name = title.value.trim().replaceAll(" ", "_");
let url = `https://pad.xpub.nl/p/${name}`;
window.open(url);
return url;
};
3 years ago
const submit = function () {
2 years ago
if (link.value == "") {
link.value = newPad();
}
2 years ago
const pad = {
title: title.value.trim(),
link: link.value,
overview: overview.value,
categories: categories.value,
date: date.value,
};
2 years ago
padStore.value.unshift(pad);
2 years ago
pad.categories = pad.categories.join(", ");
2 years ago
2 years ago
fetch(`${baseUrl.value}/api/${currentPage.value}/`, {
3 years ago
method: "POST",
headers: { "Content-Type": "application/json" },
2 years ago
body: JSON.stringify(pad),
3 years ago
});
sent.value = true;
title.value = "";
link.value = "";
overview.value = "";
categories.value = [""];
date.value = null;
};
2 years ago
return {
title,
link,
overview,
categories,
date,
submit,
newPad,
sent,
disabled,
2 years ago
padStore,
2 years ago
};
3 years ago
},
template: `
<div class='app-form'>
<h2>Add a new pad</h2>
<input class='title' type="text" v-model="title" placeholder="Title" />
<input class='link' type="text" v-model="link" placeholder="URL" />
3 years ago
<input class='overview' type="text" v-model="overview" placeholder="Overview" />
<input class='categories' type="text" v-model="categories[index]" placeholder="Category" v-for="(category, index) in categories" :key="index"/>
3 years ago
<button class="add" @click="categories.push('')">+</button>
<input class='date' type="date" v-model="date" placeholder="Date" />
3 years ago
<button @click="submit" class="submit">Insert</button>
3 years ago
</div>
`,
};