diff --git a/src/App.css b/src/App.css deleted file mode 100644 index e69de29..0000000 --- a/src/App.css +++ /dev/null diff --git a/src/App.tsx b/src/App.tsx index bacbfa1..a260020 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -22,7 +22,7 @@ } ], tables: [] - } + }; const { screenState, @@ -38,19 +38,24 @@ const { tableState, - tableActions + tableActions, + tableDispatch } = useTables(projectData); return (
-
+
diff --git a/src/components/header.tsx b/src/components/header.tsx index 9f2080c..e9e4cdb 100644 --- a/src/components/header.tsx +++ b/src/components/header.tsx @@ -1,29 +1,49 @@ +import { CiImport } from 'react-icons/ci'; import { jsonExport } from '../lib/jsonExport'; import type { Project } from '../types/project'; -import { useState } from 'react'; +import { useRef, useState, type Dispatch, type SetStateAction } from 'react'; import { FaFileExport } from 'react-icons/fa'; +import type { Table } from '../types/table'; +import type { Screen } from '../types/screen'; -export default function Header({ projectData }: { projectData: Project }) { +export default function Header( + { projectData, setScreens, setTables } + : { projectData: Project, setScreens: Dispatch>, setTables: Dispatch> } +) { + const jsonInputRef = useRef(null); const [exportTypeOpen, setExportTypeOpen] = useState(false); + const [importTypeOpen, setImportTypeOpen] = useState(false); const exportJson = async () => { - // console.log(pid) - // const project = await fetch(`/api/projects/${pid}`); - // const data = await project.json(); jsonExport(projectData); + setExportTypeOpen(false); } + + const importJson = () => { + jsonInputRef.current?.click(); + } + + const handleJsonFileChange = async (event: React.ChangeEvent) => { + const file = event.target.files?.[0]; + if (!file) return; + try { + const text = await file.text(); + const json = JSON.parse(text); + setScreens(json.screens) + setTables(json.tables) + } catch (error) { + console.log(error); + alert("JSONファイルの読み込みに失敗しました"); + } + setImportTypeOpen(false); + } + return (
- {/* */}
{projectData.title}
@@ -31,7 +51,33 @@
+ {importTypeOpen && +
+
    +
  • + JSONファイル +
  • + +
+
+ } +
+
+
}
- {/* */}
diff --git a/src/hooks/useTables.ts b/src/hooks/useTables.ts index 34cf4d4..20d623b 100644 --- a/src/hooks/useTables.ts +++ b/src/hooks/useTables.ts @@ -1,6 +1,6 @@ import type { Project } from "../types/project"; import type { Table } from "../types/table"; -import { useState } from "react"; +import { useState, type Dispatch, type SetStateAction } from "react"; export interface TablesState { tables: Table[] @@ -14,7 +14,8 @@ export interface TableStateAndActions { tableState: TablesState, - tableActions: TablesActions + tableActions: TablesActions, + tableDispatch: {setTables: Dispatch>} } export function useTables(project: Project): TableStateAndActions { @@ -39,7 +40,8 @@ addTable, updateTable, deleteTable - } + }, + tableDispatch: { setTables } } } \ No newline at end of file