ISSUE-017 - Initial work on the Overlay Tool.
Have basic state management in place and a number of simple prototypes in place to practice floating a div above the interface.
This commit is contained in:
1 parent
110d00d7bb
commit
506491eed9
14 files changed
+265
-14
No files matched your search
@@ -0,0 +1,3 @@
|
||||
import { RootState } from "../../types/state";
|
||||
|
||||
export const overlayToolSelector = (state: RootState) => state.overlayTool;
|
||||
@@ -0,0 +1,79 @@
|
||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
|
||||
import {
|
||||
RootState,
|
||||
OverlayPosition,
|
||||
OverlayId,
|
||||
AppDimensions,
|
||||
} from "../../types/state";
|
||||
|
||||
const initialState: RootState["overlayTool"] = {
|
||||
overlayIds: [],
|
||||
currentOverlayId: null,
|
||||
currentOverlayItem: null,
|
||||
visible: false,
|
||||
};
|
||||
|
||||
const makeNewOverlayItem = (
|
||||
overlayId: OverlayId,
|
||||
appDimensions: AppDimensions,
|
||||
) => ({
|
||||
id: overlayId,
|
||||
position: {
|
||||
x: appDimensions.width / 2,
|
||||
y: appDimensions.height / 2,
|
||||
},
|
||||
opacity: 1,
|
||||
scale: 1,
|
||||
});
|
||||
|
||||
|
||||
type InitNewOverlayItemAction = {
|
||||
overlayId: OverlayId,
|
||||
appDimensions: AppDimensions,
|
||||
};
|
||||
|
||||
export const overlayToolSlice = createSlice({
|
||||
name: "overlayTool",
|
||||
initialState,
|
||||
reducers: {
|
||||
initNewOverlayItem: (state, action: PayloadAction<InitNewOverlayItemAction>) => {
|
||||
if (state.currentOverlayItem == null) {
|
||||
state.currentOverlayItem = makeNewOverlayItem(
|
||||
action.payload.overlayId,
|
||||
action.payload.appDimensions,
|
||||
);
|
||||
state.currentOverlayId = action.payload.overlayId;
|
||||
}
|
||||
},
|
||||
setVisibility: (state, action: PayloadAction<boolean>) => {
|
||||
state.visible = action.payload;
|
||||
},
|
||||
setOverlayIds: (state, action: PayloadAction<Array<OverlayId>>) => {
|
||||
state.overlayIds = action.payload;
|
||||
},
|
||||
setCurrentOverlayId: (state, action: PayloadAction<OverlayId>) => {
|
||||
if (
|
||||
action.payload !== state.currentOverlayId &&
|
||||
state.currentOverlayItem != null
|
||||
) {
|
||||
state.currentOverlayId = action.payload;
|
||||
state.currentOverlayItem.id = action.payload;
|
||||
}
|
||||
},
|
||||
setPosition: (state, action: PayloadAction<OverlayPosition>) => {
|
||||
if (state.currentOverlayItem != null) {
|
||||
state.currentOverlayItem.position = action.payload;
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const {
|
||||
initNewOverlayItem,
|
||||
setVisibility,
|
||||
setOverlayIds,
|
||||
setCurrentOverlayId,
|
||||
setPosition,
|
||||
} = overlayToolSlice.actions;
|
||||
export default overlayToolSlice.reducer;
|
||||
@@ -1,3 +1,6 @@
|
||||
import { RootState } from "../../types/state";
|
||||
|
||||
export const menuSelector = (state: RootState) => state.pageDimensions.menu;
|
||||
export const menuDimensionsSelector = (state: RootState) =>
|
||||
state.pageDimensions.menu;
|
||||
export const appDimensionsSelector = (state: RootState) =>
|
||||
state.pageDimensions.app;
|
||||
@@ -1,11 +1,15 @@
|
||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
|
||||
import { RootState, MenuDimensions } from "../../types/state";
|
||||
import { RootState, MenuDimensions, AppDimensions } from "../../types/state";
|
||||
|
||||
const initialState: RootState["pageDimensions"] = {
|
||||
menu: {
|
||||
height: 0,
|
||||
},
|
||||
app: {
|
||||
height: 0,
|
||||
width: 0,
|
||||
},
|
||||
};
|
||||
|
||||
export const pageDimensionsSlice = createSlice({
|
||||
@@ -15,8 +19,11 @@ export const pageDimensionsSlice = createSlice({
|
||||
setMenuDimensions: (state, action: PayloadAction<MenuDimensions>) => {
|
||||
state.menu = action.payload;
|
||||
},
|
||||
setAppDimensions: (state, action: PayloadAction<AppDimensions>) => {
|
||||
state.app = action.payload;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const { setMenuDimensions } = pageDimensionsSlice.actions;
|
||||
export const { setMenuDimensions, setAppDimensions } = pageDimensionsSlice.actions;
|
||||
export default pageDimensionsSlice.reducer;
|
||||
Reference in new issue
Block a user