mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-03-11 00:18:51 +01:00
Auto-close account sheet when location path changes
Test this on account sheet first, probably useful for other sheets too
This commit is contained in:
parent
106cd16e41
commit
c0c2bb45fe
1 changed files with 21 additions and 9 deletions
|
@ -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 { api } from '../utils/api';
|
||||||
import states from '../utils/states';
|
import states from '../utils/states';
|
||||||
|
@ -16,17 +17,28 @@ function AccountSheet({ account, instance: propInstance, onClose }) {
|
||||||
}
|
}
|
||||||
}, [account]);
|
}, [account]);
|
||||||
|
|
||||||
|
const location = useLocation();
|
||||||
|
const currentLocationRef = useRef(location.pathname);
|
||||||
|
useEffect(() => {
|
||||||
|
if (
|
||||||
|
currentLocationRef.current &&
|
||||||
|
location.pathname !== currentLocationRef.current
|
||||||
|
) {
|
||||||
|
onClose?.();
|
||||||
|
}
|
||||||
|
}, [location.pathname]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
class="sheet"
|
class="sheet"
|
||||||
onClick={(e) => {
|
// onClick={(e) => {
|
||||||
const accountBlock = e.target.closest('.account-block');
|
// const accountBlock = e.target.closest('.account-block');
|
||||||
if (accountBlock) {
|
// if (accountBlock) {
|
||||||
onClose({
|
// onClose({
|
||||||
destination: 'account-statuses',
|
// destination: 'account-statuses',
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
}}
|
// }}
|
||||||
>
|
>
|
||||||
{!!onClose && (
|
{!!onClose && (
|
||||||
<button type="button" class="sheet-close outer" onClick={onClose}>
|
<button type="button" class="sheet-close outer" onClick={onClose}>
|
||||||
|
|
Loading…
Reference in a new issue