|
@@ -3,10 +3,7 @@ import Link from "next/link";
|
|
import styled from "styled-components";
|
|
import styled from "styled-components";
|
|
import { useLocalStorage } from "usehooks-ts";
|
|
import { useLocalStorage } from "usehooks-ts";
|
|
import { FaFileImport } from "react-icons/fa";
|
|
import { FaFileImport } from "react-icons/fa";
|
|
-import {
|
|
|
|
- MdUnfoldMore,
|
|
|
|
- MdUnfoldLess,
|
|
|
|
-} from "react-icons/md";
|
|
|
|
|
|
+import { MdUnfoldMore, MdUnfoldLess } from "react-icons/md";
|
|
import {
|
|
import {
|
|
AiFillHome,
|
|
AiFillHome,
|
|
AiOutlineClear,
|
|
AiOutlineClear,
|
|
@@ -25,6 +22,7 @@ import {
|
|
import { getNextLayout } from "src/containers/LiveEditor/helpers";
|
|
import { getNextLayout } from "src/containers/LiveEditor/helpers";
|
|
import { StorageConfig } from "src/typings/global";
|
|
import { StorageConfig } from "src/typings/global";
|
|
import { CanvasDirection } from "reaflow";
|
|
import { CanvasDirection } from "reaflow";
|
|
|
|
+import { useLoading } from "src/hooks/useLoading";
|
|
|
|
|
|
const StyledSidebar = styled.div`
|
|
const StyledSidebar = styled.div`
|
|
display: flex;
|
|
display: flex;
|
|
@@ -110,6 +108,8 @@ function getLayoutIcon(layout: CanvasDirection) {
|
|
export const Sidebar: React.FC<{
|
|
export const Sidebar: React.FC<{
|
|
setJson: React.Dispatch<React.SetStateAction<string>>;
|
|
setJson: React.Dispatch<React.SetStateAction<string>>;
|
|
}> = ({ setJson }) => {
|
|
}> = ({ setJson }) => {
|
|
|
|
+ const pageLoaded = useLoading();
|
|
|
|
+
|
|
const [jsonFile, setJsonFile] = React.useState<File | null>(null);
|
|
const [jsonFile, setJsonFile] = React.useState<File | null>(null);
|
|
const [config, setConfig] = useLocalStorage<StorageConfig>("config", {
|
|
const [config, setConfig] = useLocalStorage<StorageConfig>("config", {
|
|
layout: "LEFT",
|
|
layout: "LEFT",
|
|
@@ -117,7 +117,6 @@ export const Sidebar: React.FC<{
|
|
controls: true,
|
|
controls: true,
|
|
});
|
|
});
|
|
|
|
|
|
-
|
|
|
|
const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
if (e.target.files) setJsonFile(e.target.files?.item(0));
|
|
if (e.target.files) setJsonFile(e.target.files?.item(0));
|
|
};
|
|
};
|
|
@@ -140,89 +139,92 @@ export const Sidebar: React.FC<{
|
|
}
|
|
}
|
|
}, [jsonFile, setJson]);
|
|
}, [jsonFile, setJson]);
|
|
|
|
|
|
- return (
|
|
|
|
- <StyledSidebar>
|
|
|
|
- <StyledTopWrapper>
|
|
|
|
- <Link passHref href="/">
|
|
|
|
- <StyledElement as="a">
|
|
|
|
- <StyledLogo>
|
|
|
|
- <StyledText>J</StyledText>
|
|
|
|
- <StyledText secondary>V</StyledText>
|
|
|
|
- </StyledLogo>
|
|
|
|
- </StyledElement>
|
|
|
|
- </Link>
|
|
|
|
- <StyledElement title="Home">
|
|
|
|
- <Link href="/">
|
|
|
|
- <a>
|
|
|
|
- <AiFillHome />
|
|
|
|
- </a>
|
|
|
|
|
|
+ if (pageLoaded)
|
|
|
|
+ return (
|
|
|
|
+ <StyledSidebar>
|
|
|
|
+ <StyledTopWrapper>
|
|
|
|
+ <Link passHref href="/">
|
|
|
|
+ <StyledElement as="a">
|
|
|
|
+ <StyledLogo>
|
|
|
|
+ <StyledText>J</StyledText>
|
|
|
|
+ <StyledText secondary>V</StyledText>
|
|
|
|
+ </StyledLogo>
|
|
|
|
+ </StyledElement>
|
|
</Link>
|
|
</Link>
|
|
- </StyledElement>
|
|
|
|
- <StyledElement
|
|
|
|
- as="a"
|
|
|
|
- onClick={() => {
|
|
|
|
- setJson("[]");
|
|
|
|
- localStorage.removeItem("json");
|
|
|
|
- }}
|
|
|
|
- title="Clear JSON"
|
|
|
|
- >
|
|
|
|
- <AiOutlineClear />
|
|
|
|
- </StyledElement>
|
|
|
|
- <StyledElement
|
|
|
|
- as="a"
|
|
|
|
- onClick={() =>
|
|
|
|
- setConfig((c) => ({
|
|
|
|
- ...c,
|
|
|
|
- layout: getNextLayout(c.layout),
|
|
|
|
- }))
|
|
|
|
- }
|
|
|
|
- title="Change Layout"
|
|
|
|
- >
|
|
|
|
- {getLayoutIcon(config.layout)}
|
|
|
|
- </StyledElement>
|
|
|
|
- <StyledElement
|
|
|
|
- title="Toggle Controls"
|
|
|
|
- as="a"
|
|
|
|
- onClick={() => toggle("controls")}
|
|
|
|
- >
|
|
|
|
- {config.controls ? <AiFillControl /> : <AiOutlineControl />}
|
|
|
|
- </StyledElement>
|
|
|
|
-
|
|
|
|
- <StyledElement
|
|
|
|
- as="a"
|
|
|
|
- title="Toggle Expand/Collapse"
|
|
|
|
- onClick={() => toggle("expand")}
|
|
|
|
- >
|
|
|
|
- {config.expand ? <MdUnfoldMore /> : <MdUnfoldLess />}
|
|
|
|
- </StyledElement>
|
|
|
|
- <StyledElement as="a" title="Import JSON File">
|
|
|
|
- <StyledImportFile>
|
|
|
|
- <input
|
|
|
|
- key={jsonFile?.name}
|
|
|
|
- onChange={handleFileChange}
|
|
|
|
- type="file"
|
|
|
|
- accept="application/JSON"
|
|
|
|
- />
|
|
|
|
- <FaFileImport />
|
|
|
|
- </StyledImportFile>
|
|
|
|
- </StyledElement>
|
|
|
|
- </StyledTopWrapper>
|
|
|
|
- <StyledBottomWrapper>
|
|
|
|
- <StyledElement>
|
|
|
|
- <Link href="https://twitter.com/aykutsarach">
|
|
|
|
- <a rel="me" target="_blank">
|
|
|
|
- <AiOutlineTwitter />
|
|
|
|
- </a>
|
|
|
|
- </Link>
|
|
|
|
- </StyledElement>
|
|
|
|
- <StyledElement>
|
|
|
|
- <Link href="https://github.com/AykutSarac/jsonvisio.com">
|
|
|
|
- <a rel="me" target="_blank">
|
|
|
|
- <AiFillGithub />
|
|
|
|
- </a>
|
|
|
|
- </Link>
|
|
|
|
- </StyledElement>
|
|
|
|
- </StyledBottomWrapper>
|
|
|
|
- </StyledSidebar>
|
|
|
|
- );
|
|
|
|
|
|
+ <StyledElement title="Home">
|
|
|
|
+ <Link href="/">
|
|
|
|
+ <a>
|
|
|
|
+ <AiFillHome />
|
|
|
|
+ </a>
|
|
|
|
+ </Link>
|
|
|
|
+ </StyledElement>
|
|
|
|
+ <StyledElement
|
|
|
|
+ as="a"
|
|
|
|
+ onClick={() => {
|
|
|
|
+ setJson("[]");
|
|
|
|
+ localStorage.removeItem("json");
|
|
|
|
+ }}
|
|
|
|
+ title="Clear JSON"
|
|
|
|
+ >
|
|
|
|
+ <AiOutlineClear />
|
|
|
|
+ </StyledElement>
|
|
|
|
+ <StyledElement
|
|
|
|
+ as="a"
|
|
|
|
+ onClick={() =>
|
|
|
|
+ setConfig((c) => ({
|
|
|
|
+ ...c,
|
|
|
|
+ layout: getNextLayout(c.layout),
|
|
|
|
+ }))
|
|
|
|
+ }
|
|
|
|
+ title="Change Layout"
|
|
|
|
+ >
|
|
|
|
+ {getLayoutIcon(config.layout)}
|
|
|
|
+ </StyledElement>
|
|
|
|
+ <StyledElement
|
|
|
|
+ title="Toggle Controls"
|
|
|
|
+ as="a"
|
|
|
|
+ onClick={() => toggle("controls")}
|
|
|
|
+ >
|
|
|
|
+ {config.controls ? <AiFillControl /> : <AiOutlineControl />}
|
|
|
|
+ </StyledElement>
|
|
|
|
+
|
|
|
|
+ <StyledElement
|
|
|
|
+ as="a"
|
|
|
|
+ title="Toggle Expand/Collapse"
|
|
|
|
+ onClick={() => toggle("expand")}
|
|
|
|
+ >
|
|
|
|
+ {config.expand ? <MdUnfoldMore /> : <MdUnfoldLess />}
|
|
|
|
+ </StyledElement>
|
|
|
|
+ <StyledElement as="a" title="Import JSON File">
|
|
|
|
+ <StyledImportFile>
|
|
|
|
+ <input
|
|
|
|
+ key={jsonFile?.name}
|
|
|
|
+ onChange={handleFileChange}
|
|
|
|
+ type="file"
|
|
|
|
+ accept="application/JSON"
|
|
|
|
+ />
|
|
|
|
+ <FaFileImport />
|
|
|
|
+ </StyledImportFile>
|
|
|
|
+ </StyledElement>
|
|
|
|
+ </StyledTopWrapper>
|
|
|
|
+ <StyledBottomWrapper>
|
|
|
|
+ <StyledElement>
|
|
|
|
+ <Link href="https://twitter.com/aykutsarach">
|
|
|
|
+ <a rel="me" target="_blank">
|
|
|
|
+ <AiOutlineTwitter />
|
|
|
|
+ </a>
|
|
|
|
+ </Link>
|
|
|
|
+ </StyledElement>
|
|
|
|
+ <StyledElement>
|
|
|
|
+ <Link href="https://github.com/AykutSarac/jsonvisio.com">
|
|
|
|
+ <a rel="me" target="_blank">
|
|
|
|
+ <AiFillGithub />
|
|
|
|
+ </a>
|
|
|
|
+ </Link>
|
|
|
|
+ </StyledElement>
|
|
|
|
+ </StyledBottomWrapper>
|
|
|
|
+ </StyledSidebar>
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ return null;
|
|
};
|
|
};
|