Skip to content

Commit 06edd77

Browse files
committed
fix: peek modal shake
Signed-off-by: Innei <[email protected]>
1 parent 1bda357 commit 06edd77

File tree

5 files changed

+76
-42
lines changed

5 files changed

+76
-42
lines changed

src/app/notes/[id]/pageExtra.tsx

+1-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
'use client'
44

55
import { useEffect } from 'react'
6-
import Balancer from 'react-wrap-balancer'
76
import clsx from 'clsx'
87
import dayjs from 'dayjs'
98
import type { Image } from '@mx-space/api-client'
@@ -25,9 +24,7 @@ export const NoteTitle = () => {
2524
const title = useCurrentNoteDataSelector((data) => data?.data.title)
2625
if (!title) return null
2726
return (
28-
<h1 className="mt-8 text-left font-bold text-base-content/95">
29-
<Balancer>{title}</Balancer>
30-
</h1>
27+
<h1 className="mt-8 text-left font-bold text-base-content/95">{title}</h1>
3128
)
3229
}
3330

src/components/ui/image/ZoomedImage.tsx

+24-13
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,24 @@ export const ImageLazy: Component<TImageProps & BaseImageProps> = ({
9898
}, [zoom, zoomer_, imageLoadStatus])
9999

100100
return (
101-
<LazyLoad placeholder={placeholder} offset={30}>
102-
<figure>
103-
<span className="relative flex justify-center">
101+
<figure>
102+
<span className="relative flex justify-center">
103+
<LazyLoad placeholder={placeholder} offset={30}>
104104
<span>
105105
{imageLoadStatus !== ImageLoadStatus.Loaded && placeholder}
106106
</span>
107107

108+
{imageLoadStatus === ImageLoadStatus.Error && (
109+
<div className="absolute inset-0 z-[1] flex flex-col gap-8 center">
110+
<i className="icon-[mingcute--close-line] text-4xl text-red-500" />
111+
<span>图片加载失败</span>
112+
113+
<Divider className="w-[80px] opacity-80" />
114+
<a href={src} target="_blank" rel="noreferrer">
115+
<span>查看原图</span>
116+
</a>
117+
</div>
118+
)}
108119
<img
109120
src={src}
110121
title={title}
@@ -126,16 +137,16 @@ export const ImageLazy: Component<TImageProps & BaseImageProps> = ({
126137
}
127138
}}
128139
/>
129-
</span>
130-
131-
{!!figcaption && (
132-
<figcaption className="mt-1 flex flex-col items-center justify-center">
133-
<Divider className="w-[80px] opacity-80" />
134-
<span>{figcaption}</span>
135-
</figcaption>
136-
)}
137-
</figure>
138-
</LazyLoad>
140+
</LazyLoad>
141+
</span>
142+
143+
{!!figcaption && (
144+
<figcaption className="mt-1 flex flex-col items-center justify-center">
145+
<Divider className="w-[80px] opacity-80" />
146+
<span>{figcaption}</span>
147+
</figcaption>
148+
)}
149+
</figure>
139150
)
140151
}
141152

src/components/widgets/peek/PeekLink.tsx

+8-8
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,20 @@ export const usePeek = () => {
1515
return useCallback(
1616
(href: string) => {
1717
if (isMobile) return
18+
const basePresentProps = {
19+
clickOutsideToDismiss: true,
20+
title: 'Preview',
21+
modalClassName:
22+
'relative mx-auto mt-[10vh] scrollbar-none max-w-full overflow-auto px-2 lg:max-w-[65rem] lg:p-0',
23+
}
1824

1925
if (href.startsWith('/notes/')) {
2026
requestAnimationFrame(async () => {
2127
const NotePreview = await import('./NotePreview').then(
2228
(module) => module.NotePreview,
2329
)
2430
present({
25-
clickOutsideToDismiss: true,
26-
title: 'Preview',
27-
modalClassName: 'flex justify-center',
28-
modalContainerClassName: 'flex justify-center',
31+
...basePresentProps,
2932
CustomModalComponent: () => (
3033
<PeekModal to={href}>
3134
<NotePreview noteId={parseInt(href.split('/').pop()!)} />
@@ -45,10 +48,7 @@ export const usePeek = () => {
4548
const slug = splitpath.pop()!
4649
const category = splitpath.pop()!
4750
present({
48-
clickOutsideToDismiss: true,
49-
title: 'Preview',
50-
modalClassName: 'flex justify-center',
51-
modalContainerClassName: 'flex justify-center',
51+
...basePresentProps,
5252
CustomModalComponent: () => (
5353
<PeekModal to={href}>
5454
<PostPreview category={category} slug={slug} />

src/components/widgets/peek/PeekModal.tsx

+36-17
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,44 @@ export const PeekModal = (
1010
to: string
1111
}>,
1212
) => {
13-
const { dismissAll } = useModalStack()
13+
const { dismissAll, dismissTop } = useModalStack()
14+
1415
return (
15-
<m.div
16-
initial={{ y: 100, opacity: 0.5 }}
17-
animate={{ y: 0, opacity: 1 }}
18-
exit={{ y: 100, opacity: 0 }}
19-
transition={microReboundPreset}
20-
className="relative mt-[10vh] max-w-full overflow-auto px-2 lg:max-w-[65rem] lg:p-0"
21-
>
22-
{props.children}
16+
<div>
17+
<m.div
18+
initial={{ opacity: 0.5, y: 50 }}
19+
animate={{ opacity: 1, y: 0 }}
20+
exit={{ opacity: 0, y: 50 }}
21+
transition={microReboundPreset}
22+
className="scrollbar-none"
23+
>
24+
{props.children}
25+
</m.div>
2326

24-
<Link
25-
className="absolute right-2 top-2 flex h-8 w-8 rounded-full p-1 shadow-sm ring-1 ring-zinc-200 center dark:ring-neutral-800"
26-
href={props.to}
27-
onClick={dismissAll}
27+
<m.div
28+
initial={true}
29+
exit={{
30+
opacity: 0,
31+
}}
32+
className="fixed right-2 top-2 flex items-center gap-4"
2833
>
29-
<i className="icon-[mingcute--fullscreen-2-line] text-lg" />
30-
<span className="sr-only">Go to this link</span>
31-
</Link>
32-
</m.div>
34+
<Link
35+
className="flex h-8 w-8 rounded-full p-1 shadow-sm ring-1 ring-zinc-200 center dark:ring-neutral-800"
36+
href={props.to}
37+
onClick={dismissAll}
38+
>
39+
<i className="icon-[mingcute--fullscreen-2-line] text-lg" />
40+
<span className="sr-only">Go to this link</span>
41+
</Link>
42+
43+
<button
44+
className="flex h-8 w-8 rounded-full p-1 shadow-sm ring-1 ring-zinc-200 center dark:ring-neutral-800"
45+
onClick={dismissTop}
46+
>
47+
<i className="icon-[mingcute--close-line] text-lg" />
48+
<span className="sr-only">Dimiss</span>
49+
</button>
50+
</m.div>
51+
</div>
3352
)
3453
}

src/styles/tailwindcss.css

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)