fix burger
This commit is contained in:
parent
605afa4449
commit
516ee9bc5d
@ -63,7 +63,7 @@ const DrawerMenu = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Burger opened={drawerOpened} onClick={toggleDrawer} className={classes.burger} size="sm" />
|
<Burger opened={drawerOpened} onClick={toggleDrawer} className={classes.burger} size='md' ml='1rem' />
|
||||||
<Drawer
|
<Drawer
|
||||||
opened={drawerOpened}
|
opened={drawerOpened}
|
||||||
onClose={closeDrawer}
|
onClose={closeDrawer}
|
||||||
|
|||||||
@ -1,55 +0,0 @@
|
|||||||
import { z } from 'zod'
|
|
||||||
|
|
||||||
export const NumberFilterSchema = z.object({
|
|
||||||
id: z.string(),
|
|
||||||
name: z.string(),
|
|
||||||
defualtValue: z.union([
|
|
||||||
z.number().optional(),
|
|
||||||
z.tuple([z.number(), z.number()]).optional()
|
|
||||||
]),
|
|
||||||
min: z.number(),
|
|
||||||
max: z.number(),
|
|
||||||
range: z.boolean(),
|
|
||||||
defaultVisible: z.boolean().optional(),
|
|
||||||
priority: z.number().optional(),
|
|
||||||
// UI controlled
|
|
||||||
visible: z.boolean().optional(),
|
|
||||||
alwaysVisible: z.boolean().optional(),
|
|
||||||
})
|
|
||||||
|
|
||||||
export type NumberFilter = z.infer<typeof NumberFilterSchema>
|
|
||||||
|
|
||||||
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<typeof SelectFilterSchema>
|
|
||||||
|
|
||||||
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<typeof SwitchFilterSchema>
|
|
||||||
|
|
||||||
export type ServerFilter = (SwitchStore | NumberFilter | SelectFilter)
|
|
||||||
@ -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<ServerFilter[]> {
|
|
||||||
await sleep(500)
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user