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

Commit c60c453

Browse files
committed
refactor(tables): add repos table to community with ssr
1 parent c87775f commit c60c453

File tree

9 files changed

+121
-8
lines changed

9 files changed

+121
-8
lines changed

containers/CommunitiesContent/logic.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,15 +225,16 @@ export function unsetTag(threadId, tag) {
225225
}
226226

227227
/* when error occured cancle all the loading state */
228-
const cancleLoading = () => {
228+
const cancleLoading = () =>
229229
store.markState({
230230
communitiesLoading: false,
231231
postsLoading: false,
232232
jobsLoading: false,
233+
reposLoading: false,
234+
videosLoading: false,
233235
tagsLoading: false,
234236
categoriessLoading: false,
235237
})
236-
}
237238

238239
const DataSolver = [
239240
{
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import React from 'react'
2+
3+
import { ICON_CMD } from '../../config'
4+
import { Popover, BannerCountBrief } from '../../components'
5+
6+
import {
7+
BannerContentWrapper,
8+
Operation,
9+
OperationItem,
10+
OperationDivider,
11+
OperationTitle,
12+
OperationIcon,
13+
OperationIconChart,
14+
} from './styles/common_banner'
15+
16+
import * as logic from './logic'
17+
18+
const VideosBanner = ({ filteredCount, totalCount }) => (
19+
<BannerContentWrapper>
20+
<BannerCountBrief filteredCount={filteredCount} totalCount={totalCount} />
21+
<Operation>
22+
<OperationItem onClick={console.log}>
23+
<OperationIconChart src={`${ICON_CMD}/refresh.svg`} />
24+
刷新
25+
</OperationItem>
26+
<OperationDivider />
27+
<OperationItem>
28+
<OperationIcon src={`${ICON_CMD}/filter2.svg`} />
29+
<Popover
30+
content={<div>兼容各个页面的 Filter 菜单</div>}
31+
trigger="hover"
32+
>
33+
<OperationTitle>过滤</OperationTitle>
34+
</Popover>
35+
</OperationItem>
36+
<OperationDivider />
37+
<OperationItem onClick={logic.onAdd}>
38+
<OperationIconChart src={`${ICON_CMD}/plus.svg`} />
39+
添加
40+
</OperationItem>
41+
<OperationDivider />
42+
<OperationItem>
43+
<OperationIcon src={`${ICON_CMD}/chart.svg`} />
44+
图表
45+
</OperationItem>
46+
</Operation>
47+
</BannerContentWrapper>
48+
)
49+
50+
export default VideosBanner

containers/CommunityBanner/index.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import * as logic from './logic'
1414

1515
import PostsBanner from './PostsBanner'
1616
import JobsBanner from './JobsBanner'
17+
import VideosBanner from './VideosBanner'
1718
import TagsBanner from './TagsBanner'
1819
import ThreadsBanner from './ThreadsBanner'
1920
import SubscribersBanner from './SubscribersBanner'
@@ -28,10 +29,15 @@ const ChildBanner = ({
2829
curRoute,
2930
postsTotalCount,
3031
jobsTotalCount,
32+
videosTotalCount,
3133
tagsTotalCount,
3234
restProps,
3335
}) => {
34-
const { filteredPostsCount, filteredJobsCount } = restProps
36+
const {
37+
filteredPostsCount,
38+
filteredJobsCount,
39+
filteredVideosCount,
40+
} = restProps
3541

3642
switch (curRoute.subPath) {
3743
case ROUTE.POSTS: {
@@ -50,6 +56,14 @@ const ChildBanner = ({
5056
/>
5157
)
5258
}
59+
case ROUTE.VIDEOS: {
60+
return (
61+
<VideosBanner
62+
totalCount={videosTotalCount}
63+
filteredCount={filteredVideosCount}
64+
/>
65+
)
66+
}
5367
case ROUTE.SUBSCRIBERS: {
5468
return <SubscribersBanner totalCount={100} filteredCount={10} />
5569
}
@@ -82,6 +96,7 @@ class CommunityBannerContainer extends React.Component {
8296
curRoute,
8397
postsTotalCount,
8498
jobsTotalCount,
99+
videosTotalCount,
85100
tagsTotalCount,
86101
} = communityBanner
87102

@@ -91,6 +106,7 @@ class CommunityBannerContainer extends React.Component {
91106
curRoute={curRoute}
92107
postsTotalCount={postsTotalCount}
93108
jobsTotalCount={jobsTotalCount}
109+
videosTotalCount={videosTotalCount}
94110
tagsTotalCount={tagsTotalCount}
95111
restProps={stripMobx(communityBanner)}
96112
/>

containers/CommunityBanner/store.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const CommunityBannerStore = t
1616
// postsTotalCount: t.optional(t.number, 0),
1717
filteredPostsCount: t.maybeNull(t.number),
1818
filteredJobsCount: t.maybeNull(t.number),
19+
filteredVideosCount: t.maybeNull(t.number),
1920
// tagsTotalCount: t.optional(t.number, 0),
2021
})
2122
.views(self => ({
@@ -28,6 +29,9 @@ const CommunityBannerStore = t
2829
get jobsTotalCount() {
2930
return self.root.communityContent.pagedJobs.totalCount
3031
},
32+
get videosTotalCount() {
33+
return self.root.communityContent.pagedVideos.totalCount
34+
},
3135
get tagsTotalCount() {
3236
return self.root.communityContent.pagedTags.length
3337
},
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from 'react'
2+
3+
import VideosTable from '../../components/VideosTable'
4+
import * as logic from './logic'
5+
6+
const VideosContent = ({ data, restProps: { videosLoading } }) => (
7+
<VideosTable
8+
data={data}
9+
loading={videosLoading}
10+
onDelete={logic.onDelete}
11+
onEdit={logic.onEdit}
12+
/>
13+
)
14+
15+
export default VideosContent

containers/CommunityContent/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { makeDebugger, storePlug, ROUTE } from '../../utils'
1414
import PostsContent from './PostsContent'
1515
import JobsContent from './JobsContent'
1616
import TagsContent from './TagsContent'
17+
import VideosContent from './VideosContent'
1718

1819
import { Wrapper } from './styles'
1920
import * as logic from './logic'
@@ -26,6 +27,7 @@ const ChildContent = ({
2627
curRoute,
2728
pagedPostsData,
2829
pagedJobsData,
30+
pagedVideosData,
2931
pagedTagsData,
3032
restProps,
3133
}) => {
@@ -40,7 +42,7 @@ const ChildContent = ({
4042
return <h3>ROUTE.REPOS</h3>
4143
}
4244
case ROUTE.VIDEOS: {
43-
return <h3>ROUTE.VIDEOS</h3>
45+
return <VideosContent data={pagedVideosData} restProps={restProps} />
4446
}
4547
case ROUTE.TAGS: {
4648
return <TagsContent data={pagedTagsData} restProps={restProps} />
@@ -70,16 +72,20 @@ class CommunityContentContainer extends React.Component {
7072
curRoute,
7173
pagedPostsData,
7274
pagedJobsData,
75+
pagedVideosData,
7376
pagedTagsData,
7477
} = communityContent
7578
const restProps = { ...communityContent }
7679

80+
console.log('the fuck pagedVideosData: ', pagedVideosData)
81+
7782
return (
7883
<Wrapper>
7984
<ChildContent
8085
curRoute={curRoute}
8186
pagedPostsData={pagedPostsData}
8287
pagedJobsData={pagedJobsData}
88+
pagedVideosData={pagedVideosData}
8389
pagedTagsData={pagedTagsData}
8490
restProps={restProps}
8591
/>

containers/CommunityContent/logic.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ export function loadJobs(page = 1) {
5050
sr71$.query(S.pagedJobs, commonFilter(page, community))
5151
}
5252

53+
export function loadVideos(page = 1) {
54+
scrollIntoEle(TYPE.APP_HEADER_ID)
55+
store.markState({ videosLoading: true })
56+
const { mainPath: community } = store.curRoute
57+
sr71$.query(S.pagedVideos, commonFilter(page, community))
58+
}
59+
5360
export function loadTags() {
5461
scrollIntoEle(TYPE.APP_HEADER_ID)
5562
store.markState({ tagsLoading: true })
@@ -69,6 +76,8 @@ const cancleLoading = () => {
6976
// communitiesLoading: false,
7077
postsLoading: false,
7178
jobsLoading: false,
79+
videosLoading: false,
80+
reposLoading: false,
7281
tagsLoading: false,
7382
})
7483
}
@@ -88,6 +97,13 @@ const DataSolver = [
8897
store.markState({ pagedJobs })
8998
},
9099
},
100+
{
101+
match: asyncRes('pagedVideos'),
102+
action: ({ pagedVideos }) => {
103+
cancleLoading()
104+
store.markState({ pagedVideos })
105+
},
106+
},
91107
{
92108
match: asyncRes('partialTags'),
93109
action: ({ partialTags }) => {
@@ -102,9 +118,6 @@ const DataSolver = [
102118
debug('SIDEBAR_MENU_CHANGE ', res[EVENT.SIDEBAR_MENU_CHANGE].data)
103119

104120
switch (subPath) {
105-
case ROUTE.CATEGORIES: {
106-
return console.log('todo')
107-
}
108121
case ROUTE.TAGS: {
109122
return loadTags()
110123
}
@@ -121,7 +134,7 @@ const DataSolver = [
121134
return console.log('todo')
122135
}
123136
case ROUTE.VIDEOS: {
124-
return console.log('todo')
137+
return loadVideos()
125138
}
126139
default: {
127140
return console.log('todo')

containers/CommunityContent/store.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ const CommunityContentStore = t
5757
get pagedJobsData() {
5858
return stripMobx(self.pagedJobs)
5959
},
60+
get pagedVideosData() {
61+
return stripMobx(self.pagedVideos)
62+
},
6063
get pagedTagsData() {
6164
return { entries: stripMobx(self.pagedTags) }
6265
},

utils/ssr_helper.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ const ssrCommunityContents = (subPath, resp) => {
5959
communityContent: { pagedJobs: resp.pagedJobs },
6060
}
6161
}
62+
case ROUTE.VIDEOS: {
63+
return {
64+
communityContent: { pagedVideos: resp.pagedVideos },
65+
}
66+
}
6267
case ROUTE.TAGS: {
6368
return {
6469
communityContent: { pagedTags: resp.partialTags },

0 commit comments

Comments
 (0)