mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-20 00:25:11 +00:00
reducer context works
This commit is contained in:
1 parent
da8bee2be9
commit
1826eeb9bf
12 files changed
+210
-50
No files matched your search
@@ -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<HTMLCanvasElement | null>(null);
|
||||
|
||||
const [timelineHeight, setTimelineHeight] = useState(260);
|
||||
// const [timelineHeight, setTimelineHeight] = useState(260);
|
||||
const timelineRef = useRef<HTMLDivElement | null>(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 (
|
||||
<div>
|
||||
<TopBarHelmet>
|
||||
<Button icon={faSparkles}>Generate Movie</Button>
|
||||
</TopBarHelmet>
|
||||
|
||||
<EngineProvider>
|
||||
<TopBarHelmet>
|
||||
<Button icon={faSparkles}>Generate Movie</Button>
|
||||
</TopBarHelmet>
|
||||
<div style={{ height: "calc(100vh - 68px)" }}>
|
||||
{/* Engine section/side panel */}
|
||||
<div
|
||||
id="CanvasUiWrapper"
|
||||
className="flex"
|
||||
// style={{ height: `calc(100% - ${timelineHeight}px)` }}
|
||||
style={{ height: `calc(100% - 260px` }}
|
||||
>
|
||||
<div className="relative w-full overflow-hidden bg-gray-400">
|
||||
<canvas
|
||||
ref={canvasRef}
|
||||
id="video-scene"
|
||||
width="1280px"
|
||||
height="720px"
|
||||
/>
|
||||
<AppUIProvider value={[pageState, dispatchPageState]} >
|
||||
<div style={{ height: "calc(100vh - 68px)" }}>
|
||||
{/* Engine section/side panel */}
|
||||
<div
|
||||
id="CanvasUiWrapper"
|
||||
className="flex"
|
||||
style={{ height: `calc(100% - ${pageState.timelineHeight}px)` }}
|
||||
// style={{ height: `calc(100% - 260px` }}
|
||||
>
|
||||
<div className="relative w-full overflow-hidden bg-gray-400">
|
||||
<canvas
|
||||
ref={canvasRef}
|
||||
id="video-scene"
|
||||
width="1280px"
|
||||
height="720px"
|
||||
className={(
|
||||
pageState.viewMode !== VIEW_MODES.EDITOR)
|
||||
? 'invisible' : ''
|
||||
}
|
||||
/>
|
||||
|
||||
{/* Top controls */}
|
||||
<div className="absolute left-0 top-0 w-full">
|
||||
<div className="grid grid-cols-3 gap-4">
|
||||
<ControlsTopButtons />
|
||||
<Controls3D />
|
||||
{/* Top controls */}
|
||||
<div className="absolute left-0 top-0 w-full">
|
||||
<div className="grid grid-cols-3 gap-4">
|
||||
<ControlsTopButtons />
|
||||
<Controls3D />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Bottom controls */}
|
||||
<div className="absolute bottom-0 left-0 w-full">
|
||||
<PreviewEngineCamera />
|
||||
<ControlsVideo />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Bottom controls */}
|
||||
<div className="absolute bottom-0 left-0 w-full">
|
||||
<PreviewWindow />
|
||||
<ControlsVideo />
|
||||
</div>
|
||||
{/* Side panel */}
|
||||
<SidePanel>
|
||||
<SidePanelTabs />
|
||||
</SidePanel>
|
||||
</div>
|
||||
|
||||
{/* Side panel */}
|
||||
<SidePanel>
|
||||
<SidePanelTabs />
|
||||
</SidePanel>
|
||||
{/* Timeline */}
|
||||
<Timeline timelineHeight={pageState.timelineHeight} />
|
||||
</div>
|
||||
|
||||
{/* Timeline */}
|
||||
<Timeline timelineHeight={timelineHeight} />
|
||||
</div>
|
||||
</AppUIProvider>
|
||||
</EngineProvider>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -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 = () => {
|
||||
|
||||
@@ -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);
|
||||
|
||||
+3
-4
@@ -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 (
|
||||
<div
|
||||
id="preview-window"
|
||||
id="preview-engine-camera"
|
||||
className="absolute bottom-0 w-30 m-4"
|
||||
>
|
||||
<div className="relative">
|
||||
<div
|
||||
id="preview-window-label"
|
||||
className="text-white bg-ui-panel pt-1 px-2 pb-3 -z-10 rounded-t-lg -mb-2 w-fit"
|
||||
>
|
||||
<p>Camera View</p>
|
||||
@@ -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<boolean>(true);
|
||||
useEffect(()=>{
|
||||
setTimeout(()=>setShowLoader(false), 5000);
|
||||
},[]);
|
||||
return (
|
||||
<div
|
||||
id="preview-stylized"
|
||||
className="absolute bottom-0 w-30 m-4"
|
||||
>
|
||||
<div className="relative">
|
||||
<div
|
||||
className="text-white bg-ui-panel pt-1 px-2 pb-3 -z-10 rounded-t-lg -mb-2 w-fit"
|
||||
>
|
||||
<label>Stylized Preview</label>
|
||||
</div>
|
||||
<div className="relative rounded-lg border border-white box overflow-hidden">
|
||||
|
||||
<img
|
||||
//shoot that datat from engine context to this image
|
||||
className="aspect-video max-h-40"
|
||||
src="/resources/uiAssets/video_player_placeholder.gif"
|
||||
/>
|
||||
<div className="absolute w-full h-full top-0 left-0">
|
||||
<LoadingDotsTyping show={showLoader} transition/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -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<string>("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(
|
||||
<>
|
||||
<H4>Select Base Style</H4>
|
||||
@@ -56,9 +71,13 @@ export const TabStyling = ()=>{
|
||||
"/>
|
||||
</div>
|
||||
<div className="flex gap-2 mt-6 justify-center">
|
||||
<Button>Preview Side by Side</Button>
|
||||
<Button onClick={handleChangeViewMode}>
|
||||
{
|
||||
pageState?.viewMode === VIEW_MODES.SIDE_BY_SIDE
|
||||
? "Back to Scene" : "Preview Side by Side"
|
||||
}
|
||||
</Button>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { createContext, Dispatch, ReactNode } from "react";
|
||||
import { State, Action } from "../reducer";
|
||||
|
||||
export const AppUiContext = createContext<[State|null, Dispatch<Action>|null]>([null,null]);
|
||||
|
||||
export const AppUIProvider = ({
|
||||
value,
|
||||
children,
|
||||
}:{
|
||||
value:[State, Dispatch<Action>],
|
||||
children: ReactNode
|
||||
})=>{
|
||||
return (
|
||||
<AppUiContext.Provider value={value}>{children}</AppUiContext.Provider>
|
||||
);
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
@@ -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,
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user