Anul 3 Semestrul 1
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
export type Drug = {
|
||||
id: number;
|
||||
name: string;
|
||||
category: string;
|
||||
price: number;
|
||||
numberOfUnits: number;
|
||||
manufacturer: string;
|
||||
}
|
||||
|
||||
export type DrugState = {
|
||||
drugList: Drug[];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
import { Drug, DrugState } from "./drug";
|
||||
import { get } from "react-native/Libraries/TurboModule/TurboModuleRegistry";
|
||||
import { initDB, insertDrug } from "@/database/localdb";
|
||||
|
||||
|
||||
const initialState: DrugState = {
|
||||
drugList: [],
|
||||
};
|
||||
|
||||
|
||||
export const drugSlice = createSlice({
|
||||
name: "drug",
|
||||
initialState,
|
||||
reducers: {
|
||||
addDrug: (state, action: PayloadAction<Drug>) => {
|
||||
state.drugList.push(action.payload);
|
||||
},
|
||||
removeDrug: (state, action: PayloadAction<number>) => {
|
||||
console.log("Removing drug with id: ", action.payload);
|
||||
state.drugList = state.drugList.filter(drug => drug.id !== action.payload);
|
||||
},
|
||||
updateDrug: (state, action: PayloadAction<Drug>) => {
|
||||
console.log("Updating drug with id: ", action.payload.id);
|
||||
console.log(action.payload);
|
||||
const index = state.drugList.findIndex(drug => drug.id === action.payload.id);
|
||||
if (index !== -1) {
|
||||
state.drugList[index] = action.payload;
|
||||
}
|
||||
console.log(state.drugList);
|
||||
},
|
||||
fetchDrugs: (state, action: PayloadAction<Drug[]>) => {
|
||||
state.drugList = action.payload;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
export const { addDrug, removeDrug, updateDrug, fetchDrugs } = drugSlice.actions
|
||||
export default drugSlice.reducer
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
export type ErrorStatus = {
|
||||
status: boolean,
|
||||
message: string
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
import { ErrorStatus } from "./errorStatus";
|
||||
|
||||
|
||||
export const errorStatusSlice = createSlice({
|
||||
name: "status",
|
||||
initialState: { status: false, message: "" } as ErrorStatus,
|
||||
reducers: {
|
||||
setErrorStatus: (state, action: PayloadAction<ErrorStatus>) => {
|
||||
state.status = action.payload.status;
|
||||
state.message = action.payload.message;
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
export const { setErrorStatus } = errorStatusSlice.actions
|
||||
export default errorStatusSlice.reducer
|
||||
@@ -0,0 +1,5 @@
|
||||
export type Status = {
|
||||
isOnline: boolean;
|
||||
isConnected: boolean;
|
||||
}
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
import { Status } from "./status";
|
||||
|
||||
|
||||
export const statusSlice = createSlice({
|
||||
name: "status",
|
||||
initialState: { isOnline: false, isConnected: false } as Status,
|
||||
reducers: {
|
||||
setOnline: (state, action: PayloadAction<boolean>) => {
|
||||
state.isOnline = action.payload;
|
||||
},
|
||||
setConnected: (state, action: PayloadAction<boolean>) => {
|
||||
state.isConnected = action.payload;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export const { setOnline, setConnected } = statusSlice.actions
|
||||
export default statusSlice.reducer
|
||||
Reference in New Issue
Block a user