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