From ebc3e97c9fdaabfc4fcd9c35525f302ad3a8cb45 Mon Sep 17 00:00:00 2001 From: Kirill Rogovoy Date: Sun, 25 Jul 2021 14:38:05 +0300 Subject: Move showTweaks to tweaks.tsx --- components/tweaks.tsx | 19 +++++++++++++++---- pages/index.tsx | 51 ++++++++++++++++----------------------------------- 2 files changed, 31 insertions(+), 39 deletions(-) diff --git a/components/tweaks.tsx b/components/tweaks.tsx index a082306..ab5a6a7 100644 --- a/components/tweaks.tsx +++ b/components/tweaks.tsx @@ -25,6 +25,7 @@ import { Tooltip, VStack, } from '@chakra-ui/react' +import { useState } from 'react' import Scrollbars from 'react-custom-scrollbars-2' import { initialPhysics, initialFilter } from './config' @@ -35,11 +36,22 @@ export interface TweakProps { setThreeDim: (newValue: boolean) => void filter: typeof initialFilter setFilter: any - onClose: () => void } export const Tweaks = (props: TweakProps) => { - const { physics, setPhysics, threeDim, filter, setFilter, onClose } = props + const { physics, setPhysics, threeDim, filter, setFilter } = props + const [showTweaks, setShowTweaks] = useState(true) + + if (!showTweaks) { + return + } + onClick={() => setShowTweaks(true)} + /> + + } + return ( { borderRadius="md" maxH={650} paddingBottom={5} - //overflowY="scroll" > @@ -62,7 +73,7 @@ export const Tweaks = (props: TweakProps) => { colorScheme="purple" /> - + setShowTweaks(false)} /> (null) const [emacsNodeId, setEmacsNodeId] = useState(null) const nodeByIdRef = useRef({}) - const parentNodesByFileRef = useRef({}) //useRef({}) const linksByNodeIdRef = useRef({}) - const updateGraphData = () => { + const fetchGraphData = () => { return fetch('http://localhost:35901/graph') .then((res) => res.json()) .then((orgRoamGraphData: OrgRoamGraphReponse) => { @@ -95,18 +88,17 @@ export function GraphPage() { const emacsNodeId = e.data setEmacsNodeId(emacsNodeId) }) - updateGraphData() + fetchGraphData() }, []) useEffect(() => { if (!emacsNodeId) { return } - updateGraphData() + fetchGraphData() }, [emacsNodeId]) const [threeDim, setThreeDim] = useState(false) - const [showTweaks, setShowTweaks] = useState(true) if (!graphData) { return null @@ -114,29 +106,17 @@ export function GraphPage() { return ( - {showTweaks ? ( - { - setShowTweaks(false) - }} - /> - ) : ( - - } - onClick={() => setShowTweaks(true)} - /> - - )} + + +