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

Commit 5b7e1cb

Browse files
committed
feat(Pages): add Repo page for SSR & refactor
1 parent 271e03d commit 5b7e1cb

File tree

32 files changed

+674
-66
lines changed

32 files changed

+674
-66
lines changed

components/ContentBanner/ReactionNumbers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ const ReactionNumbers = ({ data: { views, favoritedCount, starredCount } }) => (
1616
<NumberTitle dead>浏览</NumberTitle>
1717
<NumberItem dead>{prettyNum(views)}</NumberItem>
1818
</NumberSection>
19-
<NumberDivider />
2019
{starredCount >= 0 ? (
2120
<React.Fragment>
21+
<NumberDivider />
2222
<NumberSection>
2323
<NumberTitle>喜欢</NumberTitle>
2424
<NumberItem>{numberWithCommas(starredCount)}</NumberItem>

containers/Banner/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import UserBanner from '../UserBanner'
1111
import PostBanner from '../PostBanner'
1212
import JobBanner from '../JobBanner'
1313
import VideoBanner from '../VideoBanner'
14+
import RepoBanner from '../RepoBanner'
1415
import CommunitiesBanner from '../CommunitiesBanner'
1516
import CommunityBanner from '../CommunityBanner'
1617

@@ -45,6 +46,9 @@ const BannerContent = ({ curRoute }) => {
4546
case ROUTE.VIDEO: {
4647
return <VideoBanner />
4748
}
49+
case ROUTE.REPO: {
50+
return <RepoBanner />
51+
}
4852
case ROUTE.USER: {
4953
return <UserBanner />
5054
}

containers/Content/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import CheatSheetContent from '../CheatSheetContent'
1212
import PostContent from '../PostContent'
1313
import JobContent from '../JobContent'
1414
import VideoContent from '../VideoContent'
15+
import RepoContent from '../RepoContent'
1516
import UserContent from '../UserContent'
1617

1718
import CommunityContent from '../../components/CommunityContent'
@@ -42,6 +43,9 @@ const renderContent = curRoute => {
4243
case ROUTE.VIDEO: {
4344
return <VideoContent />
4445
}
46+
case ROUTE.REPO: {
47+
return <RepoContent />
48+
}
4549
case ROUTE.USER: {
4650
return <UserContent />
4751
}

containers/RepoBanner/index.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
*
3+
* RepoBanner
4+
*
5+
*/
6+
7+
import React from 'react'
8+
import { inject, observer } from 'mobx-react'
9+
10+
import { ContentBanner } from '../../components'
11+
12+
import { makeDebugger, storePlug } from '../../utils'
13+
14+
import * as logic from './logic'
15+
/* eslint-disable no-unused-vars */
16+
const debug = makeDebugger('C:RepoBanner')
17+
/* eslint-enable no-unused-vars */
18+
19+
class RepoBannerContainer extends React.Component {
20+
componentWillMount() {
21+
const { repoBanner } = this.props
22+
logic.init(repoBanner)
23+
}
24+
25+
render() {
26+
const { repoBanner } = this.props
27+
const { viewingRepoData } = repoBanner
28+
29+
return <ContentBanner data={viewingRepoData} />
30+
}
31+
}
32+
33+
export default inject(storePlug('repoBanner'))(observer(RepoBannerContainer))

containers/RepoBanner/logic.js

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

containers/RepoBanner/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/RepoBanner/store.js

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

containers/RepoBanner/styles/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import styled from 'styled-components'
2+
3+
// import Img from '../../../components/Img'
4+
// import { theme } from '../../../utils'
5+
6+
export const Wrapper = styled.div``
7+
export const Title = styled.div``
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// import React from 'react'
2+
// import { shallow } from 'enzyme'
3+
4+
// import RepoBanner from '../index'
5+
6+
describe('TODO <RepoBanner />', () => {
7+
it('Expect to have unit tests specified', () => {
8+
expect(true).toEqual(true)
9+
})
10+
})
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* RepoBanner store test
3+
*
4+
*/
5+
6+
// import R from 'ramda'
7+
8+
// import RepoBanner from '../index'
9+
10+
it('TODO: store test RepoBanner', () => {
11+
expect(1 + 1).toBe(2)
12+
})

0 commit comments

Comments
 (0)