diff --git a/src/components/account-sheet.jsx b/src/components/account-sheet.jsx index 6a0d74f9..435cfa26 100644 --- a/src/components/account-sheet.jsx +++ b/src/components/account-sheet.jsx @@ -1,4 +1,5 @@ -import { useEffect } from 'preact/hooks'; +import { useEffect, useRef } from 'preact/hooks'; +import { useLocation } from 'react-router-dom'; import { api } from '../utils/api'; import states from '../utils/states'; @@ -16,17 +17,28 @@ function AccountSheet({ account, instance: propInstance, onClose }) { } }, [account]); + const location = useLocation(); + const currentLocationRef = useRef(location.pathname); + useEffect(() => { + if ( + currentLocationRef.current && + location.pathname !== currentLocationRef.current + ) { + onClose?.(); + } + }, [location.pathname]); + return (