1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 04:46:40 +07:00

added sidebar router

This commit is contained in:
Fedor Katurov 2022-07-27 16:29:22 +07:00
parent 8a4709103b
commit 8a71d3d462
18 changed files with 166 additions and 108 deletions

View file

@ -1,31 +0,0 @@
import { useCallback, useMemo } from 'react';
import { useRouter } from 'next/router';
/** use this to preserve scrolling and handle back button behaviour on
* opening modal
*
* this will replace url with ?modal=modalName, next you should
* show modal for that name and pass params to it
*/
export const useModalRouting = () => {
const router = useRouter();
const openModal = useCallback(
(modalName: string) => {
const [path] = router.asPath.split('?');
void router.push(path + '?modal=' + modalName, path + '?modal=' + modalName, {
shallow: true,
scroll: false,
});
},
[router]
);
const currentModal = useMemo(() => router.query.modal, [router]);
console.log(currentModal);
return { openModal };
};