From 1826eeb9bfc745c382a8831e620a3cf85b3e1402 Mon Sep 17 00:00:00 2001 From: wil Date: Tue, 26 Mar 2024 16:54:03 -0400 Subject: [PATCH] reducer context works --- app/pages/PageEnigma/PageEnigmaComponent.tsx | 99 +++++++++++-------- .../comps/Controls3D/Controls3D.tsx | 2 +- .../ControlsTopButtons/ControlsTopButtons.tsx | 2 +- .../index.tsx | 7 +- .../comps/PreviewStylized/index.tsx | 42 ++++++++ .../comps/SidePanelTabs/TabStyling.tsx | 25 ++++- .../PageEnigma/contexts/AppUiContext.tsx | 16 +++ .../PageEnigma}/contexts/EngineContext.tsx | 0 .../PageEnigma}/contexts/EngineProvider.tsx | 0 app/pages/PageEnigma/reducer/index.tsx | 14 +++ app/pages/PageEnigma/reducer/reducer.tsx | 22 +++++ app/pages/PageEnigma/reducer/types.tsx | 31 ++++++ 12 files changed, 210 insertions(+), 50 deletions(-) rename app/pages/PageEnigma/comps/{PreviewWindow => PreviewEngineCamera}/index.tsx (87%) create mode 100644 app/pages/PageEnigma/comps/PreviewStylized/index.tsx create mode 100644 app/pages/PageEnigma/contexts/AppUiContext.tsx rename app/{ => pages/PageEnigma}/contexts/EngineContext.tsx (100%) rename app/{ => pages/PageEnigma}/contexts/EngineProvider.tsx (100%) create mode 100644 app/pages/PageEnigma/reducer/index.tsx create mode 100644 app/pages/PageEnigma/reducer/reducer.tsx create mode 100644 app/pages/PageEnigma/reducer/types.tsx diff --git a/app/pages/PageEnigma/PageEnigmaComponent.tsx b/app/pages/PageEnigma/PageEnigmaComponent.tsx index 18c343a35f..defd5bc886 100644 --- a/app/pages/PageEnigma/PageEnigmaComponent.tsx +++ b/app/pages/PageEnigma/PageEnigmaComponent.tsx @@ -1,4 +1,4 @@ -import { useCallback, useEffect, useRef, useState } from "react"; +import { useCallback, useEffect, useRef, useReducer } from "react"; import { faSparkles } from "@fortawesome/pro-solid-svg-icons"; @@ -8,21 +8,31 @@ import { SidePanel } from "~/modules/SidePanel"; import { Controls3D } from "./comps/Controls3D"; import { ControlsTopButtons } from "./comps/ControlsTopButtons"; import { ControlsVideo } from "./comps/ControlsVideo"; -import { PreviewWindow } from "./comps/PreviewWindow"; +import { PreviewEngineCamera } from "./comps/PreviewEngineCamera"; import { Timeline } from "./comps/Timeline"; import { SidePanelTabs } from "./comps/SidePanelTabs"; -import { EngineProvider } from "~/contexts/EngineProvider"; +import { EngineProvider } from "./contexts/EngineProvider"; +import { AppUIProvider } from "./contexts/AppUiContext"; +import { reducer, initialState, ACTION_TYPES } from "./reducer"; +import { VIEW_MODES } from "./reducer/types"; export const PageEnigmaComponent = () => { + const [pageState, dispatchPageState] = useReducer(reducer, initialState); + const canvasRef = useRef(null); - const [timelineHeight, setTimelineHeight] = useState(260); + // const [timelineHeight, setTimelineHeight] = useState(260); const timelineRef = useRef(null); const updateTimelineHeight = useCallback(() => { if (timelineRef.current) { - setTimelineHeight(timelineRef.current.offsetHeight); + dispatchPageState({ + type: ACTION_TYPES.ON_TIMELINE_RESIZE, + payload: { + timelineHeight: timelineRef.current.offsetHeight + } + }) } }, []); @@ -43,50 +53,57 @@ export const PageEnigmaComponent = () => { return (
+ + + + - - - -
- {/* Engine section/side panel */} -
-
- + +
+ {/* Engine section/side panel */} +
+
+ - {/* Top controls */} -
-
- - + {/* Top controls */} +
+
+ + +
+
+ + {/* Bottom controls */} +
+ +
- {/* Bottom controls */} -
- - -
+ {/* Side panel */} + + +
- {/* Side panel */} - - - + {/* Timeline */} +
- - {/* Timeline */} - -
+
); diff --git a/app/pages/PageEnigma/comps/Controls3D/Controls3D.tsx b/app/pages/PageEnigma/comps/Controls3D/Controls3D.tsx index c36187a072..02d858ef1c 100644 --- a/app/pages/PageEnigma/comps/Controls3D/Controls3D.tsx +++ b/app/pages/PageEnigma/comps/Controls3D/Controls3D.tsx @@ -11,7 +11,7 @@ import { fa3dSphere, } from "@awesome.me/kit-fde2be5eb0/icons/kit/custom"; import { ButtonIcon, ButtonIconSelect } from "~/components"; -import { EngineContext } from "~/contexts/EngineContext"; +import { EngineContext } from "../../contexts/EngineContext"; import { useContext } from "react"; export const Controls3D = () => { diff --git a/app/pages/PageEnigma/comps/ControlsTopButtons/ControlsTopButtons.tsx b/app/pages/PageEnigma/comps/ControlsTopButtons/ControlsTopButtons.tsx index 75a5ecd93c..65af5650f3 100644 --- a/app/pages/PageEnigma/comps/ControlsTopButtons/ControlsTopButtons.tsx +++ b/app/pages/PageEnigma/comps/ControlsTopButtons/ControlsTopButtons.tsx @@ -1,7 +1,7 @@ import { useContext, useState } from "react"; import { Button, H4, Input } from "~/components"; import { ButtonDialogue } from "~/modules/ButtonDialogue"; -import { EngineContext } from "~/contexts/EngineContext"; +import { EngineContext } from "../../contexts/EngineContext"; export const ControlsTopButtons = () => { const editorEngine = useContext(EngineContext); diff --git a/app/pages/PageEnigma/comps/PreviewWindow/index.tsx b/app/pages/PageEnigma/comps/PreviewEngineCamera/index.tsx similarity index 87% rename from app/pages/PageEnigma/comps/PreviewWindow/index.tsx rename to app/pages/PageEnigma/comps/PreviewEngineCamera/index.tsx index 7704c68ecd..324a2bcad9 100644 --- a/app/pages/PageEnigma/comps/PreviewWindow/index.tsx +++ b/app/pages/PageEnigma/comps/PreviewEngineCamera/index.tsx @@ -1,8 +1,8 @@ import { useContext, useEffect, useState } from "react" -import { EngineContext } from "~/contexts/EngineContext" +import { EngineContext } from "../../contexts/EngineContext" import { LoadingDotsTyping } from "~/components"; -export const PreviewWindow = ()=>{ +export const PreviewEngineCamera = ()=>{ const editorEngine = useContext(EngineContext); //take data from egine context @@ -12,12 +12,11 @@ export const PreviewWindow = ()=>{ },[]); return (

Camera View

diff --git a/app/pages/PageEnigma/comps/PreviewStylized/index.tsx b/app/pages/PageEnigma/comps/PreviewStylized/index.tsx new file mode 100644 index 0000000000..8d852844fd --- /dev/null +++ b/app/pages/PageEnigma/comps/PreviewStylized/index.tsx @@ -0,0 +1,42 @@ +import { + // useContext, + useEffect, + useState, +} from "react" +// import { EngineContext } from "~/contexts/EngineContext" + +import { LoadingDotsTyping } from "~/components"; +export const PreviewStylized = ()=>{ + // const editorEngine = useContext(EngineContext); + //take data from egine context + + const [showLoader, setShowLoader] = useState(true); + useEffect(()=>{ + setTimeout(()=>setShowLoader(false), 5000); + },[]); + return ( +
+
+
+ +
+
+ + +
+ +
+
+
+
+ ) +} \ No newline at end of file diff --git a/app/pages/PageEnigma/comps/SidePanelTabs/TabStyling.tsx b/app/pages/PageEnigma/comps/SidePanelTabs/TabStyling.tsx index 4f289471b8..b114bb545f 100644 --- a/app/pages/PageEnigma/comps/SidePanelTabs/TabStyling.tsx +++ b/app/pages/PageEnigma/comps/SidePanelTabs/TabStyling.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react'; +import { useContext, useState } from 'react'; import { Button, @@ -7,14 +7,29 @@ import { Textarea } from "~/components" +import { AppUiContext } from '../../contexts/AppUiContext'; +import { ACTION_TYPES } from '../../reducer'; +import { VIEW_MODES } from '../../reducer/types'; export const TabStyling = ()=>{ + const [pageState, dispatchPageState] = useContext(AppUiContext); const [ selection, setSelection ] = useState("Anime"); const handlePickingStyle = (picked:string)=>{ console.log(`Picked style: ${picked}`); setSelection(picked); } + + const handleChangeViewMode = ()=>{ + if(dispatchPageState!==null) + dispatchPageState({ + type: ACTION_TYPES.ON_CHANGE_VIEW_MODE, + payload: { + viewMode: pageState?.viewMode === VIEW_MODES.SIDE_BY_SIDE + ? VIEW_MODES.EDITOR : VIEW_MODES.SIDE_BY_SIDE, + } + }) + } return( <>

Select Base Style

@@ -56,9 +71,13 @@ export const TabStyling = ()=>{ "/>
- +
); - } \ No newline at end of file diff --git a/app/pages/PageEnigma/contexts/AppUiContext.tsx b/app/pages/PageEnigma/contexts/AppUiContext.tsx new file mode 100644 index 0000000000..0544b3e844 --- /dev/null +++ b/app/pages/PageEnigma/contexts/AppUiContext.tsx @@ -0,0 +1,16 @@ +import { createContext, Dispatch, ReactNode } from "react"; +import { State, Action } from "../reducer"; + +export const AppUiContext = createContext<[State|null, Dispatch|null]>([null,null]); + +export const AppUIProvider = ({ + value, + children, +}:{ + value:[State, Dispatch], + children: ReactNode +})=>{ + return ( + {children} + ); +} \ No newline at end of file diff --git a/app/contexts/EngineContext.tsx b/app/pages/PageEnigma/contexts/EngineContext.tsx similarity index 100% rename from app/contexts/EngineContext.tsx rename to app/pages/PageEnigma/contexts/EngineContext.tsx diff --git a/app/contexts/EngineProvider.tsx b/app/pages/PageEnigma/contexts/EngineProvider.tsx similarity index 100% rename from app/contexts/EngineProvider.tsx rename to app/pages/PageEnigma/contexts/EngineProvider.tsx diff --git a/app/pages/PageEnigma/reducer/index.tsx b/app/pages/PageEnigma/reducer/index.tsx new file mode 100644 index 0000000000..8fe4585c96 --- /dev/null +++ b/app/pages/PageEnigma/reducer/index.tsx @@ -0,0 +1,14 @@ +import {State, Action, ACTION_TYPES, VIEW_MODES} from './types'; +import {reducer} from './reducer'; + +const initialState:State = { + timelineHeight: 260, + viewMode: VIEW_MODES.EDITOR +} + +export type {State, Action}; +export { + ACTION_TYPES, + initialState, + reducer, +} \ No newline at end of file diff --git a/app/pages/PageEnigma/reducer/reducer.tsx b/app/pages/PageEnigma/reducer/reducer.tsx new file mode 100644 index 0000000000..570646835b --- /dev/null +++ b/app/pages/PageEnigma/reducer/reducer.tsx @@ -0,0 +1,22 @@ +import { State, Action, ACTION_TYPES} from './types'; + +export function reducer(state: State, action: Action): State { + switch(action.type){ + case ACTION_TYPES.ON_TIMELINE_RESIZE:{ + return{ + ...state, + timelineHeight: action.payload.timelineHeight, + } + } + case ACTION_TYPES.ON_CHANGE_VIEW_MODE:{ + console.log(action); + return{ + ...state, + viewMode: action.payload.viewMode + } + } + default:{ + return state; //no change + } + }// end switch +} diff --git a/app/pages/PageEnigma/reducer/types.tsx b/app/pages/PageEnigma/reducer/types.tsx new file mode 100644 index 0000000000..ca40f25406 --- /dev/null +++ b/app/pages/PageEnigma/reducer/types.tsx @@ -0,0 +1,31 @@ +export enum VIEW_MODES { + EDITOR = 'editor', + SIDE_BY_SIDE = 'side-by-side' +}; + +type ViewModes = VIEW_MODES.EDITOR | VIEW_MODES.SIDE_BY_SIDE; + +export type State = { + viewMode: ViewModes; + timelineHeight: number +}; + + +export enum ACTION_TYPES { + ON_TIMELINE_RESIZE = "on_timeline_resize", + ON_CHANGE_VIEW_MODE = "on_change_view_mode" +}; + +export type Action = + | { + type: ACTION_TYPES.ON_TIMELINE_RESIZE, + payload: { + timelineHeight: number + } + } + | { + type: ACTION_TYPES.ON_CHANGE_VIEW_MODE, + payload: { + viewMode: ViewModes + } + }; \ No newline at end of file