feat: add shareable catalog pagination

This commit is contained in:
2026-09-08 19:54:56 -04:00
parent fd6d4cf37b
commit 7e5ca1448f
6 changed files with 76 additions and 8 deletions
+12 -4
View File
@@ -2,8 +2,9 @@ import { ref, watch } from 'vue';
import { searchCatalog } from '@/services/catalog-service.js';
export function useCatalogSearch() {
const query = ref('');
export function useCatalogSearch({ initialQuery = '', initialPage = 1 } = {}) {
const query = ref(initialQuery);
const page = ref(initialPage);
const result = ref({ items: [], pagination: { page: 1, limit: 20, total: 0, totalPages: 0 } });
const isLoading = ref(false);
const error = ref(null);
@@ -15,7 +16,7 @@ export function useCatalogSearch() {
error.value = null;
try {
const nextResult = await searchCatalog({ query: query.value });
const nextResult = await searchCatalog({ query: query.value, page: page.value });
if (currentRequestId === requestId) result.value = nextResult;
} catch (requestError) {
if (currentRequestId === requestId) error.value = requestError;
@@ -25,6 +26,13 @@ export function useCatalogSearch() {
}
watch(query, load);
watch(page, load);
return { query, result, isLoading, error, load };
function goToPage(nextPage) {
if (nextPage >= 1 && nextPage <= result.value.pagination.totalPages) {
page.value = nextPage;
}
}
return { query, page, result, isLoading, error, load, goToPage };
}