this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Auto-close account sheet when location path changes

Test this on account sheet first, probably useful for other sheets too

+21 -9
+21 -9
src/components/account-sheet.jsx
··· 1 - import { useEffect } from 'preact/hooks'; 1 + import { useEffect, useRef } from 'preact/hooks'; 2 + import { useLocation } from 'react-router-dom'; 2 3 3 4 import { api } from '../utils/api'; 4 5 import states from '../utils/states'; ··· 16 17 } 17 18 }, [account]); 18 19 20 + const location = useLocation(); 21 + const currentLocationRef = useRef(location.pathname); 22 + useEffect(() => { 23 + if ( 24 + currentLocationRef.current && 25 + location.pathname !== currentLocationRef.current 26 + ) { 27 + onClose?.(); 28 + } 29 + }, [location.pathname]); 30 + 19 31 return ( 20 32 <div 21 33 class="sheet" 22 - onClick={(e) => { 23 - const accountBlock = e.target.closest('.account-block'); 24 - if (accountBlock) { 25 - onClose({ 26 - destination: 'account-statuses', 27 - }); 28 - } 29 - }} 34 + // onClick={(e) => { 35 + // const accountBlock = e.target.closest('.account-block'); 36 + // if (accountBlock) { 37 + // onClose({ 38 + // destination: 'account-statuses', 39 + // }); 40 + // } 41 + // }} 30 42 > 31 43 {!!onClose && ( 32 44 <button type="button" class="sheet-close outer" onClick={onClose}>