@@ -7,18 +7,13 @@ import { observer } from 'mobx-react-lite'
77import type { NextPage } from 'next'
88import dynamic from 'next/dynamic'
99import { 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'
1711import { message } from 'react-message-popup'
1812import useUpdate from 'react-use/lib/useUpdate'
1913
2014import type { NoteModel } from '@mx-space/api-client'
2115import { RequestError } from '@mx-space/api-client'
16+ import { Banner } from '@mx-space/kami-design'
2217import { Loading } from '@mx-space/kami-design/components/Loading'
2318import { 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