diff --git a/src/App.tsx b/src/App.tsx index 50bcbe7..bacbfa1 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -25,32 +25,32 @@ } const { - screenData, + screenState, screenActions, screenDispatch } = useScreen(projectData); const { - componentData, + componentState, componentActions, componentDispatch - } = useComponent(screenData.curScreenIndex, screenData.curScreen, screenDispatch.setScreens); + } = useComponent(screenState.curScreenIndex, screenState.curScreen, screenDispatch.setScreens); const { - tableData, + tableState, tableActions } = useTables(projectData); return (
diff --git a/src/components/editor/canvas.tsx b/src/components/editor/canvas.tsx index 790cc45..db6d646 100644 --- a/src/components/editor/canvas.tsx +++ b/src/components/editor/canvas.tsx @@ -1,4 +1,4 @@ -import type { useComponentData } from "../../hooks/useComponent"; +import type { ComponentState } from "../../hooks/useComponent"; import { useDragComponent } from "../../hooks/useDragComponent"; import { ComponentType } from "../../types/component"; import type { ButtonGeneralData, Component, TableGeneralData, TextFieldGeneralData, TextGeneralData, UIData } from "../../types/component"; @@ -84,7 +84,7 @@ } interface CanvasProps { - componentData: useComponentData + componentState: ComponentState canvasWidth: number moveComponent: (index: number, uiData: UIData) => void selectComponent: (index: number) => void @@ -92,7 +92,7 @@ } export default function Canvas({ - componentData, + componentState, canvasWidth, moveComponent, selectComponent: selectComponentGrobal, @@ -113,8 +113,8 @@ draggingSquare, onDragEnd } = useDragComponent( - componentData.selectingComponent, - componentData.selectingComponentIndex, + componentState.selectingComponent, + componentState.selectingComponentIndex, moveComponent, scale, widgetScale @@ -255,17 +255,17 @@ > {/* Canvas Content */}
- {componentData.curScreenComponents.map((component, index) => + {componentState.curScreenComponents.map((component, index) =>
{ selectComopnent(e, index) }} draggable - onDragStart={(e) => { if (componentData.selectingComponentIndex === index) onDragStart(e) }} - onDrag={(e) => { if (componentData.selectingComponentIndex === index) draggingComponent(e) }} - onDragEnd={(e) => { if (componentData.selectingComponentIndex === index) onDragEnd(e) }} + onDragStart={(e) => { if (componentState.selectingComponentIndex === index) onDragStart(e) }} + onDrag={(e) => { if (componentState.selectingComponentIndex === index) draggingComponent(e) }} + onDragEnd={(e) => { if (componentState.selectingComponentIndex === index) onDragEnd(e) }} > - {componentData.selectingComponentIndex === index ? + {componentState.selectingComponentIndex === index ?
@@ -47,7 +47,7 @@ tables: Table[] screens: Screen[] curScreenIndex: number - componentActions: useComponentActions, + componentActions: ComponentActions, } function ComponentPropertyArea({ diff --git a/src/components/property/textProperties.tsx b/src/components/property/textProperties.tsx index 5480a12..47e85f0 100644 --- a/src/components/property/textProperties.tsx +++ b/src/components/property/textProperties.tsx @@ -2,13 +2,13 @@ import { ActiveTab } from "../../constants/activeTab" import type { Component, TextComponent, TextGeneralData } from "../../types/component" import { MdEdit } from "react-icons/md" -import type { useComponentActions } from "../../hooks/useComponent" +import type { ComponentActions } from "../../hooks/useComponent" interface TextPropertyProps { component: TextComponent index: number activeTab: ActiveTab - componentActions: useComponentActions + componentActions: ComponentActions updateComponent: (index: number, component: Component) => void } diff --git a/src/components/sidebar/screenList.tsx b/src/components/sidebar/screenList.tsx index 63bdb9d..5761d7e 100644 --- a/src/components/sidebar/screenList.tsx +++ b/src/components/sidebar/screenList.tsx @@ -1,6 +1,6 @@ -import type { useComponentActions } from "../../hooks/useComponent"; -import type { useScreenActions, useScreenData } from "../../hooks/useScreen"; -import type { useTablesData } from "../../hooks/useTables"; +import type { ComponentActions } from "../../hooks/useComponent"; +import type { ScreenActions, ScreenState } from "../../hooks/useScreen"; +import type { TablesState } from "../../hooks/useTables"; import { capitalizeFirst } from "../../lib/stringUtils"; import { ComponentType } from "../../types/component" import type { ButtonComponent, Component, TextComponent, TextFieldComponent } from "../../types/component"; @@ -9,14 +9,14 @@ import { FiEdit3, FiMoreHorizontal, FiTrash2, FiX } from "react-icons/fi" interface ScreenListPorps { - screenData: useScreenData, - screenActions: useScreenActions, - componentActions: useComponentActions, - tableData: useTablesData + screenData: ScreenState, + screenActions: ScreenActions, + componentActions: ComponentActions, + tableState: TablesState selectComponent: (index: number) => void } -export function ScreenList({ screenData, screenActions, componentActions, tableData, selectComponent }: ScreenListPorps) { +export function ScreenList({ screenData, screenActions, componentActions, tableState, selectComponent }: ScreenListPorps) { const [showAddModal, setShowAddModel] = useState(false); const [editIndex, setEditIndex] = useState(-1); @@ -99,7 +99,7 @@ />} {showTemplateModal && setShowTemplateModal(false)} @@ -275,13 +275,13 @@ interface AddTemplateModalProps { close: () => void, - tableData: useTablesData, - screenData: useScreenData - screenActions: useScreenActions - componenetActions: useComponentActions + tableState: TablesState, + screenData: ScreenState + screenActions: ScreenActions + componenetActions: ComponentActions } -function AddTemplateModal({ close, tableData, screenData, screenActions, componenetActions }: AddTemplateModalProps) { +function AddTemplateModal({ close, tableState, screenData, screenActions, componenetActions }: AddTemplateModalProps) { const [type, setType] = useState<"add" | "list" | "delete" | "update" | "search" | "">(""); const [screenName, setScreenName] = useState(""); @@ -346,7 +346,7 @@
{type === "add" && void } -function AddTemplate({ tableData, componenetActions, screenName, screenActions, screenData, close }: AddTemplateProps) { +function AddTemplate({ tableState, componenetActions, screenName, screenActions, screenData, close }: AddTemplateProps) { - const tables = useMemo(() => tableData.tables, [tableData.tables]) + const tables = useMemo(() => tableState.tables, [tableState.tables]) const [selectedTableId, setSelectedTableId] = useState(""); const [successScreen, setSuccessScreen] = useState(""); diff --git a/src/components/sidebar/sidebar.tsx b/src/components/sidebar/sidebar.tsx index c5da47b..34701c0 100644 --- a/src/components/sidebar/sidebar.tsx +++ b/src/components/sidebar/sidebar.tsx @@ -7,27 +7,27 @@ import type { Dispatch, SetStateAction } from "react"; import { ComponentList } from "./componentList"; import { TableList } from "./tableList"; -import type { useScreenActions, useScreenData } from "../../hooks/useScreen"; -import type { useComponentActions, useComponentData } from "../../hooks/useComponent"; -import type { useTablesActions, useTablesData } from "../../hooks/useTables"; +import type { ScreenActions, ScreenState } from "../../hooks/useScreen"; +import type { ComponentActions, ComponentState } from "../../hooks/useComponent"; +import type { TablesActions, TablesState } from "../../hooks/useTables"; interface SidebarProps { activeTabId: string - screenData: useScreenData - screenActions: useScreenActions - componentData: useComponentData - componentActions: useComponentActions - tableData: useTablesData - tableActions: useTablesActions + screenData: ScreenState + screenActions: ScreenActions + componentState: ComponentState + componentActions: ComponentActions + tableState: TablesState + tableActions: TablesActions } export function Sidebar({ activeTabId, screenData, screenActions, - componentData, + componentState, componentActions, - tableData, + tableState, tableActions, }: SidebarProps) { @@ -42,14 +42,14 @@ screenData={screenData} screenActions={screenActions} componentActions={componentActions} - tableData={tableData} + tableState={tableState} selectComponent={componentActions.selectComponent} /> } {activeTabId === "layer" && } diff --git a/src/components/sidebar/tableList.tsx b/src/components/sidebar/tableList.tsx index a795ce0..b1d5770 100644 --- a/src/components/sidebar/tableList.tsx +++ b/src/components/sidebar/tableList.tsx @@ -1,4 +1,4 @@ -import type { useTablesActions, useTablesData } from "../../hooks/useTables"; +import type { TablesActions, TablesState } from "../../hooks/useTables"; import { DataType, translateDataType } from "../../types/table"; import type { Column, Table } from "../../types/table"; import { useMemo, useState } from "react" @@ -6,11 +6,11 @@ import { MdDeleteOutline, MdOutlineDelete, MdOutlineEdit } from "react-icons/md"; interface TalbeListProps { - tableData: useTablesData, - tableActions: useTablesActions + tableState: TablesState, + tableActions: TablesActions } -export function TableList({ tableData, tableActions }: TalbeListProps) { +export function TableList({ tableState, tableActions }: TalbeListProps) { const [showAddModal, setShowAddModal] = useState(false); const [editTableIndex, setEditTableIndex] = useState(-1); @@ -31,7 +31,7 @@
- {tableData.tables.map((table, idx) => + {tableState.tables.map((table, idx) =>
{ setEditTableIndex(idx); setShowAddModal(true) }} @@ -65,8 +65,8 @@
{showAddModal && { setEditTableIndex(-1); setShowAddModal(false) }} - tables={tableData.tables} - editTable={editTableIndex === -1 ? null : tableData.tables[editTableIndex]} + tables={tableState.tables} + editTable={editTableIndex === -1 ? null : tableState.tables[editTableIndex]} addTable={tableActions.addTable} updateTable={tableActions.updateTable} />} diff --git a/src/components/workspace.tsx b/src/components/workspace.tsx index 624f35b..08657a3 100644 --- a/src/components/workspace.tsx +++ b/src/components/workspace.tsx @@ -1,20 +1,19 @@ import { Sidebar, SidebarIcons } from "./sidebar/sidebar"; import Editor from "./editor/editor"; import Property from "./property/property"; -import type { ScreenDataAndActions } from "../hooks/useScreen"; -import type { ComponentDataAndActions } from "../hooks/useComponent"; +import type { ScreenStateAndActions } from "../hooks/useScreen"; +import type { ComponentStateAndActions } from "../hooks/useComponent"; import { useState } from "react"; -import type { TableDataAndActions } from "../hooks/useTables"; +import type { TableStateAndActions } from "../hooks/useTables"; export default function Workspace({ - screenDataAndActions, - componentDataAndActions, - tableDataAndActions + screenStateAndActions, + componentStateAndActions, + tableStateAndActions }: { - screenDataAndActions: ScreenDataAndActions, - componentDataAndActions: ComponentDataAndActions, - tableDataAndActions: TableDataAndActions - + screenStateAndActions: ScreenStateAndActions, + componentStateAndActions: ComponentStateAndActions, + tableStateAndActions: TableStateAndActions }) { @@ -29,26 +28,26 @@
diff --git a/src/hooks/useComponent.ts b/src/hooks/useComponent.ts index 2cb531e..d0e4445 100644 --- a/src/hooks/useComponent.ts +++ b/src/hooks/useComponent.ts @@ -4,7 +4,7 @@ import { useCallback, useMemo, useRef, useState } from "react"; import type { Dispatch, SetStateAction } from "react"; -export interface useComponentData { +export interface ComponentState { selectingComponent: Component | null, selectingComponentIndex: number, curScreenComponents: Component[] @@ -12,7 +12,7 @@ export type SelectComponentListenerType = (selected: Component | null) => void -export interface useComponentActions { +export interface ComponentActions { addComponent: (type: ComponentType) => void, addComponents: (components: Component[], screenId: string) => void moveComponent: (index: number, uiData: UIData) => void, @@ -24,21 +24,21 @@ activateSelectMode: () => void } -export interface useComponentDispatch { +export interface ComponentDispatch { setSelectingComponentIndex: Dispatch>, } -export interface ComponentDataAndActions { - componentData: useComponentData, - componentActions: useComponentActions, - componentDispatch: useComponentDispatch +export interface ComponentStateAndActions { + componentState: ComponentState, + componentActions: ComponentActions, + componentDispatch: ComponentDispatch } export function useComponent( curScreenIndex: number, curScreen: Screen, setScreens: Dispatch> -): ComponentDataAndActions { +): ComponentStateAndActions { const [selectingComponentIndex, setSelectingComponentIndex] = useState(-1); const [selectMode, setSelectMode] = useState(false); @@ -241,7 +241,7 @@ } return { - componentData: { + componentState: { selectingComponent, selectingComponentIndex, curScreenComponents diff --git a/src/hooks/useDragComponent.ts b/src/hooks/useDragComponent.ts index f123cc8..3bee4e9 100644 --- a/src/hooks/useDragComponent.ts +++ b/src/hooks/useDragComponent.ts @@ -25,18 +25,22 @@ const MIN_HEIGHT = 20; useEffect(() => { + // eslint-disable-next-line react-hooks/set-state-in-effect setComponentX(baseX); }, [baseX]) useEffect(() => { + // eslint-disable-next-line react-hooks/set-state-in-effect setComponentY(baseY) }, [baseY]) useEffect(() => { + // eslint-disable-next-line react-hooks/set-state-in-effect setComponentW(baseW); }, [baseW]); useEffect(() => { + // eslint-disable-next-line react-hooks/set-state-in-effect setComponentH(baseH); }, [baseH]) diff --git a/src/hooks/useScreen.ts b/src/hooks/useScreen.ts index 2ad0814..6caeb03 100644 --- a/src/hooks/useScreen.ts +++ b/src/hooks/useScreen.ts @@ -3,28 +3,28 @@ import { useMemo, useState } from "react"; import type { Dispatch, SetStateAction } from "react"; -export interface useScreenData { +export interface ScreenState { screens: Screen[], curScreenIndex: number, curScreen: Screen } -export interface useScreenActions { +export interface ScreenActions { setCurScreenIndex: (index: number) => void addScreen: (name: string) => Promise, deleteScreen: (index: number) => void, updateScreen: (index: number, name: string) => void } -export interface ScreenDataAndActions { - screenData: useScreenData, - screenActions: useScreenActions, +export interface ScreenStateAndActions { + screenState: ScreenState, + screenActions: ScreenActions, screenDispatch: { setScreens: Dispatch> } } -export function useScreen(project: Project): ScreenDataAndActions { +export function useScreen(project: Project): ScreenStateAndActions { const [screens, setScreens] = useState(project.screens); const [curScreenIndex, setCurScreenIndex] = useState(0); @@ -80,7 +80,7 @@ } return { - screenData: { + screenState: { screens, curScreenIndex, curScreen diff --git a/src/hooks/useTables.ts b/src/hooks/useTables.ts index 059b210..05ea89d 100644 --- a/src/hooks/useTables.ts +++ b/src/hooks/useTables.ts @@ -2,22 +2,22 @@ import type { Table } from "../types/table"; import { useState } from "react"; -export interface useTablesData { +export interface TablesState { tables: Table[] } -export interface useTablesActions { +export interface TablesActions { addTable: (table: Table) => void, deleteTable: (id: string) => void, updateTable: (updatedTable: Table) => void } -export interface TableDataAndActions { - tableData: useTablesData, - tableActions: useTablesActions +export interface TableStateAndActions { + tableState: TablesState, + tableActions: TablesActions } -export function useTables(project: Project): TableDataAndActions { +export function useTables(project: Project): TableStateAndActions { const [tables, setTables] = useState(project.tables); @@ -55,7 +55,7 @@ } return { - tableData: { tables }, + tableState: { tables }, tableActions: { addTable, updateTable,