Skip to content

Commit

Permalink
fix: some optimize
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <[email protected]>
  • Loading branch information
Innei committed Oct 31, 2023
1 parent 493546f commit 45bad96
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 22 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"@vercel/analytics": "1.1.1",
"@vercel/postgres": "0.5.0",
"axios": "1.6.0",
"bypass-vue-devtools": "0.0.6",
"clsx": "2.0.0",
"daisyui": "3.9.4",
"dayjs": "1.11.10",
Expand Down
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions src/app/InitInClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use client'

import { useEffect } from 'react'
import { cheatVueDevtools } from 'bypass-vue-devtools'

import { init } from './init'

init()

export const InitInClient = () => {
useEffect(() => {
cheatVueDevtools()
}, [])
return null
}
5 changes: 3 additions & 2 deletions src/app/init.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import dayjs from "dayjs"
import dayjs from 'dayjs'

import 'dayjs/locale/zh-cn'

export const init = () => {
dayjs.locale('zh-cn')
}
}
2 changes: 2 additions & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { queries } from '~/queries/definition'
import { Providers } from '../providers/root'
import { Analyze } from './analyze'
import { init } from './init'
import { InitInClient } from './InitInClient'

const { version } = PKG
init()
Expand Down Expand Up @@ -162,6 +163,7 @@ export default async function RootLayout(props: Props) {
</Providers>
<ToastContainer />
<ScrollTop />
<InitInClient />
</body>
</html>
<Analytics />
Expand Down
4 changes: 2 additions & 2 deletions src/components/ui/theme-switcher/ThemeSwitcher.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client'

import { useCallback } from 'react'
import { flushSync } from 'react-dom'
import { atom } from 'jotai'
import { useTheme } from 'next-themes'
import { tv } from 'tailwind-variants'
Expand Down Expand Up @@ -146,8 +147,7 @@ const ButtonGroup = () => {

document
.startViewTransition(() => {
setTheme(theme)
return Promise.resolve()
flushSync(() => setTheme(theme))
})
?.ready.then(() => {
if (mousePosition.x === 0) return
Expand Down
42 changes: 24 additions & 18 deletions src/providers/root/modal-stack-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import { CloseIcon } from '~/components/icons/close'
import { DialogOverlay } from '~/components/ui/dialog/DialogOverlay'
import { Divider } from '~/components/ui/divider'
import { microReboundPreset } from '~/constants/spring'
import { useEventCallback } from '~/hooks/common/use-event-callback'
import { useIsClient } from '~/hooks/common/use-is-client'
import { useIsUnMounted } from '~/hooks/common/use-is-unmounted'
import { stopPropagation } from '~/lib/dom'
import { clsxm } from '~/lib/helper'
import { jotaiStore } from '~/lib/store'
Expand Down Expand Up @@ -55,23 +55,26 @@ export const useModalStack = () => {
const id = useId()
const currentCount = useRef(0)
return {
present(props: ModalProps & { id?: string }) {
const modalId = `${id}-${currentCount.current++}`
jotaiStore.set(modalStackAtom, (p) => {
const modalProps = {
...props,
id: props.id ?? modalId,
}
modalIdToPropsMap[modalProps.id] = modalProps
return p.concat(modalProps)
})

return () => {
present: useCallback(
(props: ModalProps & { id?: string }) => {
const modalId = `${id}-${currentCount.current++}`
jotaiStore.set(modalStackAtom, (p) => {
return p.filter((item) => item.id !== modalId)
const modalProps = {
...props,
id: props.id ?? modalId,
}
modalIdToPropsMap[modalProps.id] = modalProps
return p.concat(modalProps)
})
}
},

return () => {
jotaiStore.set(modalStackAtom, (p) => {
return p.filter((item) => item.id !== modalId)
})
}
},
[id],
),

...actions,
}
Expand Down Expand Up @@ -136,11 +139,11 @@ const Modal: Component<{
index: number
}> = memo(function Modal({ item, index }) {
const setStack = useSetAtom(modalStackAtom)
const close = useEventCallback(() => {
const close = useCallback(() => {
setStack((p) => {
return p.filter((modal) => modal.id !== item.id)
})
})
}, [item.id, setStack])

const onClose = useCallback(
(open: boolean): void => {
Expand Down Expand Up @@ -170,6 +173,8 @@ const Modal: Component<{
},
[close],
)

const isUnmounted = useIsUnMounted()
const noticeModal = useCallback(() => {
animateController
.start({
Expand All @@ -179,6 +184,7 @@ const Modal: Component<{
},
})
.then(() => {
if (isUnmounted.current) return
animateController.start({
scale: 1,
})
Expand Down

1 comment on commit 45bad96

@vercel
Copy link

@vercel vercel bot commented on 45bad96 Oct 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
springtide.vercel.app
shiro-innei.vercel.app
innei.in

Please sign in to comment.