From 186f3b94dc9519bd6d8d8ea09e907ac4656c93ad Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Sun, 2 Jun 2024 16:31:47 -0400 Subject: [PATCH 1/3] remove page level implementation --- .../daos/[daoAddress]/proposals/new/index.tsx | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/src/pages/daos/[daoAddress]/proposals/new/index.tsx b/src/pages/daos/[daoAddress]/proposals/new/index.tsx index c64d97c391..8273da71ca 100644 --- a/src/pages/daos/[daoAddress]/proposals/new/index.tsx +++ b/src/pages/daos/[daoAddress]/proposals/new/index.tsx @@ -1,42 +1,22 @@ import { Center } from '@chakra-ui/react'; -import { useRef, useEffect } from 'react'; import { ProposalBuilder } from '../../../../../components/ProposalBuilder'; import { DEFAULT_PROPOSAL } from '../../../../../components/ProposalBuilder/constants'; import { BarLoader } from '../../../../../components/ui/loaders/BarLoader'; import { useHeaderHeight } from '../../../../../constants/common'; import { usePrepareProposal } from '../../../../../hooks/DAO/proposal/usePrepareProposal'; import { useFractal } from '../../../../../providers/App/AppProvider'; -import { useSafeAPI } from '../../../../../providers/App/hooks/useSafeAPI'; -import { NodeAction } from '../../../../../providers/App/node/action'; import { ProposalBuilderMode } from '../../../../../types'; export default function CreateProposalPage() { const { - action, node: { daoAddress, safe }, governance: { type }, } = useFractal(); - const safeAPI = useSafeAPI(); const { prepareProposal } = usePrepareProposal(); const HEADER_HEIGHT = useHeaderHeight(); - const isMounted = useRef(false); - useEffect(() => { - if (!safeAPI || !daoAddress || isMounted.current) { - return; - } - (async () => { - const safeInfo = await safeAPI.getSafeData(daoAddress); - action.dispatch({ - type: NodeAction.SET_SAFE_INFO, - payload: safeInfo, - }); - })(); - - isMounted.current = true; - }, [action, daoAddress, safeAPI]); if (!type || !daoAddress || !safe) { return ( From d20470e3028a4c5b15fddf3b505502854652a5b0 Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Sun, 2 Jun 2024 16:33:52 -0400 Subject: [PATCH 2/3] add new hook to retrieve lastest info on page/url change --- src/hooks/utils/useUpdateSafeData.ts | 32 ++++++++++++++++++++++++++++ src/pages/DAOController.tsx | 2 ++ 2 files changed, 34 insertions(+) create mode 100644 src/hooks/utils/useUpdateSafeData.ts diff --git a/src/hooks/utils/useUpdateSafeData.ts b/src/hooks/utils/useUpdateSafeData.ts new file mode 100644 index 0000000000..fd4e1bbd1f --- /dev/null +++ b/src/hooks/utils/useUpdateSafeData.ts @@ -0,0 +1,32 @@ +import { useRef, useEffect } from 'react'; +import { useLocation } from 'react-router-dom'; +import { useFractal } from '../../providers/App/AppProvider'; +import { useSafeAPI } from '../../providers/App/hooks/useSafeAPI'; +import { NodeAction } from '../../providers/App/node/action'; + +export const useUpdateSafeData = () => { + const { + action, + node: { daoAddress }, + } = useFractal(); + const safeAPI = useSafeAPI(); + const location = useLocation(); + const prevPathname = useRef(location.pathname); + + useEffect(() => { + if (!safeAPI || !daoAddress) { + return; + } + + if (prevPathname.current !== location.pathname) { + (async () => { + const safeInfo = await safeAPI.getSafeData(daoAddress); + action.dispatch({ + type: NodeAction.SET_SAFE_INFO, + payload: safeInfo, + }); + })(); + prevPathname.current = location.pathname; + } + }, [action, daoAddress, safeAPI, location]); +}; diff --git a/src/pages/DAOController.tsx b/src/pages/DAOController.tsx index 820e0698d6..e1ea0a2254 100644 --- a/src/pages/DAOController.tsx +++ b/src/pages/DAOController.tsx @@ -1,11 +1,13 @@ import { useEffect } from 'react'; import { Outlet } from 'react-router-dom'; import useDAOController from '../hooks/DAO/useDAOController'; +import { useUpdateSafeData } from '../hooks/utils/useUpdateSafeData'; import { useFractal } from '../providers/App/AppProvider'; import LoadingProblem from './LoadingProblem'; export default function DAOController() { const { errorLoading, wrongNetwork, invalidQuery } = useDAOController(); + useUpdateSafeData(); const { node: { daoName }, } = useFractal(); From e8726055470731eaa89c59583d402b655a69ecc8 Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Sun, 2 Jun 2024 20:35:33 -0400 Subject: [PATCH 3/3] run pretty/lint --- src/pages/daos/[daoAddress]/proposals/new/index.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/pages/daos/[daoAddress]/proposals/new/index.tsx b/src/pages/daos/[daoAddress]/proposals/new/index.tsx index 8273da71ca..6c7a3ed961 100644 --- a/src/pages/daos/[daoAddress]/proposals/new/index.tsx +++ b/src/pages/daos/[daoAddress]/proposals/new/index.tsx @@ -16,8 +16,6 @@ export default function CreateProposalPage() { const HEADER_HEIGHT = useHeaderHeight(); - - if (!type || !daoAddress || !safe) { return (