Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor(dashboard): export globalLayout to post
  • Loading branch information
mydearxym committed Jul 4, 2022
commit aa17d5ac5280a6ab90e62ee207e0355835e533cb
2 changes: 2 additions & 0 deletions src/containers/thread/ArticlesThread/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const ArticlesThreadContainer: FC<TProps> = ({ articlesThread: store }) => {
c11n,
resState,
mode,
globalLayout,
} = store
const { pageNumber, totalCount } = pagedArticlesData

Expand Down Expand Up @@ -92,6 +93,7 @@ const ArticlesThreadContainer: FC<TProps> = ({ articlesThread: store }) => {
thread={curThread}
resState={resState as TResState}
c11n={c11n}
globalLayout={globalLayout}
/>
)}
{mode === 'search' && <FaqList mode="search-hint" />}
Expand Down
7 changes: 5 additions & 2 deletions src/containers/thread/ArticlesThread/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type {
TThread,
TArticleFilter,
TC11N,
TGlobalLayout,
} from '@/spec'

import { TYPE } from '@/constant'
Expand Down Expand Up @@ -109,14 +110,16 @@ const ArticlesThread = T.model('ArticlesThread', {
const slf = self as TStore
return `paged${plural(slf.curThread, 'titleCase')}`
},
get globalLayout(): TGlobalLayout {
const root = getParent(self) as TRootStore
return root.dashboardThread.globalLayout
},
}))
.actions((self) => ({
afterInitLoading(): void {
const slf = self as TStore
const { totalCount } = slf.pagedArticlesData

console.log('totalCount -> ', totalCount)

if (totalCount === 0) {
self.resState = TYPE.RES_STATE.EMPTY
} else {
Expand Down
15 changes: 14 additions & 1 deletion src/containers/thread/DashboardThread/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { types as T, getParent, Instance } from 'mobx-state-tree'
import { keys, values, pick, findIndex, clone } from 'ramda'

import type { TCommunity, TRootStore, TTag } from '@/spec'
import type { TCommunity, TRootStore, TTag, TGlobalLayout } from '@/spec'
import { mockTags } from '@/utils/mock'

import {
Expand Down Expand Up @@ -68,6 +68,19 @@ const DashboardThread = T.model('DashboardThread', {
initSettings: T.optional(InitSettings, {}),
})
.views((self) => ({
get globalLayout(): TGlobalLayout {
const slf = self as TStore
const { initSettings } = slf
const { primaryColor, changelogLayout, postLayout, bannerLayout } =
initSettings

return {
primaryColor,
post: postLayout,
changelog: changelogLayout,
banner: bannerLayout,
}
},
get curCommunity(): TCommunity {
const root = getParent(self) as TRootStore

Expand Down
2 changes: 2 additions & 0 deletions src/containers/user/UserPublishedArticles/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const UserPublishedArticlesContainer: FC<TProps> = ({
c11n,
resState,
hasContentBg,
globalLayout,
} = store

// console.log('pagedArticlesData: ', pagedArticlesData)
Expand All @@ -49,6 +50,7 @@ const UserPublishedArticlesContainer: FC<TProps> = ({
thread={thread}
resState={resState as TResState}
c11n={c11n}
globalLayout={globalLayout}
/>
</ArticlesWrapper>
</Fragment>
Expand Down
5 changes: 5 additions & 0 deletions src/containers/user/UserPublishedArticles/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
TArticleThread,
TPagedArticles,
TC11N,
TGlobalLayout,
} from '@/spec'
import { TYPE, ARTICLE_THREAD } from '@/constant'
import { buildLog } from '@/utils/logger'
Expand Down Expand Up @@ -77,6 +78,10 @@ const UserPublishedArticles = T.model('UserPublishedArticles', {
get hasContentBg(): boolean {
return !includes(self.thread, [ARTICLE_THREAD.JOB, ARTICLE_THREAD.RADAR])
},
get globalLayout(): TGlobalLayout {
const root = getParent(self) as TRootStore
return root.dashboardThread.globalLayout
},
}))
.actions((self) => ({
markRes(res: Record<string, TPagedArticles>): void {
Expand Down
11 changes: 10 additions & 1 deletion src/spec/article.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { TCommunity, TTag } from './index'
import type { TUser, TAccount, TSimpleUser, TRSSAuthor } from './account'
import type { TID } from './utils'
import type { TEmotion } from './emotion'
import type { TColorName } from './color'

export type TCopyright = 'cc' | 'approve' | 'forbid'

Expand Down Expand Up @@ -135,6 +136,7 @@ export type TJob = TBaseArticle & {
}

export type TArticle = TPost | TJob | TBlog | TRadar
export type TArticleEntries = TPost[] | TJob[] | TBlog[] | TRadar[]

type TPagi = {
totalCount: number
Expand All @@ -144,7 +146,7 @@ type TPagi = {
}

export type TPagedArticles = {
entries: TPost[] | TJob[] | TBlog[] | TRadar[]
entries: TArticleEntries
} & TPagi

export type TPagedWorks = {
Expand Down Expand Up @@ -219,6 +221,13 @@ export type TBannerLayout = 'header' | 'tabber'
export type TPostLayout = 'upvote_first' | 'comment_first'
export type TChangelogLayout = 'fold' | 'normal'

export type TGlobalLayout = {
primaryColor: TColorName
post: TPostLayout
banner: TBannerLayout
changelog: TChangelogLayout
}

export type TCollectionFolder = {
id: TID
title: string
Expand Down
2 changes: 2 additions & 0 deletions src/spec/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export type {
TPagedCollectionFolder,
TDocument,
TArticle,
TArticleEntries,
TArticleMeta,
TPost,
TBlog,
Expand All @@ -114,6 +115,7 @@ export type {
TBannerLayout,
TPostLayout,
TChangelogLayout,
TGlobalLayout,
TCommentsState,
TWorksTab,
TBlogTab,
Expand Down
18 changes: 15 additions & 3 deletions src/widgets/PagedArticles/ArticleList.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/* eslint-disable react/display-name */

import { Fragment, memo } from 'react'
import { Fragment, memo, FC } from 'react'

import { THREAD, TYPE } from '@/constant'
import type { TArticleEntries } from '@/spec'

import PostItem from '@/widgets/PostItem'
import JobItem from '@/widgets/JobItem'
import BlogItem from '@/widgets/BlogItem'
Expand All @@ -12,9 +14,18 @@ import MasonryCards from '@/widgets/MasonryCards'
import LavaLampLoading from '@/widgets/Loading/LavaLampLoading'
import { EmptyThread } from './dynamic'

const ArticleList = (props) => {
const { curCommunity, thread, resState, entries, c11n } = props
import type { TProps as TBaseTProps } from '.'

type TProps = { entries: TArticleEntries } & Omit<TBaseTProps, 'data'>

const ArticleList: FC<TProps> = ({
curCommunity,
thread,
resState,
entries,
c11n,
globalLayout,
}) => {
// switch between threads
if (resState === TYPE.RES_STATE.LOADING && entries.length === 0) {
return <LavaLampLoading top={20} left={30} />
Expand Down Expand Up @@ -73,6 +84,7 @@ const ArticleList = (props) => {
article={entry}
c11n={c11n}
curCommunity={curCommunity}
layout={globalLayout.post}
/>
))}
</Fragment>
Expand Down
6 changes: 5 additions & 1 deletion src/widgets/PagedArticles/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type {
TPagedArticles,
TResState,
TC11N,
TGlobalLayout,
} from '@/spec'
import { EVENT } from '@/constant'
import { send } from '@/utils/helper'
Expand All @@ -24,14 +25,15 @@ import ArticleList from './ArticleList'
/* eslint-disable-next-line */
const log = buildLog('c:PagedArticles:index')

type TProps = {
export type TProps = {
curCommunity?: TCommunity | null
thread: TThread
data: TPagedArticles
resState: TResState
// TODO: remove
emptyPrefix?: string
c11n: TC11N
globalLayout: TGlobalLayout
}

const PagedArticles: FC<TProps> = ({
Expand All @@ -41,6 +43,7 @@ const PagedArticles: FC<TProps> = ({
resState,
emptyPrefix,
c11n,
globalLayout,
}) => {
const { entries, ...pagi } = data

Expand All @@ -53,6 +56,7 @@ const PagedArticles: FC<TProps> = ({
resState={resState}
emptyPrefix={emptyPrefix}
c11n={c11n}
globalLayout={globalLayout}
/>

<Pagi
Expand Down
11 changes: 9 additions & 2 deletions src/widgets/PostItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@

import { FC, memo, Fragment } from 'react'

import type { TCommunity, TPost, TUser, TAccount, TC11N } from '@/spec'
import type {
TCommunity,
TPost,
TUser,
TAccount,
TC11N,
TPostLayout,
} from '@/spec'
import { POST_LAYOUT } from '@/constant'
import { buildLog } from '@/utils/logger'

Expand All @@ -21,7 +28,7 @@ type TProps = {
curCommunity: TCommunity | null
article: TPost
c11n: TC11N
layout?: string
layout?: TPostLayout
isMobilePreview?: boolean

onUserSelect?: (obj: TUser) => void
Expand Down