feat: add public catalog web foundation
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { ref, watch } from 'vue';
|
||||
|
||||
import { searchCatalog } from '@/services/catalog-service.js';
|
||||
|
||||
export function useCatalogSearch() {
|
||||
const query = ref('');
|
||||
const result = ref({ items: [], pagination: { page: 1, limit: 20, total: 0, totalPages: 0 } });
|
||||
const isLoading = ref(false);
|
||||
const error = ref(null);
|
||||
let requestId = 0;
|
||||
|
||||
async function load() {
|
||||
const currentRequestId = ++requestId;
|
||||
isLoading.value = true;
|
||||
error.value = null;
|
||||
|
||||
try {
|
||||
const nextResult = await searchCatalog({ query: query.value });
|
||||
if (currentRequestId === requestId) result.value = nextResult;
|
||||
} catch (requestError) {
|
||||
if (currentRequestId === requestId) error.value = requestError;
|
||||
} finally {
|
||||
if (currentRequestId === requestId) isLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
watch(query, load);
|
||||
|
||||
return { query, result, isLoading, error, load };
|
||||
}
|
||||
Reference in New Issue
Block a user