refaktoryzacja service api.
wydzielenie mockow. dodanie parsowania wyszukiwania
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
import { computed, ref } from 'vue'
|
||||
import { acceptHMRUpdate, defineStore } from 'pinia'
|
||||
import { fetchProducts } from 'src/services/productsApi'
|
||||
import { parseOrderSearchQuery } from 'src/utils/orderSearchParser'
|
||||
|
||||
const DEFAULT_LIMIT = 30
|
||||
|
||||
function createDefaultFilters() {
|
||||
return {
|
||||
search: '',
|
||||
modelId: null,
|
||||
clientId: null,
|
||||
finish: null,
|
||||
@@ -19,6 +19,8 @@ export const useProductsStore = defineStore('products', () => {
|
||||
const ids = ref([])
|
||||
const byId = ref({})
|
||||
const filters = ref(createDefaultFilters())
|
||||
const searchQuery = ref('')
|
||||
const orderSearch = ref([])
|
||||
const limit = ref(DEFAULT_LIMIT)
|
||||
const offset = ref(0)
|
||||
const total = ref(null)
|
||||
@@ -33,7 +35,8 @@ export const useProductsStore = defineStore('products', () => {
|
||||
return {
|
||||
limit: limit.value,
|
||||
offset: offset.value,
|
||||
search: filters.value.search || undefined,
|
||||
search: searchQuery.value || undefined,
|
||||
orderSearch: orderSearch.value.length ? orderSearch.value : undefined,
|
||||
model: filters.value.modelId || undefined,
|
||||
client: filters.value.clientId || undefined,
|
||||
finish: filters.value.finish || undefined,
|
||||
@@ -95,11 +98,21 @@ export const useProductsStore = defineStore('products', () => {
|
||||
}
|
||||
}
|
||||
|
||||
function setSearchQuery(value) {
|
||||
searchQuery.value = value
|
||||
orderSearch.value = parseOrderSearchQuery(value)
|
||||
}
|
||||
|
||||
async function applyFilters(nextFilters) {
|
||||
setFilters(nextFilters)
|
||||
await fetchFirstPage()
|
||||
}
|
||||
|
||||
async function applySearch(value) {
|
||||
setSearchQuery(value)
|
||||
await fetchFirstPage()
|
||||
}
|
||||
|
||||
function updateProduct(productId, patch) {
|
||||
const current = byId.value[productId]
|
||||
|
||||
@@ -133,6 +146,8 @@ export const useProductsStore = defineStore('products', () => {
|
||||
ids,
|
||||
byId,
|
||||
filters,
|
||||
searchQuery,
|
||||
orderSearch,
|
||||
limit,
|
||||
offset,
|
||||
total,
|
||||
@@ -144,7 +159,9 @@ export const useProductsStore = defineStore('products', () => {
|
||||
fetchFirstPage,
|
||||
fetchNextPage,
|
||||
setFilters,
|
||||
setSearchQuery,
|
||||
applyFilters,
|
||||
applySearch,
|
||||
updateProduct,
|
||||
applyTimelinePreviewUpdate,
|
||||
clear,
|
||||
|
||||
Reference in New Issue
Block a user