mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-22 23:53:50 +00:00
[WIP] Integrate local aggregated address search in AddressPicker
Added a `local-search` driver to support aggregated address fetching. Integrated the `getAddressesAggregated` function with `AddressPicker.vue` for dynamic search suggestions and abortable fetch requests.
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
<script setup lang="ts">
|
||||
import { Address } from "ChillMainAssets/types";
|
||||
import SearchBar from "ChillMainAssets/vuejs/AddressPicker/Component/SearchBar.vue";
|
||||
import {
|
||||
AddressAggregated,
|
||||
getAddressesAggregated,
|
||||
} from "ChillMainAssets/vuejs/AddressPicker/driver/local-search";
|
||||
import { Ref, ref } from "vue";
|
||||
|
||||
interface AddressPickerProps {
|
||||
suggestions?: Address[];
|
||||
@@ -10,14 +15,43 @@ const props = withDefaults(defineProps<AddressPickerProps>(), {
|
||||
suggestions: () => [],
|
||||
});
|
||||
|
||||
const onSearch = function (search: string) {
|
||||
const addresses: Ref<AddressAggregated[]> = ref([]);
|
||||
let abortController: null | AbortController = null;
|
||||
|
||||
const onSearch = async function (search: string): Promise<void> {
|
||||
if (null !== abortController) {
|
||||
abortController.abort();
|
||||
}
|
||||
|
||||
if ("" === search) {
|
||||
addresses.value = [];
|
||||
abortController = null;
|
||||
return;
|
||||
}
|
||||
|
||||
abortController = new AbortController();
|
||||
|
||||
console.log("onSearch", search);
|
||||
try {
|
||||
addresses.value = await getAddressesAggregated(search, abortController);
|
||||
} catch (e: unknown) {
|
||||
if (e instanceof DOMException && e.name === "AbortError") {
|
||||
console.log("search aborted for:", search);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<search-bar @search="onSearch"></search-bar>
|
||||
<p>test</p>
|
||||
<p v-for="a in addresses" :key="a.row_number">
|
||||
{{ a.street }}, positions: {{ a.positions[0] }}
|
||||
</p>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss"></style>
|
||||
|
Reference in New Issue
Block a user