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.

54 lines
1.4 KiB
JavaScript

2 years ago
export default {
setup() {
const { ref, computed } = Vue;
const pads = ref([]);
2 years ago
const currentSort = ref("date");
const currentSortDir = ref("asc");
const sortedPads = computed(() => {
return pads.value.sort((a, b) => {
let modifier = 1;
if (currentSortDir.value === "desc") modifier = -1;
if (a[currentSort.value] < b[currentSort.value]) return -1 * modifier;
if (a[currentSort.value] > b[currentSort.value]) return 1 * modifier;
return 0;
});
});
const sort = function (s) {
if (s == currentSort.value) {
currentSortDir.value = currentSortDir.value === "asc" ? "desc" : "asc";
}
currentSort.value = s;
};
2 years ago
const columns = ["title", "overview", "categories", "date"];
2 years ago
fetch("https://hub.xpub.nl/soupboat/padliography/")
2 years ago
.then((res) => res.json())
.then((data) => (pads.value = data));
2 years ago
return { pads, columns, sortedPads, sort };
2 years ago
},
template: `
<table>
<tr class="header">
2 years ago
<th v-for="column in columns" @click='sort(column)'>{{column }}</th>
2 years ago
</tr>
2 years ago
<tr v-for="(pad, index) in sortedPads" key="pad.title, index" :class="pad.category">
2 years ago
<td class="title">
<a :href="pad.link" target="_blank"> {{pad.title}} </a>
</td>
<td class="overview">{{pad.overview}}</td>
<td class="categories">{{pad.category}}</td>
<td class="date">{{pad.date}}</td>
</tr>
</table>
`,
};