Refactor into useQueryable and Search components

This commit is contained in:
BlossomiShymae
2024-10-14 18:31:36 -05:00
parent 766ec716f9
commit 793cd3e120
14 changed files with 113 additions and 165 deletions

View File

@@ -4,22 +4,12 @@ const { currentLocale } = useLocale();
const getRunes = async () => (await client.perks.listAsync({locale: currentLocale.value, version: "latest"}))
.sort((a, b) => a.id - b.id)
const query = ref("");
const runes = ref(await getRunes());
watch(currentLocale, async() => {
runes.value = await getRunes();
});
const { isNumeric } = useIsNumeric();
const filteredRunes = computed(() => {
let filtered = [];
if (isNumeric(query.value))
filtered = runes.value.filter((x) => x.id == parseInt(query.value, 10));
else
filtered = runes.value.filter((x) => x.name.toLocaleLowerCase().includes(query.value.toLocaleLowerCase()));
return filtered;
})
const { query, results } = useQueryable(runes, (x) => x.id, (x) => x.name);
</script>
<template>
@@ -29,13 +19,10 @@ const filteredRunes = computed(() => {
<Card class="d-flex justify-content-center align-items-center me-auto">
<span>{{ runes.length }} runes</span>
</Card>
<div class="input-group" style="max-width: 400px;">
<input type="text" class="form-control border-light border-opacity-25" placeholder="Search" name="Search"
v-model="query"/>
</div>
<Search v-model="query"/>
</div>
<div class="d-flex flex-column align-items-center gap-2">
<Card class="d-flex w-50 flex-column" v-for="rune in filteredRunes" :key="rune.id"
<Card class="d-flex w-50 flex-column" v-for="rune in results" :key="rune.id"
data-aos="zoom-out"
data-aos-duration="500"
style="height: fit-content;">