did some more cleanup of the interface and UI interactions.
This commit is contained in:
@ -1,12 +1,13 @@
|
||||
import { createSelector, createSlice, PayloadAction } from '@reduxjs/toolkit';
|
||||
import { area_t, dimensions_t, Id, length_t, Product, ProductData } from '@/lib/product';
|
||||
import { dimensions_t, Id, Product, ProductData } from '@/lib/product';
|
||||
import uuid from "react-native-uuid";
|
||||
import { RootState } from '@/app/store';
|
||||
import { classToPlain, plainToClass } from 'class-transformer';
|
||||
import { Length } from 'convert';
|
||||
|
||||
const initialState = {
|
||||
products: [] as ProductData[],
|
||||
}
|
||||
units: "ft",
|
||||
};
|
||||
|
||||
export type UpdateAttribute = {
|
||||
product_id: Id,
|
||||
@ -30,6 +31,9 @@ const productsState = createSlice({
|
||||
name: 'products-slice',
|
||||
initialState,
|
||||
reducers: {
|
||||
setUnits(state, action : PayloadAction<Length>) {
|
||||
state.units = action.payload;
|
||||
},
|
||||
createProduct(state, action: PayloadAction<ProductData>) {
|
||||
if (!state) {
|
||||
return initialState
|
||||
@ -150,6 +154,10 @@ export const selectProductsDatas = (state: RootState) => {
|
||||
return state.products;
|
||||
}
|
||||
|
||||
export const selectUnits = (state : RootState) => {
|
||||
return (state.units || "ft") as Length;
|
||||
}
|
||||
|
||||
export const selectProducts = createSelector([selectProductsDatas], productsData => {
|
||||
return productsData.map(d => Product.fromObject(d));
|
||||
})
|
||||
@ -172,6 +180,7 @@ export const actions = {
|
||||
};
|
||||
|
||||
export const {
|
||||
setUnits,
|
||||
createProduct,
|
||||
deleteProduct,
|
||||
changeKey,
|
||||
|
Reference in New Issue
Block a user