| 1 | import { useReducer } from "react"; |
| 2 | import type { BasicFilters, CurveChannel, CurvePoint, FilterState } from "./lib/types"; |
| 3 | import { DEFAULT_FILTER_STATE } from "./lib/types"; |
| 4 | import { CameraView } from "./components/CameraView"; |
| 5 | import { ControlPanel } from "./components/ControlPanel"; |
| 6 | import { FullscreenButton } from "./components/FullscreenButton"; |
| 7 | import "./App.css"; |
| 8 | |
| 9 | type Action = |
| 10 | | { type: "SET_BASIC"; key: keyof BasicFilters; value: number } |
| 11 | | { type: "SET_CURVE"; channel: CurveChannel; points: CurvePoint[] } |
| 12 | | { type: "SET_ALL"; state: FilterState } |
| 13 | | { type: "RESET" }; |
| 14 | |
| 15 | function reducer(state: FilterState, action: Action): FilterState { |
| 16 | switch (action.type) { |
| 17 | case "SET_BASIC": |
| 18 | return { ...state, basic: { ...state.basic, [action.key]: action.value } }; |
| 19 | case "SET_CURVE": |
| 20 | return { ...state, curves: { ...state.curves, [action.channel]: action.points } }; |
| 21 | case "SET_ALL": |
| 22 | return action.state; |
| 23 | case "RESET": |
| 24 | return { ...DEFAULT_FILTER_STATE }; |
| 25 | default: |
| 26 | return state; |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | function App() { |
| 31 | const [filterState, dispatch] = useReducer(reducer, DEFAULT_FILTER_STATE); |
| 32 | |
| 33 | return ( |
| 34 | <div className="app"> |
| 35 | <CameraView filterState={filterState} /> |
| 36 | <FullscreenButton /> |
| 37 | <ControlPanel |
| 38 | filterState={filterState} |
| 39 | onBasicChange={(key, value) => dispatch({ type: "SET_BASIC", key, value })} |
| 40 | onCurveChange={(channel, points) => dispatch({ type: "SET_CURVE", channel, points })} |
| 41 | onSetAll={(state: FilterState) => dispatch({ type: "SET_ALL", state })} |
| 42 | onReset={() => dispatch({ type: "RESET" })} |
| 43 | /> |
| 44 | </div> |
| 45 | ); |
| 46 | } |
| 47 | |
| 48 | export default App; |