|
4 | 4 | */ |
5 | 5 |
|
6 | 6 | import { types as T, getParent, Instance } from 'mobx-state-tree' |
7 | | -import { concat, keys, reduce, merge, contains, values } from 'ramda' |
| 7 | +import { concat, keys, reduce, merge, contains, values, findIndex } from 'ramda' |
8 | 8 |
|
9 | | -import type { TRootStore, TCommunity, TThread, TArticle } from '@/spec' |
10 | | -import { TYPE, ARTICLE_THREAD } from '@/constant' |
| 9 | +import type { TRootStore, TCommunity, TThread, TArticle, TWorks } from '@/spec' |
| 10 | +import { TYPE, ARTICLE_THREAD, THREAD } from '@/constant' |
11 | 11 |
|
12 | 12 | import { markStates, toJS } from '@/utils/mobx' |
13 | 13 | import { toggleGlobalBlur, lockPage, unlockPage } from '@/utils/dom' |
14 | | -import { Global } from '@/utils/helper' |
| 14 | +import { Global, titleCase } from '@/utils/helper' |
15 | 15 | import { WIDTH, mediaBreakPoints } from '@/utils/css/metric' |
16 | 16 | import { User } from '@/model' |
17 | 17 |
|
18 | | -import { TSwipeOption } from './spec' |
| 18 | +import { TSwipeOption, TArticleNavi } from './spec' |
19 | 19 | import { SWIPE_THRESHOLD } from './styles/metrics' |
20 | 20 |
|
21 | 21 | const defaultOptions: TSwipeOption = { direction: 'bottom', position: 'M' } |
@@ -117,10 +117,42 @@ const DrawerStore = T.model('DrawerStore', { |
117 | 117 | get modalVisible() { |
118 | 118 | return self.visible && Global.innerWidth > mediaBreakPoints.desktopL |
119 | 119 | }, |
120 | | - |
121 | 120 | get slideVisible() { |
122 | 121 | return self.visible && Global.innerWidth <= mediaBreakPoints.desktopL |
123 | 122 | }, |
| 123 | + get viewingArticle(): TArticle { |
| 124 | + const root = getParent(self) as TRootStore |
| 125 | + return root.viewing.viewingArticle |
| 126 | + }, |
| 127 | + get articleNavi(): TArticleNavi { |
| 128 | + const slf = self as TStore |
| 129 | + const root = getParent(self) as TRootStore |
| 130 | + const viewingArticleId = slf.viewingArticle.id |
| 131 | + |
| 132 | + let pagedArticles |
| 133 | + switch (slf.curThread) { |
| 134 | + case THREAD.WORKS: { |
| 135 | + pagedArticles = toJS(root.worksContent.pagedWorks) |
| 136 | + break |
| 137 | + } |
| 138 | + |
| 139 | + default: { |
| 140 | + pagedArticles = toJS( |
| 141 | + root.articlesThread[`paged${titleCase(slf.curThread)}s`], |
| 142 | + ) |
| 143 | + break |
| 144 | + } |
| 145 | + } |
| 146 | + |
| 147 | + const curIndex = findIndex( |
| 148 | + (a: TWorks) => a.id === viewingArticleId, |
| 149 | + pagedArticles.entries, |
| 150 | + ) |
| 151 | + return { |
| 152 | + previous: pagedArticles.entries[curIndex - 1] || null, |
| 153 | + next: pagedArticles.entries[curIndex + 1] || null, |
| 154 | + } |
| 155 | + }, |
124 | 156 | })) |
125 | 157 | .actions((self) => ({ |
126 | 158 | open({ type, data, options = {} }): void { |
|
0 commit comments