Skip to content

Commit

Permalink
fix: modal close when router change
Browse files Browse the repository at this point in the history
  • Loading branch information
Innei committed Jul 31, 2023
1 parent d85bd23 commit 6b12fdb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/components/layout/header/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ export const headerMenuConfig: IHeaderMenu[] = [
icon: h(FaSolidCircle),
path: '/timeline?memory=1',
},
{
title: '专栏',
path: '/notes/topics',
icon: h('i', {
className: 'icon-[mingcute--align-bottom-fill] flex center',
}),
},
],
},
{
Expand Down
11 changes: 11 additions & 0 deletions src/providers/root/modal-stack-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from 'react'
import { AnimatePresence, m, useAnimationControls } from 'framer-motion'
import { atom, useAtomValue, useSetAtom } from 'jotai'
import { usePathname } from 'next/navigation'
import type { Target, Transition } from 'framer-motion'
import type { FC, PropsWithChildren, SyntheticEvent } from 'react'

Expand Down Expand Up @@ -43,6 +44,13 @@ interface ModalProps {

const modalStackAtom = atom([] as (ModalProps & { id: string })[])

const useDismissAllWhenRouterChange = () => {
const pathname = usePathname()
useEffect(() => {
actions.dismissAll()
}, [pathname])
}

export const useModalStack = () => {
const id = useId()
const currentCount = useRef(0)
Expand Down Expand Up @@ -97,6 +105,7 @@ const ModalStack = () => {
const stack = useAtomValue(modalStackAtom)

const isClient = useIsClient()
useDismissAllWhenRouterChange()
if (!isClient) return null

return (
Expand All @@ -117,9 +126,11 @@ const initialStyle: Target = {
scale: 0.96,
opacity: 0,
}

const modalTransition: Transition = {
...microReboundPreset,
}

const Modal: Component<{
item: ModalProps & { id: string }
index: number
Expand Down

1 comment on commit 6b12fdb

@vercel
Copy link

@vercel vercel bot commented on 6b12fdb Jul 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

shiro – ./

shiro-git-main-innei.vercel.app
shiro-innei.vercel.app
springtide.vercel.app
innei.in

Please sign in to comment.