Skip to content

Commit 77301f0

Browse files
committed
fix: notes styles and crash
Signed-off-by: Innei <tukon479@gmail.com>
1 parent c671ef2 commit 77301f0

File tree

3 files changed

+37
-41
lines changed

3 files changed

+37
-41
lines changed

src/assets/styles/extra.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ ph {
263263
padding: 1em 5em;
264264
outline: none !important;
265265

266-
@media screen and (max-width: 900px) {
266+
@media screen and (max-width: 599px) {
267267
margin-left: -1.25em;
268268
margin-right: -1.25em;
269269
padding: 1em 3em;

src/components/app/ErrorBoundary/index.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import Router from 'next/router'
12
import React, { PureComponent, createElement } from 'react'
23

34
export class ErrorBoundary extends PureComponent<{
@@ -19,6 +20,20 @@ export class ErrorBoundary extends PureComponent<{
1920
errorInfo,
2021
})
2122
}
23+
eventsRef: any = () => void 0
24+
componentDidMount(): void {
25+
this.eventsRef = () => {
26+
this.setState({
27+
error: null,
28+
errorInfo: null,
29+
})
30+
}
31+
Router.events.on('routeChangeStart', this.eventsRef)
32+
}
33+
34+
componentWillUnmount(): void {
35+
Router.events.off('routeChangeStart', this.eventsRef)
36+
}
2237

2338
render() {
2439
const { errorInfo } = this.state

src/pages/notes/[id].tsx

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,13 @@ import { observer } from 'mobx-react-lite'
77
import type { NextPage } from 'next'
88
import dynamic from 'next/dynamic'
99
import { useRouter } from 'next/router'
10-
import React, {
11-
createElement,
12-
useEffect,
13-
useMemo,
14-
useRef,
15-
useState,
16-
} from 'react'
10+
import React, { createElement, useEffect, useMemo, useRef } from 'react'
1711
import { message } from 'react-message-popup'
1812
import useUpdate from 'react-use/lib/useUpdate'
1913

2014
import type { NoteModel } from '@mx-space/api-client'
2115
import { RequestError } from '@mx-space/api-client'
16+
import { Banner } from '@mx-space/kami-design'
2217
import { Loading } from '@mx-space/kami-design/components/Loading'
2318
import { ImageSizeMetaContext } from '@mx-space/kami-design/contexts/image-size'
2419

@@ -151,36 +146,23 @@ const NoteView: React.FC<{ id: string }> = observer((props) => {
151146
`生活观察日记${note.topic ? ` / ${note.topic.name}` : ''}`,
152147
)
153148
useNoteMusic(note.music)
149+
useJumpToSimpleMarkdownRender(note.id)
154150

155151
const { title, id, text } = note
156-
157-
const [tips, setTips] = useState(``)
158-
159152
const { description, wordCount } = getSummaryFromMd(text, {
160153
count: true,
161154
length: 150,
162155
})
163-
useEffect(() => {
164-
try {
165-
setTips(
166-
`创建于 ${parseDate(note.created, 'YYYY-MM-DD dddd')}${
167-
note.modified
168-
? `, 修改于 ${parseDate(note.modified, 'YYYY-MM-DD dddd')}`
169-
: ''
170-
}, 全文字数:${wordCount}, 阅读次数:${note.count.read}, 喜欢次数:${
171-
note.count.like
172-
}`,
173-
)
174-
// eslint-disable-next-line no-empty
175-
} catch {}
176-
}, [
177-
text,
178-
note.created,
179-
note.modified,
180-
note.count.read,
181-
note.count.like,
182-
wordCount,
183-
])
156+
157+
const tips = useMemo(() => {
158+
return `创建于 ${parseDate(note.created, 'YYYY-MM-DD dddd')}${
159+
note.modified
160+
? `, 修改于 ${parseDate(note.modified, 'YYYY-MM-DD dddd')}`
161+
: ''
162+
}, 全文字数:${wordCount}, 阅读次数:${note.count.read}, 喜欢次数:${
163+
note.count.like
164+
}`
165+
}, [note.count.like, note.count.read, note.created, note.modified, wordCount])
184166

185167
const isSecret = note.secret ? dayjs(note.secret).isAfter(new Date()) : false
186168
const secretDate = useMemo(() => new Date(note.secret!), [note.secret])
@@ -206,7 +188,11 @@ const NoteView: React.FC<{ id: string }> = observer((props) => {
206188
}
207189
}, [isSecret, secretDate])
208190

209-
useJumpToSimpleMarkdownRender(note.id)
191+
const imageSizeProviderValue = useMemo(
192+
() => imagesRecord2Map(note.images || []),
193+
[note.images],
194+
)
195+
210196
return (
211197
<>
212198
{createElement(Seo, {
@@ -231,16 +217,11 @@ const NoteView: React.FC<{ id: string }> = observer((props) => {
231217
这篇文章暂时没有公开呢,将会在 {dateFormat} 解锁,再等等哦
232218
</p>
233219
) : (
234-
<ImageSizeMetaContext.Provider
235-
value={useMemo(
236-
() => imagesRecord2Map(note.images || []),
237-
[note.images],
238-
)}
239-
>
220+
<ImageSizeMetaContext.Provider value={imageSizeProviderValue}>
240221
{isSecret && (
241-
<span className={'flex justify-center -mb-3.5'}>
222+
<Banner type="info" className="mt-4">
242223
这是一篇非公开的文章。(将在 {dateFormat} 解锁)
243-
</span>
224+
</Banner>
244225
)}
245226

246227
<BanCopy>

0 commit comments

Comments
 (0)