Skip to content

Commit

Permalink
add max results in search
Browse files Browse the repository at this point in the history
  • Loading branch information
sawich committed Dec 26, 2023
1 parent f2fef0a commit 1d9289f
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions components/items/search/suggs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ type Props = {
request: string;
};
const MAX_RESULTS = 30;
const { request } = defineProps<Props>();
const enum SelectionType {
Expand All @@ -43,6 +41,14 @@ const enum FromType {
Locale,
}
const maxResults = [
{ name: "25", count: 25, value: 0 },
{ name: "50", count: 50, value: 1 },
{ name: "75", count: 75, value: 2 },
{ name: "100", count: 100, value: 3 },
];
const selectedMaxResults = ref(0);
const method = [
{
value: SelectionType.Includes,
Expand Down Expand Up @@ -105,7 +111,7 @@ function* getItemValues(item: Item) {
const results = reactive<Items>([]);
watch(
() => [request, selectedMethod, selectedWhere],
() => [request, selectedMethod, selectedWhere, selectedMaxResults],
() => filter(items),
{ deep: true }
);
Expand All @@ -124,7 +130,7 @@ const filter = useDebounceFn((items: Items) => {
for (const value of getItemValues(item)) {
results.push(value);
if (results.length >= MAX_RESULTS) {
if (results.length >= maxResults[selectedMaxResults.value].count) {
return;
}
}
Expand Down Expand Up @@ -159,6 +165,18 @@ const filter = useDebounceFn((items: Items) => {
</ItemsSearchSelect>
</template>
</ItemsSearchSelectBadge>

<ItemsSearchSelectBadge>
<template #head> max results </template>

<template #body>
<ItemsSearchSelect v-model="selectedMaxResults">
<ItemsSearchSelectOption v-for="{ name, value } of maxResults" :value="value" :key="value">
{{ name }}
</ItemsSearchSelectOption>
</ItemsSearchSelect>
</template>
</ItemsSearchSelectBadge>
</div>
</template>

Expand Down

0 comments on commit 1d9289f

Please sign in to comment.