import React from "react"; import toast from "react-hot-toast"; import Link from "next/link"; import styled from "styled-components"; import { TiFlowMerge } from "react-icons/ti"; import { CgArrowsMergeAltH, CgArrowsShrinkH } from "react-icons/cg"; import { AiOutlineDelete, AiFillGithub, AiOutlineTwitter, AiOutlineSave, AiOutlineFileAdd, AiOutlineLink, AiOutlineEdit, } from "react-icons/ai"; import { Tooltip } from "src/components/Tooltip"; import { useRouter } from "next/router"; import { ImportModal } from "src/containers/Modals/ImportModal"; import { ClearModal } from "src/containers/Modals/ClearModal"; import { ShareModal } from "src/containers/Modals/ShareModal"; import useConfig from "src/hooks/store/useConfig"; import { HiHeart } from "react-icons/hi"; import shallow from "zustand/shallow"; import { MdCenterFocusWeak } from "react-icons/md"; import { getNextLayout } from "src/utils/getNextLayout"; const StyledSidebar = styled.div` display: flex; justify-content: space-between; flex-direction: column; align-items: center; width: fit-content; background: ${({ theme }) => theme.BACKGROUND_TERTIARY}; padding: 4px; border-right: 1px solid ${({ theme }) => theme.BACKGROUND_MODIFIER_ACCENT}; @media only screen and (max-width: 768px) { flex-direction: row; width: 100%; } `; const StyledElement = styled.div<{ beta?: boolean }>` position: relative; display: flex; justify-content: center; text-align: center; font-size: 26px; font-weight: 600; width: 100%; color: ${({ theme }) => theme.INTERACTIVE_NORMAL}; cursor: pointer; svg { padding: 8px; vertical-align: middle; } a { display: flex; } &:hover :is(a, svg) { color: ${({ theme }) => theme.INTERACTIVE_HOVER}; } `; const StyledText = styled.span<{ secondary?: boolean }>` color: ${({ theme, secondary }) => secondary ? theme.INTERACTIVE_NORMAL : theme.ORANGE}; `; const StyledFlowIcon = styled(TiFlowMerge)<{ rotate: number }>` transform: rotate(${({ rotate }) => `${rotate}deg`}); `; const StyledTopWrapper = styled.nav` display: flex; justify-content: space-between; flex-direction: column; align-items: center; width: 100%; & > div:nth-child(n + 1) { border-bottom: 1px solid ${({ theme }) => theme.BACKGROUND_MODIFIER_ACCENT}; } .mobile { display: none; } @media only screen and (max-width: 768px) { flex-direction: row; & > div:nth-child(n + 1) { border-bottom: none; } .mobile { display: initial; } .desktop { display: none; } } `; const StyledBottomWrapper = styled.nav` display: flex; justify-content: space-between; flex-direction: column; align-items: center; width: 100%; & > div, a:nth-child(0) { border-top: 1px solid ${({ theme }) => theme.BACKGROUND_MODIFIER_ACCENT}; } @media only screen and (max-width: 768px) { display: none; } `; const StyledLogo = styled.div` color: ${({ theme }) => theme.FULL_WHITE}; `; function rotateLayout(layout: "LEFT" | "RIGHT" | "DOWN" | "UP") { if (layout === "LEFT") return 90; if (layout === "UP") return 180; if (layout === "RIGHT") return 270; return 360; } export const Sidebar: React.FC = () => { const getJson = useConfig((state) => state.getJson); const setConfig = useConfig((state) => state.setConfig); const centerView = useConfig((state) => state.centerView); const [uploadVisible, setUploadVisible] = React.useState(false); const [clearVisible, setClearVisible] = React.useState(false); const [shareVisible, setShareVisible] = React.useState(false); const { push } = useRouter(); const [expand, layout, hideEditor] = useConfig( (state) => [state.expand, state.layout, state.hideEditor], shallow ); const handleSave = () => { const a = document.createElement("a"); const file = new Blob([getJson()], { type: "text/plain" }); a.href = window.URL.createObjectURL(file); a.download = "jsoncrack.json"; a.click(); }; const toggleExpandCollapse = () => { setConfig("expand", !expand); toast(`${expand ? "Collapsed" : "Expanded"} nodes.`); }; const toggleLayout = () => { const nextLayout = getNextLayout(layout); setConfig("layout", nextLayout); }; return ( push("/")}> J C setConfig("hideEditor", !hideEditor)}> setUploadVisible(true)}> {expand ? : } setClearVisible(true)}> setShareVisible(true)}> ); };