All files / src/entities/shape/model slice.ts

44.44% Statements 4/9
100% Branches 0/0
0% Functions 0/5
44.44% Lines 4/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51                          12x               12x                                                   12x   12x  
import { createSlice, type PayloadAction } from '@reduxjs/toolkit';
import { TOOLS } from '@/shared/constants';
 
export type ShapeType = 'rect' | 'circle';
 
export interface ShapeState {
	active: boolean;
	type: ShapeType;
	fill: string;
	stroke: string;
	thickness: number;
}
 
const initialState: ShapeState = {
	active: false,
	type: 'rect',
	fill: '#ffffff',
	stroke: '#000000',
	thickness: 2,
};
 
const shapeSlice = createSlice({
	name: TOOLS.SHAPE,
	initialState,
	reducers: {
		setShapeType(state, action: PayloadAction<ShapeType>) {
			state.type = action.payload;
		},
		setShapeFill(state, action: PayloadAction<string>) {
			state.fill = action.payload;
		},
		setShapeStroke(state, action: PayloadAction<string>) {
			state.stroke = action.payload;
		},
		setShapeThickness(state, action: PayloadAction<number>) {
			state.thickness = action.payload;
		},
		resetShapeState: () => initialState,
	},
});
 
export const {
	setShapeType,
	setShapeFill,
	setShapeStroke,
	setShapeThickness,
	resetShapeState,
} = shapeSlice.actions;
 
export const shapeReducer = shapeSlice.reducer;