Skip to content

Commit 85c723e

Browse files
committed
refactor: load pageddata based on sidebar root menu
1 parent ba3652b commit 85c723e

File tree

12 files changed

+95
-54
lines changed

12 files changed

+95
-54
lines changed

containers/CommunitiesContent/logic.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export function loadPosts(page = 1) {
8888
const size = PAGE_SIZE.D
8989
const args = {
9090
filter: { page, size },
91+
userHasLogin: false,
9192
}
9293
scrollIntoEle(TYPE.APP_HEADER_ID)
9394
store.markState({ postsLoading: true })
@@ -116,17 +117,11 @@ export function loadCommunitiesIfOnClient() {
116117
}
117118

118119
export function loadTagsIfOnClient() {
119-
if (!store.pagedTags) {
120-
debug('loadTagsIfOnClient')
121-
// loadTags()
122-
}
120+
debug('loadTagsIfOnClient')
123121
}
124122

125123
export function loadThreadsIfOnClient() {
126-
if (!store.pagedThreads) {
127-
debug('loadThreadsIfOnClient')
128-
// loadThreads()
129-
}
124+
debug('loadThreadsIfOnClient')
130125
}
131126

132127
export function onEdit(record) {
@@ -381,6 +376,15 @@ const DataSolver = [
381376
case ROUTE.CATEGORIES: {
382377
return loadCategories()
383378
}
379+
case ROUTE.TAGS: {
380+
return loadTags()
381+
}
382+
case ROUTE.THREADS: {
383+
return loadThreads()
384+
}
385+
case ROUTE.POSTS: {
386+
return loadPosts()
387+
}
384388
default: {
385389
return loadCommunities()
386390
}

containers/Content/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { inject, observer } from 'mobx-react'
1010
// import Link from 'next/link'
1111
import CommunityContent from '../CommunityContent'
1212
import CommunitiesContent from '../CommunitiesContent'
13+
import UsersContent from '../UsersContent'
1314
// import { CommunityContent, CommunitiesContent } from '.'
1415

1516
import { makeDebugger, storePlug, ROUTE } from '../../utils'
@@ -24,6 +25,9 @@ const DomainContent = ({ curRoute }) => {
2425
case ROUTE.COMMUNITIES: {
2526
return <CommunitiesContent />
2627
}
28+
case ROUTE.USERS: {
29+
return <UsersContent />
30+
}
2731
default: {
2832
return <CommunityContent />
2933
}

containers/Sidebar/CommunitiesRootMenuItem.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import * as logic from './logic'
2121
const MenuChildren = ({ activeRaw, curRaw, activeThread }) => (
2222
<ChildrenWrapper active={activeRaw === curRaw}>
2323
<ChildrenItem
24-
active={ROUTE.COMMUNITIES === activeThread}
24+
active={ROUTE.COMMUNITIES === activeThread || activeThread === 'index'}
2525
onClick={logic.onRootMenuSelect.bind(this, 'communities', 'index')}
2626
>
2727
<ChildrenItemInner>

containers/Sidebar/UsersRootMenuItem.js

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react'
2-
import Link from 'next/link'
32

43
import { ICON_CMD } from '../../config'
54

@@ -21,37 +20,23 @@ import * as logic from './logic'
2120

2221
const MenuChildren = ({ activeRaw, curRaw, activeThread }) => (
2322
<ChildrenWrapper active={activeRaw === curRaw}>
24-
<ChildrenItem active={ROUTE.USERS === activeThread}>
25-
<Link href="/users">
26-
<ChildrenItemInner>
27-
<ChildrenTitle>注册用户</ChildrenTitle>
28-
<ChildrenNum>23</ChildrenNum>
29-
</ChildrenItemInner>
30-
</Link>
23+
<ChildrenItem
24+
active={ROUTE.USERS === activeThread || activeThread === 'index'}
25+
onClick={logic.onRootMenuSelect.bind(this, 'users', 'index')}
26+
>
27+
<ChildrenItemInner>
28+
<ChildrenTitle>注册用户</ChildrenTitle>
29+
<ChildrenNum>23</ChildrenNum>
30+
</ChildrenItemInner>
3131
</ChildrenItem>
32-
<ChildrenItem active={ROUTE.PAYS === activeThread}>
33-
<Link href="/users" as="/users/pays">
34-
<ChildrenItemInner>
35-
<ChildrenTitle>衣食父母</ChildrenTitle>
36-
<ChildrenNum>22</ChildrenNum>
37-
</ChildrenItemInner>
38-
</Link>
39-
</ChildrenItem>
40-
<ChildrenItem active={ROUTE.PASSPORTS === activeThread}>
41-
<Link href="/users" as="/users/passports">
42-
<ChildrenItemInner>
43-
<ChildrenTitle>权限</ChildrenTitle>
44-
<ChildrenNum>22</ChildrenNum>
45-
</ChildrenItemInner>
46-
</Link>
47-
</ChildrenItem>
48-
<ChildrenItem active={ROUTE.ROLES === activeThread}>
49-
<Link href="/users" as="/users/roles">
50-
<ChildrenItemInner>
51-
<ChildrenTitle>角色</ChildrenTitle>
52-
<ChildrenNum>445</ChildrenNum>
53-
</ChildrenItemInner>
54-
</Link>
32+
<ChildrenItem
33+
active={ROUTE.PAYS === activeThread}
34+
onClick={logic.onRootMenuSelect.bind(this, 'users', 'pays')}
35+
>
36+
<ChildrenItemInner>
37+
<ChildrenTitle>衣食父母</ChildrenTitle>
38+
<ChildrenNum>22</ChildrenNum>
39+
</ChildrenItemInner>
5540
</ChildrenItem>
5641
</ChildrenWrapper>
5742
)

containers/Sidebar/logic.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,9 @@ export function extendMenuBar(communityRaw) {
5757
}
5858

5959
export function onRootMenuSelect(mainPath, subPath) {
60-
console.log('onRootMenuSelect mainPath: ', mainPath)
61-
console.log('onRootMenuSelect subPath: ', subPath)
62-
6360
store.markRoute({ mainPath, subPath })
6461

6562
dispatchEvent(EVENT.SIDEBAR_MENU_CHANGE, {
66-
// type: TYPE.SIDEBAR_MENU_CHANGE,
6763
data: { mainPath, subPath },
6864
})
6965
}

containers/UsersBanner/logic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const debug = makeDebugger('L:UsersBanner')
1515
let store = null
1616

1717
export function loadUsers() {
18-
sr71$.query(S.pagedUsers, { filter: {} })
18+
sr71$.query(S.pagedUsers, { filter: {}, userHasLogin: false })
1919
}
2020

2121
export function onAdd() {}

containers/UsersContent/IndexContent.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,7 @@ const columns = [
146146
]
147147

148148
class IndexContent extends React.Component {
149-
componentDidMount() {
150-
logic.loadUsers()
151-
}
149+
componentDidMount() {}
152150

153151
render() {
154152
const {

containers/UsersContent/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ const debug = makeDebugger('C:UsersContent')
2222
const renderChildBanner = (route, store, restProps) => {
2323
const { pagedUsersData } = store
2424

25+
console.log('pagedUsersData: ', pagedUsersData)
2526
switch (route.subPath) {
2627
case ROUTE.USERS: {
2728
return <IndexContent data={pagedUsersData} restProps={restProps} />
2829
}
2930
default: {
30-
return <h2>Index</h2>
31+
return <IndexContent data={pagedUsersData} restProps={restProps} />
3132
}
3233
}
3334
}
@@ -38,6 +39,10 @@ class UsersContentContainer extends React.Component {
3839
logic.init(usersContent)
3940
}
4041

42+
componentWillUnmount() {
43+
logic.uninit()
44+
}
45+
4146
render() {
4247
const { usersContent } = this.props
4348
const { route } = usersContent

containers/UsersContent/logic.js

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
// ERR,
77
EVENT,
88
TYPE,
9+
ROUTE,
910
dispatchEvent,
1011
scrollIntoEle,
1112
} from '../../utils'
@@ -15,7 +16,7 @@ import S from './schema'
1516
import SR71 from '../../utils/network/sr71'
1617

1718
const sr71$ = new SR71({
18-
resv_event: [EVENT.PREVIEW_CLOSE],
19+
resv_event: [EVENT.PREVIEW_CLOSE, EVENT.SIDEBAR_MENU_CHANGE],
1920
})
2021
let sub$ = null
2122

@@ -29,10 +30,13 @@ const commonFilter = page => {
2930
const size = PAGE_SIZE.D
3031
return {
3132
filter: { page, size },
33+
userHasLogin: false,
3234
}
3335
}
3436

3537
export function loadUsers(page = 1) {
38+
debug('do loadUsers')
39+
3640
scrollIntoEle(TYPE.APP_HEADER_ID)
3741
store.markState({ usersLoading: true })
3842
sr71$.query(S.pagedUsers, commonFilter(page))
@@ -62,6 +66,7 @@ const DataSolver = [
6266
match: asyncRes('pagedUsers'),
6367
action: ({ pagedUsers }) => {
6468
cancleLoading()
69+
debug('get pagedUsers: ', pagedUsers)
6570
store.markState({ pagedUsers })
6671
},
6772
},
@@ -81,12 +86,50 @@ const DataSolver = [
8186
}
8287
},
8388
},
89+
{
90+
match: asyncRes(EVENT.SIDEBAR_MENU_CHANGE),
91+
action: res => {
92+
const { mainPath, subPath } = res[EVENT.SIDEBAR_MENU_CHANGE].data
93+
debug('mainPath event: ', mainPath)
94+
debug('mainPath subPath: ', subPath)
95+
96+
if (mainPath !== ROUTE.USERS) return false
97+
loadUsers()
98+
99+
/*
100+
switch (subPath) {
101+
case ROUTE.CATEGORIES: {
102+
return loadCategories()
103+
}
104+
case ROUTE.TAGS: {
105+
return loadTags()
106+
}
107+
case ROUTE.THREADS: {
108+
return loadThreads()
109+
}
110+
case ROUTE.POSTS: {
111+
return loadPosts()
112+
}
113+
default: {
114+
return loadCommunities()
115+
}
116+
}
117+
*/
118+
},
119+
},
84120
]
85121
const ErrSolver = []
86122

87-
export function init(selectedStore) {
88-
store = selectedStore
123+
export function init(_store) {
124+
store = _store
89125

90-
if (sub$) sub$.unsubscribe()
126+
if (sub$) return false
91127
sub$ = sr71$.data().subscribe($solver(DataSolver, ErrSolver))
92128
}
129+
130+
export function uninit() {
131+
if (!sub$) return false
132+
debug('===== do uninit')
133+
// sub$.unsubscribe()
134+
// sub$ = null
135+
}

containers/schemas/pages/post.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ export const pagedPosts = `
4343
digest
4444
linkAddr
4545
copyRight
46+
communities {
47+
${F.community}
48+
}
4649
commentsCount
4750
commentsParticipators(filter: { first: 5 }) {
4851
${F.author}

0 commit comments

Comments
 (0)