|
@@ -19,6 +19,7 @@ import { ConfigActionType } from "src/reducer/reducer";
|
|
import { useConfig } from "src/hocs/config";
|
|
import { useConfig } from "src/hocs/config";
|
|
import { useRouter } from "next/router";
|
|
import { useRouter } from "next/router";
|
|
import { ImportModal } from "src/containers/ImportModal";
|
|
import { ImportModal } from "src/containers/ImportModal";
|
|
|
|
+import { ClearModal } from "src/containers/ClearModal";
|
|
|
|
|
|
const StyledSidebar = styled.div`
|
|
const StyledSidebar = styled.div`
|
|
display: flex;
|
|
display: flex;
|
|
@@ -103,18 +104,8 @@ function rotateLayout(layout: CanvasDirection) {
|
|
export const Sidebar: React.FC = () => {
|
|
export const Sidebar: React.FC = () => {
|
|
const { json, settings, dispatch } = useConfig();
|
|
const { json, settings, dispatch } = useConfig();
|
|
const router = useRouter();
|
|
const router = useRouter();
|
|
- const [jsonFile, setJsonFile] = React.useState<File | null>(null);
|
|
|
|
- const [modalVisible, setModalVisible] = React.useState(false);
|
|
|
|
-
|
|
|
|
- const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
|
|
- if (e.target.files) setJsonFile(e.target.files?.item(0));
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- const handleClear = () => {
|
|
|
|
- dispatch({ type: ConfigActionType.SET_JSON, payload: "{}" });
|
|
|
|
- localStorage.removeItem("json");
|
|
|
|
- toast.success(`Cleared JSON and removed from memory.`);
|
|
|
|
- };
|
|
|
|
|
|
+ const [uploadVisible, setUploadVisible] = React.useState(false);
|
|
|
|
+ const [clearVisible, setClearVisible] = React.useState(false);
|
|
|
|
|
|
const handleSave = () => {
|
|
const handleSave = () => {
|
|
localStorage.setItem("json", json);
|
|
localStorage.setItem("json", json);
|
|
@@ -126,24 +117,9 @@ export const Sidebar: React.FC = () => {
|
|
toast(`${settings.expand ? "Collapsed" : "Expanded"} nodes.`);
|
|
toast(`${settings.expand ? "Collapsed" : "Expanded"} nodes.`);
|
|
};
|
|
};
|
|
|
|
|
|
- React.useEffect(() => {
|
|
|
|
- if (jsonFile) {
|
|
|
|
- const reader = new FileReader();
|
|
|
|
-
|
|
|
|
- reader.readAsText(jsonFile, "UTF-8");
|
|
|
|
- reader.onload = function (data) {
|
|
|
|
- dispatch({
|
|
|
|
- type: ConfigActionType.SET_JSON,
|
|
|
|
- payload: data.target?.result as string,
|
|
|
|
- });
|
|
|
|
- };
|
|
|
|
- }
|
|
|
|
- }, [jsonFile, dispatch]);
|
|
|
|
-
|
|
|
|
return (
|
|
return (
|
|
<StyledSidebar>
|
|
<StyledSidebar>
|
|
<StyledTopWrapper>
|
|
<StyledTopWrapper>
|
|
- <ImportModal visible={modalVisible} setVisible={setModalVisible} />
|
|
|
|
<Link passHref href="/">
|
|
<Link passHref href="/">
|
|
<StyledElement onClick={() => router.push("/")}>
|
|
<StyledElement onClick={() => router.push("/")}>
|
|
<StyledLogo>
|
|
<StyledLogo>
|
|
@@ -153,7 +129,7 @@ export const Sidebar: React.FC = () => {
|
|
</StyledElement>
|
|
</StyledElement>
|
|
</Link>
|
|
</Link>
|
|
<Tooltip title="Import File">
|
|
<Tooltip title="Import File">
|
|
- <StyledElement onClick={() => setModalVisible(true)}>
|
|
|
|
|
|
+ <StyledElement onClick={() => setUploadVisible(true)}>
|
|
<AiOutlineFileAdd />
|
|
<AiOutlineFileAdd />
|
|
</StyledElement>
|
|
</StyledElement>
|
|
</Tooltip>
|
|
</Tooltip>
|
|
@@ -173,7 +149,7 @@ export const Sidebar: React.FC = () => {
|
|
</StyledElement>
|
|
</StyledElement>
|
|
</Tooltip>
|
|
</Tooltip>
|
|
<Tooltip title="Clear JSON">
|
|
<Tooltip title="Clear JSON">
|
|
- <StyledElement onClick={handleClear}>
|
|
|
|
|
|
+ <StyledElement onClick={() => setClearVisible(true)}>
|
|
<AiOutlineDelete />
|
|
<AiOutlineDelete />
|
|
</StyledElement>
|
|
</StyledElement>
|
|
</Tooltip>
|
|
</Tooltip>
|
|
@@ -206,6 +182,8 @@ export const Sidebar: React.FC = () => {
|
|
</Link>
|
|
</Link>
|
|
</StyledElement>
|
|
</StyledElement>
|
|
</StyledBottomWrapper>
|
|
</StyledBottomWrapper>
|
|
|
|
+ <ImportModal visible={uploadVisible} setVisible={setUploadVisible} />
|
|
|
|
+ <ClearModal visible={clearVisible} setVisible={setClearVisible} />
|
|
</StyledSidebar>
|
|
</StyledSidebar>
|
|
);
|
|
);
|
|
};
|
|
};
|