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

Commit ec43456

Browse files
committed
refactor(sidebar): count status in real number
1 parent 5a6ae98 commit ec43456

File tree

10 files changed

+88
-45
lines changed

10 files changed

+88
-45
lines changed

containers/CommunityContent/PostsContent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ const columns = [
131131

132132
class PostsContent extends React.Component {
133133
componentDidMount() {
134-
logic.loadPosts()
134+
// logic.loadPosts()
135135
}
136136

137137
render() {

containers/CommunityContent/TagsContent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ const columns = [
101101

102102
class TagsContent extends React.Component {
103103
componentDidMount() {
104-
logic.loadTags()
104+
// logic.loadTags()
105105
}
106106

107107
render() {

containers/CommunityContent/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ class CommunityContentContainer extends React.Component {
4848
logic.init(communityContent)
4949
}
5050

51+
componentWillUnmount() {
52+
logic.uninit()
53+
}
54+
5155
render() {
5256
const { communityContent } = this.props
5357
const { route } = communityContent

containers/CommunityContent/logic.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ const ErrSolver = []
8181
export function init(selectedStore) {
8282
store = selectedStore
8383
debug(store)
84-
if (sub$) sub$.unsubscribe()
84+
if (sub$) return false
8585
sub$ = sr71$.data().subscribe($solver(DataSolver, ErrSolver))
8686
}
87+
88+
export function uninit() {
89+
if (!sub$) return false
90+
debug('===== do uninit')
91+
sub$.unsubscribe()
92+
sub$ = null
93+
}

containers/Sidebar/CommunitiesRootMenuItem.js

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const MenuChildren = ({ activeRaw, curRaw, activeThread, countsInfo }) => (
2626
>
2727
<ChildrenItemInner>
2828
<ChildrenTitle>社区</ChildrenTitle>
29-
<ChildrenNum>{countsInfo.communitiesTotalCount}</ChildrenNum>
29+
<ChildrenNum>{countsInfo.communitiesCount}</ChildrenNum>
3030
</ChildrenItemInner>
3131
</ChildrenItem>
3232
<ChildrenItem
@@ -35,7 +35,7 @@ const MenuChildren = ({ activeRaw, curRaw, activeThread, countsInfo }) => (
3535
>
3636
<ChildrenItemInner>
3737
<ChildrenTitle>分类</ChildrenTitle>
38-
<ChildrenNum>{countsInfo.categoriesTotalCount}</ChildrenNum>
38+
<ChildrenNum>{countsInfo.categoriesCount}</ChildrenNum>
3939
</ChildrenItemInner>
4040
</ChildrenItem>
4141
<ChildrenItem
@@ -44,7 +44,7 @@ const MenuChildren = ({ activeRaw, curRaw, activeThread, countsInfo }) => (
4444
>
4545
<ChildrenItemInner>
4646
<ChildrenTitle>标签</ChildrenTitle>
47-
<ChildrenNum>{countsInfo.tagsTotalCount}</ChildrenNum>
47+
<ChildrenNum>{countsInfo.tagsCount}</ChildrenNum>
4848
</ChildrenItemInner>
4949
</ChildrenItem>
5050
<ChildrenItem
@@ -62,7 +62,7 @@ const MenuChildren = ({ activeRaw, curRaw, activeThread, countsInfo }) => (
6262
>
6363
<ChildrenItemInner>
6464
<ChildrenTitle>Threads</ChildrenTitle>
65-
<ChildrenNum>{countsInfo.threadsTotalCount}</ChildrenNum>
65+
<ChildrenNum>{countsInfo.threadsCount}</ChildrenNum>
6666
</ChildrenItemInner>
6767
</ChildrenItem>
6868
<ChildrenItem
@@ -71,7 +71,7 @@ const MenuChildren = ({ activeRaw, curRaw, activeThread, countsInfo }) => (
7171
>
7272
<ChildrenItemInner>
7373
<ChildrenTitle>帖子</ChildrenTitle>
74-
<ChildrenNum>{countsInfo.postsTotalCount}</ChildrenNum>
74+
<ChildrenNum>{countsInfo.postsCount}</ChildrenNum>
7575
</ChildrenItemInner>
7676
</ChildrenItem>
7777
<ChildrenItem
@@ -80,7 +80,7 @@ const MenuChildren = ({ activeRaw, curRaw, activeThread, countsInfo }) => (
8080
>
8181
<ChildrenItemInner>
8282
<ChildrenTitle>招聘</ChildrenTitle>
83-
<ChildrenNum>--</ChildrenNum>
83+
<ChildrenNum>{countsInfo.jobsCount}</ChildrenNum>
8484
</ChildrenItemInner>
8585
</ChildrenItem>
8686
</ChildrenWrapper>
@@ -103,18 +103,21 @@ const CommunitiesItemBar = ({ active }) => (
103103
</MenuItemEach>
104104
)
105105

106-
const CommunitiesRootMenuItem = ({ activeRaw, activeThread, countsInfo }) => (
107-
<MenuItemWrapper>
108-
<div>
109-
<CommunitiesItemBar active={activeRaw === ROUTE.COMMUNITIES} />
110-
<MenuChildren
111-
activeRaw={activeRaw}
112-
curRaw={ROUTE.COMMUNITIES}
113-
activeThread={activeThread}
114-
countsInfo={countsInfo}
115-
/>
116-
</div>
117-
</MenuItemWrapper>
118-
)
106+
const CommunitiesRootMenuItem = ({ activeRaw, activeThread, countsInfo }) => {
107+
console.log('get fucking countsInfo: ', countsInfo)
108+
return (
109+
<MenuItemWrapper>
110+
<div>
111+
<CommunitiesItemBar active={activeRaw === ROUTE.COMMUNITIES} />
112+
<MenuChildren
113+
activeRaw={activeRaw}
114+
curRaw={ROUTE.COMMUNITIES}
115+
activeThread={activeThread}
116+
countsInfo={countsInfo}
117+
/>
118+
</div>
119+
</MenuItemWrapper>
120+
)
121+
}
119122

120123
export default CommunitiesRootMenuItem

containers/Sidebar/MenuList.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,18 @@ import { MenuItem } from './styles/menu'
88

99
import { uid } from '../../utils'
1010

11-
const MenuList = ({ items, activeRaw, activeThread, countsInfo }) => (
11+
const MenuList = ({
12+
items,
13+
activeRaw,
14+
activeThread,
15+
rootCountStatusData,
16+
countsInfo,
17+
}) => (
1218
<MenuItem>
1319
<CommunitiesRootMenuItem
1420
activeRaw={activeRaw}
1521
activeThread={activeThread}
16-
countsInfo={countsInfo}
22+
countsInfo={rootCountStatusData}
1723
/>
1824
<UsersRootMenuItem
1925
activeRaw={activeRaw}

containers/Sidebar/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,13 @@ class SidebarContainer extends React.Component {
3838
activeThread,
3939
countsInfo,
4040
searchValue,
41+
rootCountStatusData,
4142
} = sidebar
4243
// onMouseLeave={logic.leaveSidebar}
4344
// onMouseLeave is not unreliable in chrome: https://github.com/facebook/react/issues/4492
4445

46+
console.log('rootCountStatusData: ', rootCountStatusData)
47+
4548
return (
4649
<Sidebar>
4750
<Banner>
@@ -53,6 +56,7 @@ class SidebarContainer extends React.Component {
5356
<MenuList
5457
items={subscribedCommunities}
5558
activeRaw={activeRaw}
59+
rootCountStatusData={rootCountStatusData}
5660
countsInfo={countsInfo}
5761
activeThread={activeThread}
5862
/>

containers/Sidebar/logic.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ export function loadCommunities(page = 1) {
7979
sr71$.query(S.pagedCommunities, args)
8080
}
8181

82+
export const loadCountStatus = () => sr71$.query(S.countStatus, {})
83+
8284
export const searchCommunities = title =>
8385
sr71$.query(S.searchCommunities, { title })
8486

@@ -104,6 +106,12 @@ const DataSolver = [
104106
store.markState({ matchedCommunities })
105107
},
106108
},
109+
{
110+
match: asyncRes('countStatus'),
111+
action: ({ countStatus: rootCountStatus }) => {
112+
store.markState({ rootCountStatus })
113+
},
114+
},
107115
]
108116

109117
const ErrSolver = [
@@ -129,8 +137,9 @@ const ErrSolver = [
129137

130138
export function init(selectedStore) {
131139
store = selectedStore
132-
if (sub$) return false
140+
if (sub$) return loadCountStatus()
133141
sub$ = sr71$.data().subscribe($solver(DataSolver, ErrSolver))
142+
loadCountStatus()
134143
// loadCommunities()
135144
}
136145

containers/Sidebar/schema.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,25 @@ const searchCommunities = gql`
3333
}
3434
`
3535

36+
const countStatus = gql`
37+
query {
38+
countStatus {
39+
communitiesCount
40+
postsCount
41+
jobsCount
42+
videosCount
43+
reposCount
44+
categoriesCount
45+
tagsCount
46+
threadsCount
47+
}
48+
}
49+
`
50+
3651
const schema = {
3752
communities,
3853
searchCommunities,
54+
countStatus,
3955
}
4056

4157
export default schema

containers/Sidebar/store.js

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,24 @@ import { makeDebugger, markStates, ROUTE, stripMobx } from '../../utils'
1414
const debug = makeDebugger('S:SidebarStore')
1515
/* eslint-enable no-unused-vars */
1616

17-
/*
18-
const validParts = [
19-
ROUTE.COMMUNITIES,
20-
ROUTE.COMMUNITY,
21-
ROUTE.POSTS,
22-
ROUTE.JOBS,
23-
ROUTE.ACTIVITIES,
24-
ROUTE.CHEATSHEETS,
25-
ROUTE.CATEGORIES,
26-
ROUTE.EDITORS,
27-
ROUTE.THREADS,
28-
ROUTE.TAGS,
29-
ROUTE.SUBSCRIBERS,
30-
31-
ROUTE.USERS,
32-
ROUTE.PAYS,
33-
ROUTE.PASSPORTS,
34-
ROUTE.ROLES,
35-
]
36-
*/
17+
const RootCountStatus = t.model('RootCountStatus', {
18+
communitiesCount: t.optional(t.number, 0),
19+
postsCount: t.optional(t.number, 0),
20+
jobsCount: t.optional(t.number, 0),
21+
videosCount: t.optional(t.number, 0),
22+
reposCount: t.optional(t.number, 0),
23+
categoriesCount: t.optional(t.number, 0),
24+
tagsCount: t.optional(t.number, 0),
25+
threadsCount: t.optional(t.number, 0),
26+
})
3727

3828
const SidebarStore = t
3929
.model('SidebarStore', {
4030
// open: t.optional(t.boolean, false),
4131
pin: t.optional(t.boolean, true),
4232
searchValue: t.optional(t.string, ''),
4333
matchedCommunities: t.optional(PagedCommunities, emptyPagiData),
34+
rootCountStatus: t.optional(RootCountStatus, {}),
4435
// theme: t.string, // view staff
4536
// curSelectItem: t.string, // view staff
4637
// searchBox: t.string, // complex data
@@ -76,6 +67,9 @@ const SidebarStore = t
7667

7768
return R.isEmpty(subPath) ? ROUTE.COMMUNITIES : subPath
7869
},
70+
get rootCountStatusData() {
71+
return stripMobx(self.rootCountStatus)
72+
},
7973

8074
get communitiesTotalCount() {
8175
return self.root.communitiesContent.pagedCommunities.totalCount

0 commit comments

Comments
 (0)