mirror of
https://github.com/BlossomiShymae/clean-cuts.git
synced 2025-12-06 10:10:47 +01:00
Refactor into useQueryable and Search components
This commit is contained in:
@@ -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;">
|
||||
|
||||
Reference in New Issue
Block a user