Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit 0f4d925

Browse files
authored
fix(drawer): loading article too slow (#1237)
1 parent daedf00 commit 0f4d925

File tree

7 files changed

+29
-21
lines changed

7 files changed

+29
-21
lines changed

src/containers/tool/CollectionFolder/logic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ export const useInit = (_store: TStore, isMobile: boolean): void => {
236236
store = _store
237237
// log('effect init')
238238
sub$ = sr71$.data().subscribe($solver(DataSolver, ErrSolver))
239-
load()
239+
// load()
240240

241241
if (isMobile) {
242242
store.changeViewTo('setter')

src/containers/unit/Footer/logic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export const useInit = (_store: TStore, metric: TMetric): void => {
118118
store = _store
119119
store.mark({ metric })
120120
sub$ = sr71$.data().subscribe($solver(DataSolver, ErrSolver))
121-
getOnlineStatus()
121+
// getOnlineStatus()
122122
checkSessionState()
123123

124124
return () => {

src/containers/viewer/ArticleViewer/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@ const ArticleViewerContainer: FC<TProps> = ({
3838
testid = 'article-viewer',
3939
}) => {
4040
useInit(store)
41-
const { viewingArticle, loading, tab, blogRssInfoData } = store
41+
const { viewingArticle, documentData, loading, tab, blogRssInfoData } = store
42+
const article = Object.assign(viewingArticle, { document: documentData })
4243

4344
return (
4445
<Wrapper testid={testid}>
4546
<CollectionFolder />
4647
<Viewer
47-
article={viewingArticle}
48+
article={article}
4849
loading={loading}
4950
tab={tab}
5051
blogRssInfo={blogRssInfoData}

src/containers/viewer/ArticleViewer/logic.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,24 @@ const loadArticle = (): void => {
7070
const markLoading = (maybe = true) => store.mark({ loading: maybe })
7171

7272
const handleArticleRes = (article: TArticle): void => {
73-
log('handleArticleRes: ', article)
74-
75-
const thread = article.meta.thread.toLowerCase()
76-
store.setViewing({ [thread]: merge(store.viewingArticle, article) })
73+
log('# handleArticleRes: ', article)
7774
markLoading(false)
7875

79-
const { id, viewerHasUpvoted, views, upvotesCount } = article
80-
store.syncArticle({
81-
id,
82-
viewerHasUpvoted,
83-
views,
84-
upvotesCount,
85-
viewerHasViewed: true,
86-
})
76+
const thread = article.meta.thread.toLowerCase()
77+
const { document, ...restArticle } = article
78+
store.mark({ document })
79+
store.setViewing({ [thread]: merge(store.viewingArticle, restArticle) })
80+
81+
setTimeout(() => {
82+
const { id, viewerHasUpvoted, views, upvotesCount } = article
83+
store.syncArticle({
84+
id,
85+
viewerHasUpvoted,
86+
views,
87+
upvotesCount,
88+
viewerHasViewed: true,
89+
})
90+
}, 2000)
8791
}
8892

8993
const handleUovoteRes = ({ upvotesCount, meta }) => {
@@ -169,12 +173,10 @@ const ErrSolver = [
169173
export const useInit = (_store: TStore): void => {
170174
useEffect(() => {
171175
store = _store
172-
// log('effect init')
173176
sub$ = sr71$.data().subscribe($solver(DataSolver, ErrSolver))
174177
loadArticle()
175178

176179
return () => {
177-
log('uninit')
178180
store.reset()
179181
sr71$.stop()
180182
sub$.unsubscribe()

src/containers/viewer/ArticleViewer/store.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ import type {
1414
TArticleMeta,
1515
TThread,
1616
TBlogRSS,
17+
TDocument,
1718
} from '@/spec'
1819

1920
import uid from '@/utils/uid'
2021
import { markStates, toJS } from '@/utils/mobx'
2122
import { buildLog } from '@/utils/logger'
22-
import { BlogRSSInfo } from '@/model'
23+
import { BlogRSSInfo, Document } from '@/model'
2324

2425
/* eslint-disable-next-line */
2526
const log = buildLog('S:ArticleViewer')
@@ -29,12 +30,16 @@ const ArticleViewer = T.model('ArticleViewer', {
2930
tab: T.optional(T.string, ''),
3031
// blog-spec
3132
blogRssInfo: T.optional(BlogRSSInfo, {}),
33+
document: T.optional(Document, {}),
3234
})
3335
.views((self) => ({
3436
get isLogin(): boolean {
3537
const root = getParent(self) as TRootStore
3638
return root.account.isLogin
3739
},
40+
get documentData(): TDocument {
41+
return toJS(self.document)
42+
},
3843
get accountInfo(): TAccount {
3944
const root = getParent(self) as TRootStore
4045
return root.account.accountInfo

src/stores/Model/helper/article.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const ArticleMeta = T.model('ArticleMeta', {
1818
illegalWords: T.optional(T.array(T.string), []),
1919
})
2020

21-
const Document = T.model('ArticleMeta', {
21+
export const Document = T.model('ArticleMeta', {
2222
bodyHtml: T.optional(T.string, ''),
2323
body: T.maybeNull(T.string),
2424
// toc:

src/stores/Model/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ export const Mention = T.model('Mention', {
3535
avatar: T.string,
3636
})
3737

38-
export { articleFields } from './helper/article'
38+
export { articleFields, Document } from './helper/article'

0 commit comments

Comments
 (0)