diff --git a/src/shared/components/menu/DrawerMenu.tsx b/src/shared/components/menu/DrawerMenu.tsx index 8b711fc..8f7c6f6 100644 --- a/src/shared/components/menu/DrawerMenu.tsx +++ b/src/shared/components/menu/DrawerMenu.tsx @@ -63,7 +63,7 @@ const DrawerMenu = ({ return ( <> - + - -export const SelectValueSchema = z.object({ - valueId: z.string(), - valueName: z.string(), -}) - -export const SelectFilterSchema = z.object({ - id: z.string(), - name: z.string(), - defualtValueId: z.string().optional(), - multi: z.boolean(), - values: z.array(SelectValueSchema), - defaultVisible: z.boolean().optional(), - priority: z.number().optional(), - // UI controlled - visible: z.boolean().optional(), - alwaysVisible: z.boolean().optional(), -}) - -export type SelectFilter = z.infer - -export const SwitchFilterSchema = z.object({ - id: z.string(), - name: z.string(), - defualtValue: z.boolean().optional(), - defaultVisible: z.boolean().optional(), - priority: z.number().optional(), - // UI controlled - visible: z.boolean().optional(), - alwaysVisible: z.boolean().optional(), -}) - -export type SwitchStore = z.infer - -export type ServerFilter = (SwitchStore | NumberFilter | SelectFilter) \ No newline at end of file diff --git a/src/shared/stores/filters/toDel.filters.store b/src/shared/stores/filters/toDel.filters.store deleted file mode 100644 index ffb2916..0000000 --- a/src/shared/stores/filters/toDel.filters.store +++ /dev/null @@ -1,88 +0,0 @@ -import { makeAutoObservable, runInAction } from "mobx" -import { sleep } from "../../utils/async.sleep" -import { ServerFilter } from "./toDel.filters.interface" -import { addItem, removeFilter, removeItem } from "../../utils/array.helper" -import { valueIsNotEmpty } from "../../utils/any.helper" - - -export class FiltersStore { - private _filters: ServerFilter[] = [] - public get filters(): ServerFilter[] { - return this._filters - } - - private _showAll: boolean = false - public get showAll(): boolean { - return this._showAll - } - - private _isLoading = false - public get isLoading() { - return this._isLoading - } - - constructor() { - makeAutoObservable(this) - } - - updateFilters = async (categoryId: string) => { - this._isLoading = true - try { - const res = await this.fetchFiltersFromServer(categoryId) - runInAction(() => { - this._filters = res.sort((a, b) => (a.priority || 0) - (b.priority || 0)) - this.setDefaultVisible() - this._isLoading = false - }) - } catch { - this._isLoading = false - } - } - - handleChangeFilter = (id: string, value: any) => { - const changedFilter = this._filters.find(filter => filter.id === id) - if (changedFilter) { - console.log(changedFilter) - if (valueIsNotEmpty(value)) this.setFilterVisible(changedFilter, true) - // todo add send state to product store and to update products from server - } - } - - offAlwaysVisible = (id: string) => { - const changedFilter = this._filters.find(filter => filter.id === id) - if (changedFilter) { - this.setFilterVisible(changedFilter, false) - } - } - - setSpoilerVisible = (value: boolean) => { - if (value) { - this.showAllFilters() - } else { - this.setDefaultVisible() - } - } - - private setFilterVisible = (filter: ServerFilter, value: boolean) => { - this._filters = this._filters.map(item => { - if (item.id === filter.id && !item.defaultVisible) return { ...item, visible: value, alwaysVisible: value } - else return item - }) - } - - private showAllFilters = () => { - this._filters = this._filters.map(filter => ({ ...filter, visible: true })) - this._showAll = true - } - - private setDefaultVisible() { - this._filters = this._filters.map(filter => ({ ...filter, visible: filter.alwaysVisible ? filter.alwaysVisible : filter.defaultVisible })) - this._showAll = false - } - - private async fetchFiltersFromServer(categoryId: string): Promise { - await sleep(500) - return [] - } - -} \ No newline at end of file