working filters

master
km0 2 years ago
parent 8b0e338e70
commit c745d9f6fd

@ -1,6 +1,6 @@
export default { export default {
setup() { setup() {
const { ref, computed } = Vue; const { ref, computed, watch } = Vue;
const currentPage = ref(""); const currentPage = ref("");
const pads = ref([]); const pads = ref([]);
@ -10,9 +10,14 @@ export default {
const currentSortDir = ref("desc"); const currentSortDir = ref("desc");
const tags = ref([]); const tags = ref([]);
const selected = ref(new Set());
const toggle = function (tag) {
selected.value.has(tag) ? selected.value.delete(tag) : selected.value.add(tag);
};
const sortedPads = computed(() => { const sortedPads = computed(() => {
return pads.value.sort((a, b) => { return filteredPads.value.sort((a, b) => {
let modifier = 1; let modifier = 1;
if (currentSortDir.value === "desc") modifier = -1; if (currentSortDir.value === "desc") modifier = -1;
@ -28,6 +33,14 @@ export default {
}); });
}); });
const filteredPads = computed(() => {
if (selected.value.size == 0) return pads.value;
else
return pads.value.filter((pad) => {
return pad.categories.some((category) => selected.value.has(category));
});
});
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
@ -67,11 +80,14 @@ export default {
pads, pads,
columns, columns,
sortedPads, sortedPads,
filteredPads,
currentPage, currentPage,
currentSort, currentSort,
currentSortDir, currentSortDir,
loaded, loaded,
tags, tags,
selected,
toggle,
sort, sort,
formatDate, formatDate,
}; };
@ -88,7 +104,8 @@ export default {
<div class="filter"> <div class="filter">
<h2>Filter Categories</h2> <h2>Filter Categories</h2>
<ul> <ul>
<li v-for="tag in tags" :key="tag">{{tag}}</li> <li :class="{active: selected.size == 0}" @click="selected.clear()">All</li>
<li v-for="tag in tags" :key="tag" @click="toggle(tag)" :class="{active: selected.has(tag)}">{{tag}}</li>
</ul> </ul>
</div> </div>

@ -1,6 +1,6 @@
:root { :root {
--bg: #000000; --bg: dodgerblue;
--color: dodgerblue; --color: white;
} }
* { * {
@ -182,6 +182,13 @@ tr:hover:not(:first-of-type) {
display: inline-block; display: inline-block;
border: 1px solid currentColor; border: 1px solid currentColor;
padding: 0 4px; padding: 0 4px;
user-select: none;
cursor: pointer;
}
.filter .active {
background-color: var(--color);
color: var(--bg);
} }
tr { tr {

Loading…
Cancel
Save