Compare commits
No commits in common. "6d97d437a2a2cd038a1914f38a88b56a954c3c5f" and "d5e46e186ec8d099b07c64084ff90174286fa9f7" have entirely different histories.
6d97d437a2
...
d5e46e186e
File diff suppressed because one or more lines are too long
@ -7,7 +7,6 @@ use tokio::{fs::File, io::AsyncReadExt};
|
|||||||
pub struct Product {
|
pub struct Product {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub couple: Vec<String>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PRODUCTS: OnceLock<Vec<Product>> = OnceLock::new();
|
static PRODUCTS: OnceLock<Vec<Product>> = OnceLock::new();
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
import { concat, find, pluck, propEq, uniq } from "ramda";
|
import { concat, pluck, uniq } from "ramda";
|
||||||
import { create } from "zustand";
|
import { create } from "zustand";
|
||||||
|
|
||||||
interface Product {
|
interface Product {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
couple: string[];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ProductsStore {
|
interface ProductsStore {
|
||||||
@ -19,12 +18,8 @@ interface ProductsStore {
|
|||||||
export const useProductsStore = create<ProductsStore>((set, get) => ({
|
export const useProductsStore = create<ProductsStore>((set, get) => ({
|
||||||
products: [],
|
products: [],
|
||||||
selectedProducts: [],
|
selectedProducts: [],
|
||||||
append: (code: string) => {
|
append: (code: string) =>
|
||||||
const selectedProduct: Product | undefined = find(propEq(code, "id"), get().products);
|
set((state) => ({ selectedProducts: [...state.selectedProducts, code] })),
|
||||||
set((state) => ({
|
|
||||||
selectedProducts: uniq([...state.selectedProducts, code, ...(selectedProduct.couple ?? [])]),
|
|
||||||
}));
|
|
||||||
},
|
|
||||||
remove: (code: string) =>
|
remove: (code: string) =>
|
||||||
set((state) => ({ selectedProducts: state.selectedProducts.filter((item) => item !== code) })),
|
set((state) => ({ selectedProducts: state.selectedProducts.filter((item) => item !== code) })),
|
||||||
unselectAll: () => set({ selectedProducts: [] }),
|
unselectAll: () => set({ selectedProducts: [] }),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user