|
@@ -1,29 +1,22 @@
|
|
import React from "react";
|
|
import React from "react";
|
|
|
|
+import toast from "react-hot-toast";
|
|
import Link from "next/link";
|
|
import Link from "next/link";
|
|
import styled from "styled-components";
|
|
import styled from "styled-components";
|
|
-import { FaFileImport } from "react-icons/fa";
|
|
|
|
-import {
|
|
|
|
- MdUnfoldMore,
|
|
|
|
- MdUnfoldLess,
|
|
|
|
- MdAutoFixHigh,
|
|
|
|
- MdOutlineAutoFixOff,
|
|
|
|
-} from "react-icons/md";
|
|
|
|
|
|
+import { CanvasDirection } from "reaflow";
|
|
|
|
+import { TiFlowMerge } from "react-icons/ti";
|
|
|
|
+import { BsList } from "react-icons/bs";
|
|
|
|
+import { MdUploadFile } from "react-icons/md";
|
|
|
|
+import { RiPatreonFill } from "react-icons/ri";
|
|
|
|
+import { CgArrowsMergeAltH, CgArrowsShrinkH } from "react-icons/cg";
|
|
import {
|
|
import {
|
|
- AiFillHome,
|
|
|
|
- AiFillDelete,
|
|
|
|
|
|
+ AiOutlineDelete,
|
|
AiFillGithub,
|
|
AiFillGithub,
|
|
AiOutlineTwitter,
|
|
AiOutlineTwitter,
|
|
|
|
+ AiOutlineSave,
|
|
|
|
+ AiOutlineFileAdd,
|
|
} from "react-icons/ai";
|
|
} from "react-icons/ai";
|
|
-import {
|
|
|
|
- CgArrowLongDownE,
|
|
|
|
- CgArrowLongLeftE,
|
|
|
|
- CgArrowLongRightE,
|
|
|
|
- CgArrowLongUpE,
|
|
|
|
-} from "react-icons/cg";
|
|
|
|
|
|
|
|
-import { CanvasDirection } from "reaflow";
|
|
|
|
-import toast from "react-hot-toast";
|
|
|
|
-import { Tooltip } from "../Tooltip";
|
|
|
|
|
|
+import { Tooltip } from "src/components/Tooltip";
|
|
import { ConfigActionType } from "src/reducer/reducer";
|
|
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";
|
|
@@ -33,7 +26,7 @@ const StyledSidebar = styled.div`
|
|
justify-content: space-between;
|
|
justify-content: space-between;
|
|
flex-direction: column;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
align-items: center;
|
|
- width: 42px;
|
|
|
|
|
|
+ width: 36px;
|
|
background: ${({ theme }) => theme.BACKGROUND_TERTIARY};
|
|
background: ${({ theme }) => theme.BACKGROUND_TERTIARY};
|
|
padding: 8px;
|
|
padding: 8px;
|
|
border-right: 1px solid ${({ theme }) => theme.BACKGROUND_MODIFIER_ACCENT};
|
|
border-right: 1px solid ${({ theme }) => theme.BACKGROUND_MODIFIER_ACCENT};
|
|
@@ -64,6 +57,10 @@ const StyledText = styled.span<{ secondary?: boolean }>`
|
|
secondary ? theme.INTERACTIVE_NORMAL : theme.ORANGE};
|
|
secondary ? theme.INTERACTIVE_NORMAL : theme.ORANGE};
|
|
`;
|
|
`;
|
|
|
|
|
|
|
|
+const StyledFlowIcon = styled(TiFlowMerge)<{ rotate: number }>`
|
|
|
|
+ transform: rotate(${({ rotate }) => `${rotate}deg`});
|
|
|
|
+`;
|
|
|
|
+
|
|
const StyledTopWrapper = styled.nav`
|
|
const StyledTopWrapper = styled.nav`
|
|
display: flex;
|
|
display: flex;
|
|
justify-content: space-between;
|
|
justify-content: space-between;
|
|
@@ -101,15 +98,15 @@ const StyledImportFile = styled.label`
|
|
}
|
|
}
|
|
`;
|
|
`;
|
|
|
|
|
|
-function getLayoutIcon(layout: CanvasDirection) {
|
|
|
|
- if (layout === "LEFT") return <CgArrowLongLeftE />;
|
|
|
|
- if (layout === "UP") return <CgArrowLongUpE />;
|
|
|
|
- if (layout === "RIGHT") return <CgArrowLongRightE />;
|
|
|
|
- return <CgArrowLongDownE />;
|
|
|
|
|
|
+function rotateLayout(layout: CanvasDirection) {
|
|
|
|
+ if (layout === "LEFT") return 90;
|
|
|
|
+ if (layout === "UP") return 180;
|
|
|
|
+ if (layout === "RIGHT") return 270;
|
|
|
|
+ return 360;
|
|
}
|
|
}
|
|
|
|
|
|
export const Sidebar: React.FC = () => {
|
|
export const Sidebar: React.FC = () => {
|
|
- const { settings, dispatch } = useConfig();
|
|
|
|
|
|
+ const { json, settings, dispatch } = useConfig();
|
|
const router = useRouter();
|
|
const router = useRouter();
|
|
const [jsonFile, setJsonFile] = React.useState<File | null>(null);
|
|
const [jsonFile, setJsonFile] = React.useState<File | null>(null);
|
|
|
|
|
|
@@ -123,11 +120,9 @@ export const Sidebar: React.FC = () => {
|
|
toast.success(`Cleared JSON and removed from memory.`);
|
|
toast.success(`Cleared JSON and removed from memory.`);
|
|
};
|
|
};
|
|
|
|
|
|
- const toggleAutoFormat = () => {
|
|
|
|
- dispatch({ type: ConfigActionType.TOGGLE_AUTOFORMAT });
|
|
|
|
- toast(
|
|
|
|
- `Auto format has been ${settings.autoformat ? "disabled." : "enabled."}`
|
|
|
|
- );
|
|
|
|
|
|
+ const handleSave = () => {
|
|
|
|
+ localStorage.setItem("json", json);
|
|
|
|
+ toast.success("Saved JSON successfully!");
|
|
};
|
|
};
|
|
|
|
|
|
const toggleExpandCollapse = () => {
|
|
const toggleExpandCollapse = () => {
|
|
@@ -160,47 +155,42 @@ export const Sidebar: React.FC = () => {
|
|
</StyledLogo>
|
|
</StyledLogo>
|
|
</StyledElement>
|
|
</StyledElement>
|
|
</Link>
|
|
</Link>
|
|
- <Tooltip title="Home">
|
|
|
|
- <StyledElement onClick={() => router.push("/")}>
|
|
|
|
- <AiFillHome />
|
|
|
|
- </StyledElement>
|
|
|
|
- </Tooltip>
|
|
|
|
- <Tooltip title="Auto Format">
|
|
|
|
- <StyledElement onClick={toggleAutoFormat}>
|
|
|
|
- {settings.autoformat ? <MdAutoFixHigh /> : <MdOutlineAutoFixOff />}
|
|
|
|
|
|
+ <Tooltip title="Import File">
|
|
|
|
+ <StyledElement>
|
|
|
|
+ <StyledImportFile>
|
|
|
|
+ <input
|
|
|
|
+ key={jsonFile?.name}
|
|
|
|
+ onChange={handleFileChange}
|
|
|
|
+ type="file"
|
|
|
|
+ accept="application/JSON"
|
|
|
|
+ />
|
|
|
|
+ <AiOutlineFileAdd />
|
|
|
|
+ </StyledImportFile>
|
|
</StyledElement>
|
|
</StyledElement>
|
|
</Tooltip>
|
|
</Tooltip>
|
|
- <Tooltip title="Change Layout">
|
|
|
|
|
|
+ <Tooltip title="Rotate Layout">
|
|
<StyledElement
|
|
<StyledElement
|
|
onClick={() => dispatch({ type: ConfigActionType.TOGGLE_LAYOUT })}
|
|
onClick={() => dispatch({ type: ConfigActionType.TOGGLE_LAYOUT })}
|
|
>
|
|
>
|
|
- {getLayoutIcon(settings.layout)}
|
|
|
|
|
|
+ <StyledFlowIcon rotate={rotateLayout(settings.layout)} />
|
|
</StyledElement>
|
|
</StyledElement>
|
|
</Tooltip>
|
|
</Tooltip>
|
|
- <Tooltip title="Toggle Compact Nodes">
|
|
|
|
|
|
+ <Tooltip title={settings.expand ? "Shrink Nodes" : "Expand Nodes"}>
|
|
<StyledElement
|
|
<StyledElement
|
|
title="Toggle Expand/Collapse"
|
|
title="Toggle Expand/Collapse"
|
|
onClick={toggleExpandCollapse}
|
|
onClick={toggleExpandCollapse}
|
|
>
|
|
>
|
|
- {settings.expand ? <MdUnfoldMore /> : <MdUnfoldLess />}
|
|
|
|
|
|
+ {settings.expand ? <CgArrowsMergeAltH /> : <CgArrowsShrinkH />}
|
|
</StyledElement>
|
|
</StyledElement>
|
|
</Tooltip>
|
|
</Tooltip>
|
|
<Tooltip title="Clear JSON">
|
|
<Tooltip title="Clear JSON">
|
|
<StyledElement onClick={handleClear}>
|
|
<StyledElement onClick={handleClear}>
|
|
- <AiFillDelete />
|
|
|
|
|
|
+ <AiOutlineDelete />
|
|
</StyledElement>
|
|
</StyledElement>
|
|
</Tooltip>
|
|
</Tooltip>
|
|
- <Tooltip title="Import File">
|
|
|
|
- <StyledElement>
|
|
|
|
- <StyledImportFile>
|
|
|
|
- <input
|
|
|
|
- key={jsonFile?.name}
|
|
|
|
- onChange={handleFileChange}
|
|
|
|
- type="file"
|
|
|
|
- accept="application/JSON"
|
|
|
|
- />
|
|
|
|
- <FaFileImport />
|
|
|
|
- </StyledImportFile>
|
|
|
|
|
|
+ <Tooltip title="Save JSON">
|
|
|
|
+ <StyledElement onClick={handleSave}>
|
|
|
|
+ <AiOutlineSave />
|
|
</StyledElement>
|
|
</StyledElement>
|
|
</Tooltip>
|
|
</Tooltip>
|
|
</StyledTopWrapper>
|
|
</StyledTopWrapper>
|
|
@@ -219,6 +209,13 @@ export const Sidebar: React.FC = () => {
|
|
</a>
|
|
</a>
|
|
</Link>
|
|
</Link>
|
|
</StyledElement>
|
|
</StyledElement>
|
|
|
|
+ <StyledElement>
|
|
|
|
+ <Link href="https://www.patreon.com/aykutsarac">
|
|
|
|
+ <a aria-label="Patreon" rel="me" target="_blank">
|
|
|
|
+ <RiPatreonFill />
|
|
|
|
+ </a>
|
|
|
|
+ </Link>
|
|
|
|
+ </StyledElement>
|
|
</StyledBottomWrapper>
|
|
</StyledBottomWrapper>
|
|
</StyledSidebar>
|
|
</StyledSidebar>
|
|
);
|
|
);
|