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

Commit 1b7c9f8

Browse files
committed
refactor(community page): use spec banner/content instead common ones
1 parent 2f3332f commit 1b7c9f8

File tree

17 files changed

+341
-125
lines changed

17 files changed

+341
-125
lines changed

components/CommunityContent/index.js

Lines changed: 0 additions & 62 deletions
This file was deleted.

containers/Banner/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { inject, observer } from 'mobx-react'
99

1010
import UserBanner from '../UserBanner'
1111

12-
import ArticleBanner from '../ArticleBanner'
1312
import CommunitiesBanner from '../CommunitiesBanner'
1413
import CommunityBanner from '../CommunityBanner'
1514

@@ -36,6 +35,7 @@ const BannerContent = ({ curRoute }) => {
3635
case ROUTE.ACTIVITIES: {
3736
return <ActivitiesRootBanner />
3837
}
38+
/*
3939
case ROUTE.POST: {
4040
return <ArticleBanner />
4141
}
@@ -50,6 +50,8 @@ const BannerContent = ({ curRoute }) => {
5050
<ArticleBanner showStar={false} showWordCount={false} showLastSync />
5151
)
5252
}
53+
*/
54+
5355
case ROUTE.USER: {
5456
return <UserBanner />
5557
}

containers/CommunityContent/index.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
*
3+
* CommunityContent
4+
*
5+
*/
6+
7+
import React from 'react'
8+
import { inject, observer } from 'mobx-react'
9+
10+
import PostsThread from '../PostsThread'
11+
import VideosThread from '../VideosThread'
12+
import ReposThread from '../ReposThread'
13+
import WikiThread from '../WikiThread'
14+
import JobsThread from '../JobsThread'
15+
import UsersThread from '../UsersThread'
16+
import CheatsheetThread from '../CheatsheetThread'
17+
18+
import { Wrapper } from './styles'
19+
20+
import { makeDebugger, storePlug, ROUTE } from '../../utils'
21+
import * as logic from './logic'
22+
23+
/* eslint-disable-next-line */
24+
const debug = makeDebugger('C:CommunityContent')
25+
26+
const ComunityContent = ({ curRoute }) => {
27+
const { subPath } = curRoute
28+
switch (subPath) {
29+
case ROUTE.REPOS: {
30+
return <ReposThread />
31+
}
32+
case ROUTE.USERS: {
33+
return <UsersThread />
34+
}
35+
case ROUTE.VIDEOS: {
36+
return <VideosThread />
37+
}
38+
case ROUTE.JOBS: {
39+
return <JobsThread />
40+
}
41+
case ROUTE.WIKI: {
42+
return <WikiThread />
43+
}
44+
case ROUTE.CHEATSHEET: {
45+
return <CheatsheetThread />
46+
}
47+
default: {
48+
return <PostsThread />
49+
}
50+
}
51+
}
52+
53+
class CommunityContentContainer extends React.Component {
54+
componentDidMount() {
55+
const { communityContent } = this.props
56+
logic.init(communityContent)
57+
}
58+
59+
componentWillUnmount() {
60+
logic.uninit()
61+
}
62+
63+
render() {
64+
const { communityContent } = this.props
65+
const { curRoute } = communityContent
66+
67+
return (
68+
<Wrapper>
69+
<ComunityContent curRoute={curRoute} />
70+
</Wrapper>
71+
)
72+
}
73+
}
74+
75+
export default inject(storePlug('communityContent'))(
76+
observer(CommunityContentContainer)
77+
)

containers/CommunityContent/logic.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// import R from 'ramda'
2+
3+
import { makeDebugger, $solver, asyncErr, ERR } from '../../utils'
4+
5+
import SR71 from '../../utils/network/sr71'
6+
// import S from './schema'
7+
8+
const sr71$ = new SR71()
9+
let sub$ = null
10+
let store = null
11+
12+
/* eslint-disable-next-line */
13+
const debug = makeDebugger('L:CommunityContent')
14+
15+
export function someMethod() {}
16+
17+
// ###############################
18+
// Data & Error handlers
19+
// ###############################
20+
21+
const DataSolver = []
22+
const ErrSolver = [
23+
{
24+
match: asyncErr(ERR.CRAPHQL),
25+
action: ({ details }) => {
26+
debug('ERR.CRAPHQL -->', details)
27+
},
28+
},
29+
{
30+
match: asyncErr(ERR.TIMEOUT),
31+
action: ({ details }) => {
32+
debug('ERR.TIMEOUT -->', details)
33+
},
34+
},
35+
{
36+
match: asyncErr(ERR.NETWORK),
37+
action: ({ details }) => {
38+
debug('ERR.NETWORK -->', details)
39+
},
40+
},
41+
]
42+
43+
export function init(_store) {
44+
store = _store
45+
46+
debug(store)
47+
if (sub$) return false
48+
sub$ = sr71$.data().subscribe($solver(DataSolver, ErrSolver))
49+
}
50+
51+
export function uninit() {
52+
if (!sub$) return false
53+
debug('===== do uninit')
54+
sub$.unsubscribe()
55+
sub$ = null
56+
}

containers/CommunityContent/schema.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import gql from 'graphql-tag'
2+
3+
const simpleMutation = gql`
4+
mutation($id: ID!) {
5+
post(id: $id) {
6+
id
7+
}
8+
}
9+
`
10+
const simpleQuery = gql`
11+
query($filter: filter!) {
12+
post(id: $id) {
13+
id
14+
}
15+
}
16+
`
17+
18+
const schema = {
19+
simpleMutation,
20+
simpleQuery,
21+
}
22+
23+
export default schema

containers/CommunityContent/store.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* CommunityContent store
3+
*
4+
*/
5+
6+
import { types as t, getParent } from 'mobx-state-tree'
7+
// import R from 'ramda'
8+
9+
import { markStates, makeDebugger } from '../../utils'
10+
/* eslint-disable-next-line */
11+
const debug = makeDebugger('S:CommunityContent')
12+
13+
const CommunityContent = t
14+
.model('CommunityContent', {})
15+
.views(self => ({
16+
get root() {
17+
return getParent(self)
18+
},
19+
get curRoute() {
20+
return self.root.curRoute
21+
},
22+
}))
23+
.actions(self => ({
24+
markState(sobj) {
25+
markStates(sobj, self)
26+
},
27+
}))
28+
29+
export default CommunityContent
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* CommunityContent store test
3+
*
4+
*/
5+
6+
// import R from 'ramda'
7+
8+
// import CommunityContent from '../index'
9+
10+
it('TODO: store test CommunityContent', () => {
11+
expect(1 + 1).toBe(2)
12+
})

containers/Content/index.js

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,11 @@
77
import React from 'react'
88
import { inject, observer } from 'mobx-react'
99

10+
import CommunityContent from '../CommunityContent'
1011
import CommunitiesContent from '../CommunitiesContent'
1112
import CheatSheetContent from '../CheatSheetContent'
12-
import PostContent from '../PostContent'
13-
import JobContent from '../JobContent'
14-
import VideoContent from '../VideoContent'
15-
import RepoContent from '../RepoContent'
1613
import UserContent from '../UserContent'
1714

18-
import CommunityContent from '../../components/CommunityContent'
1915
import { Wrapper } from './styles'
2016

2117
import { makeDebugger, storePlug, ROUTE } from '../../utils'
@@ -33,23 +29,11 @@ const renderContent = curRoute => {
3329
case ROUTE.COMMUNITIES: {
3430
return <CommunitiesContent />
3531
}
36-
case ROUTE.POST: {
37-
return <PostContent />
38-
}
39-
case ROUTE.JOB: {
40-
return <JobContent />
41-
}
42-
case ROUTE.VIDEO: {
43-
return <VideoContent />
44-
}
45-
case ROUTE.REPO: {
46-
return <RepoContent />
47-
}
4832
case ROUTE.USER: {
4933
return <UserContent />
5034
}
5135
default: {
52-
return <CommunityContent curRoute={curRoute} />
36+
return <CommunityContent />
5337
}
5438
}
5539
}

containers/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ export { default as UserBanner } from './UserBanner'
3232
export { default as CommunityBanner } from './CommunityBanner'
3333
export { default as CommunitiesBanner } from './CommunitiesBanner'
3434
/* contents */
35-
export { default as UserContent } from './UserContent'
35+
export { default as CommunityContent } from './CommunityContent'
3636
export { default as CommunitiesContent } from './CommunitiesContent'
37+
export { default as UserContent } from './UserContent'
3738
export { default as PostContent } from './PostContent'
3839
export { default as JobContent } from './JobContent'
3940
export { default as VideoContent } from './VideoContent'

pages/community.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import {
1616
Route,
1717
BodyLayout,
1818
Header,
19-
Banner,
20-
Content,
19+
CommunityBanner,
20+
CommunityContent,
2121
Footer,
2222
} from '../containers'
2323

@@ -181,8 +181,8 @@ export default class PageCommunity extends React.Component {
181181
<Doraemon />
182182
<BodyLayout>
183183
<Header />
184-
<Banner />
185-
<Content />
184+
<CommunityBanner />
185+
<CommunityContent />
186186
<Footer />
187187
</BodyLayout>
188188
</MultiLanguage>

0 commit comments

Comments
 (0)