diff --git a/src/components/sidebar/componentList.tsx b/src/components/sidebar/componentList.tsx
index 1cfed9c..ab743ff 100644
--- a/src/components/sidebar/componentList.tsx
+++ b/src/components/sidebar/componentList.tsx
@@ -2,6 +2,9 @@
import type { Component } from "../../types/component"
import { FiEdit3, FiGrid, FiSquare, FiType } from "react-icons/fi";
import { FaTrash } from "react-icons/fa";
+import { useContext } from "react";
+import { ProjectContext } from "../../hooks/useProject";
+import { CurrentScreenContext } from "../../hooks/useCurrentScreen";
function IconComponent({ type, size }: { type: ComponentType, size: number }) {
switch (type) {
@@ -23,7 +26,7 @@
isSelecting: boolean
index: number
selectComponent: (index: number) => void
- deleteComponent: (index: number, compoenntId: string) => void
+ deleteComponent: (screenId: string, compoenntId: string) => void
}
function ComponentItem({ component, isSelecting, index, selectComponent, deleteComponent }: ComponentItemProps) {
@@ -36,7 +39,7 @@
const deleteHandler = (e: React.MouseEvent) => {
e.stopPropagation()
selectComponent(-1);
- deleteComponent(index, component.id);
+ deleteComponent(component.screenId, component.id);
}
return (
@@ -65,20 +68,16 @@
)
}
-interface ComponentListProps {
- components: Component[],
- selectingComponentIndex: number,
- selectComponent: (index: number) => void
- resetSelectingComponent: () => void
- deleteComponent: (componentIndex: number, compoenntId: string) => void
-}
+export function ComponentList() {
-export function ComponentList({
- components,
- selectingComponentIndex,
- selectComponent,
- deleteComponent
-}: ComponentListProps) {
+ const projectContext = useContext(ProjectContext);
+ const curScreenContext = useContext(CurrentScreenContext);
+
+ if (projectContext === null || curScreenContext === null) return
loading...
+
+ const projectActions = projectContext.projectActions;
+ const curScreenStates = curScreenContext.curScreenStates;
+ const curScreenActions = curScreenContext.curScreenActions;
return (
@@ -87,14 +86,14 @@
コンポーネント
- {components.length}
+ {curScreenStates.curScreenComponents.length}
- {components.length === 0 ? (
+ {curScreenStates.curScreenComponents.length === 0 ? (
@@ -103,14 +102,14 @@
) : (
- {components.map((item, index) => (
+ {curScreenStates.curScreenComponents.map((item, index) => (
))}
diff --git a/src/components/sidebar/screenList.tsx b/src/components/sidebar/screenList.tsx
index e8ab75d..a4384f8 100644
--- a/src/components/sidebar/screenList.tsx
+++ b/src/components/sidebar/screenList.tsx
@@ -1,22 +1,17 @@
-import type { ComponentActions } from "../../hooks/useComponent";
-import type { ScreenActions, ScreenState } from "../../hooks/useScreen";
-import type { TablesState } from "../../hooks/useTables";
+import { CurrentScreenContext } from "../../hooks/useCurrentScreen";
+import { ProjectContext } from "../../hooks/useProject";
import { capitalizeFirst } from "../../lib/stringUtils";
import { ComponentType } from "../../types/component"
import type { ButtonComponent, Component, TextComponent, TextFieldComponent } from "../../types/component";
import type { Screen } from "../../types/screen"
-import { useState } from "react";
+import { useContext, useState } from "react";
import { FiEdit3, FiMoreHorizontal, FiTrash2, FiX } from "react-icons/fi"
-interface ScreenListPorps {
- screenState: ScreenState,
- screenActions: ScreenActions,
- componentActions: ComponentActions,
- tableState: TablesState
- selectComponent: (index: number) => void
-}
-export function ScreenList({ screenState, screenActions, componentActions, tableState, selectComponent }: ScreenListPorps) {
+export function ScreenList() {
+
+ const projectContext = useContext(ProjectContext);
+ const curScreenContext = useContext(CurrentScreenContext);
const [showAddModal, setShowAddModel] = useState(false);
const [editIndex, setEditIndex] = useState(-1);
@@ -40,6 +35,12 @@
setShowAddModel(true);
}
+ if (projectContext === null || curScreenContext === null) return
loading...
+
+ const screens = projectContext.projectStates.screens;
+ const projectActions = projectContext.projectActions;
+ const curScreenState = curScreenContext.curScreenStates;
+ const curScreenActions = curScreenContext.curScreenActions;
return (
@@ -48,20 +49,20 @@
- {screenState.screens.map((screen, index) => (
+ {screens.map((screen, index) => (
))}
@@ -91,17 +92,14 @@
)}
{showAddModal &&
setShowAddModel(false)}
- addScreen={screenActions.addScreen}
+ screen={screens[editIndex]}
+ addScreen={projectActions.addScreen}
editIndex={editIndex}
editName={editName}
- selectComponent={selectComponent}
- updateScreen={screenActions.updateScreen}
+ selectComponent={curScreenActions.selectComponent}
+ updateScreen={projectActions.updateScreen}
/>}
{showTemplateModal && setShowTemplateModal(false)}
/>}
@@ -117,7 +115,7 @@
setActiveDropdown: (index: number) => void,
isLast: boolean,
closeDropdown: () => void,
- deleteScreen: (index: number) => void,
+ deleteScreen: (screenId: string) => void,
startEdit: (index: number, curName: string) => void
selectComponent: (index: number) => void
}
@@ -145,8 +143,8 @@
startEdit(index, name)
closeDropdown()
};
- const handleDeleteAction = (index: number) => {
- deleteScreen(index);
+ const handleDeleteAction = () => {
+ deleteScreen(screen.id);
closeDropdown()
};
@@ -182,7 +180,7 @@
<>
{type === "add" &&
}
@@ -359,20 +350,26 @@
}
interface AddTemplateProps {
- tableState: TablesState,
- componenetActions: ComponentActions,
- screenState: ScreenState,
- screenActions: ScreenActions
screenName: string
close: () => void
}
-function AddTemplate({ tableState, componenetActions, screenName, screenActions, screenState, close }: AddTemplateProps) {
+function AddTemplate({ screenName, close }: AddTemplateProps) {
- const tables = tableState.tables;
+ const projectContext = useContext(ProjectContext);
+ const curScreenContext = useContext(CurrentScreenContext);
+
const [selectedTableId, setSelectedTableId] = useState("");
const [successScreen, setSuccessScreen] = useState("");
+ if (projectContext === null || curScreenContext === null) return
loading...
+
+ const tables = projectContext.projectStates.tables;
+ const projectActions = projectContext.projectActions;
+ const projectStates = projectContext.projectStates;
+ const curScreenActions = curScreenContext.curScreenActions;
+
+
const confirm = async () => {
const MARGIN_X = 50;
const COLUMN_MARGIN_Y = 20;
@@ -382,8 +379,8 @@
const INPUT_WIDTH = 650;
const INPUT_HEIGHT = 40;
- const screenId = await screenActions.addScreen(screenName);
- componenetActions.selectComponent(-1);
+ const screenId = projectActions.addScreen(screenName);
+ curScreenActions.selectComponent(-1);
const table = tables.find((table) => table.id === selectedTableId);
const actionData: { [key: string]: string } = {};
const components: Component[] = [];
@@ -485,7 +482,7 @@
}
components.push(confirmButton);
components.push(backButton)
- componenetActions.addComponents(components, screenId);
+ projectActions.addComponents(screenId, components);
close();
}
@@ -515,7 +512,7 @@
>
- {screenState.screens.map((screen, idx) => (
+ {projectStates.screens.map((screen, idx) => (
diff --git a/src/components/sidebar/sidebar.tsx b/src/components/sidebar/sidebar.tsx
index 2a835e1..5ebaa66 100644
--- a/src/components/sidebar/sidebar.tsx
+++ b/src/components/sidebar/sidebar.tsx
@@ -7,28 +7,13 @@
import type { Dispatch, SetStateAction } from "react";
import { ComponentList } from "./componentList";
import { TableList } from "./tableList";
-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
- screenState: ScreenState
- screenActions: ScreenActions
- componentState: ComponentState
- componentActions: ComponentActions
- tableState: TablesState
- tableActions: TablesActions
}
export function Sidebar({
activeTabId,
- screenState,
- screenActions,
- componentState,
- componentActions,
- tableState,
- tableActions,
}: SidebarProps) {
return (
@@ -38,33 +23,16 @@
>
{activeTabId === "screens" &&
-
+
}
{activeTabId === "layer" &&
-
+
}
{activeTabId === "components" &&
-
+
}
{activeTabId === "tables" &&
-
+
}
diff --git a/src/components/sidebar/tableList.tsx b/src/components/sidebar/tableList.tsx
index 0256100..7b1b256 100644
--- a/src/components/sidebar/tableList.tsx
+++ b/src/components/sidebar/tableList.tsx
@@ -1,27 +1,31 @@
-import type { TablesActions, TablesState } from "../../hooks/useTables";
-import { DataType, translateDataType } from "../../types/table";
+import { DataType, translateDataType } from "../../types/table";
import type { Column, Table } from "../../types/table";
-import { useState } from "react"
+import { useContext, useState } from "react"
import { FiX } from "react-icons/fi";
import { MdDeleteOutline, MdOutlineDelete, MdOutlineEdit } from "react-icons/md";
+import { ProjectContext } from "../../hooks/useProject";
+import { CurrentScreenContext } from "../../hooks/useCurrentScreen";
-interface TalbeListProps {
- tableState: TablesState,
- tableActions: TablesActions
-}
-
-export function TableList({ tableState, tableActions }: TalbeListProps) {
+export function TableList() {
const [showAddModal, setShowAddModal] = useState