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

Commit f81c7e5

Browse files
committed
refactor(UserPublished): support videos/jobs/repos
1 parent acceb48 commit f81c7e5

File tree

10 files changed

+291
-31
lines changed

10 files changed

+291
-31
lines changed

components/JobItem/styles/company_info.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export const Footer = styled.div`
3131
color: ${theme('thread.articleDigest')};
3232
`
3333
export const Title = styled.div`
34+
color: ${theme('thread.articleTitle')};
3435
font-size: 1rem;
3536
`
3637
export const StatesWrapper = styled.div`

components/JobItem/styles/job_info.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ export const Middle = styled.div`
1515
padding: 5px 0;
1616
margin-bottom: 2px;
1717
`
18-
export const Footer = styled.div``
18+
export const Footer = styled.div`
19+
color: ${theme('thread.articleDigest')};
20+
`
1921

2022
export const Title = styled.div`
23+
color: ${theme('thread.articleTitle')};
2124
font-size: 1rem;
2225
width: 90%;
2326
`

containers/UserPublished/PublishedContents.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,25 @@ import React from 'react'
22

33
// import { Wrapper } from './styles'
44
import PublishedPosts from './PublishedPosts'
5+
import PublishedJobs from './PublishedJobs'
6+
import PublishedVideos from './PublishedVideos'
7+
import PublishedRepos from './PublishedRepos'
58

69
import { THREAD } from '../../utils'
710

811
const PublishedContents = ({ thread, curView, entries }) => {
912
switch (thread) {
10-
case THREAD.POST: {
11-
return <PublishedPosts entries={entries} curView={curView} />
13+
case THREAD.JOB: {
14+
return <PublishedJobs entries={entries} curView={curView} />
15+
}
16+
case THREAD.VIDEO: {
17+
return <PublishedVideos entries={entries} curView={curView} />
18+
}
19+
case THREAD.REPO: {
20+
return <PublishedRepos entries={entries} curView={curView} />
1221
}
1322
default: {
14-
return <h3>other published contents</h3>
23+
return <PublishedPosts entries={entries} curView={curView} />
1524
}
1625
}
1726
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React from 'react'
2+
3+
import { JobItemLoading, JobItem } from '../../components'
4+
5+
import { uid, TYPE } from '../../utils'
6+
7+
const PublishedJobs = ({ entries, curView, active }) => {
8+
switch (curView) {
9+
case TYPE.RESULT: {
10+
return (
11+
<React.Fragment>
12+
{entries.map(entry => (
13+
<JobItem
14+
key={uid.gen()}
15+
entry={entry}
16+
active={active}
17+
onTitleSelect={console.log}
18+
/>
19+
))}
20+
</React.Fragment>
21+
)
22+
}
23+
default:
24+
return <JobItemLoading num={4} />
25+
}
26+
}
27+
28+
export default PublishedJobs
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React from 'react'
2+
3+
import { RepoItemLoading, RepoItem } from '../../components'
4+
5+
import { uid, TYPE } from '../../utils'
6+
7+
const PublishedRepos = ({ entries, curView, active }) => {
8+
switch (curView) {
9+
case TYPE.RESULT: {
10+
return (
11+
<React.Fragment>
12+
{entries.map(entry => (
13+
<RepoItem
14+
key={uid.gen()}
15+
entry={entry}
16+
active={active}
17+
onTitleSelect={console.log}
18+
/>
19+
))}
20+
</React.Fragment>
21+
)
22+
}
23+
default:
24+
return <RepoItemLoading num={4} />
25+
}
26+
}
27+
28+
export default PublishedRepos
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React from 'react'
2+
3+
import { VideoItemLoading, VideoItem } from '../../components'
4+
5+
import { uid, TYPE } from '../../utils'
6+
7+
const PublishedVideos = ({ entries, curView, active }) => {
8+
switch (curView) {
9+
case TYPE.RESULT: {
10+
return (
11+
<React.Fragment>
12+
{entries.map(entry => (
13+
<VideoItem
14+
key={uid.gen()}
15+
entry={entry}
16+
active={active}
17+
onTitleSelect={console.log}
18+
/>
19+
))}
20+
</React.Fragment>
21+
)
22+
}
23+
default:
24+
return <VideoItemLoading num={4} />
25+
}
26+
}
27+
28+
export default PublishedVideos

containers/UserPublished/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ class UserPublishedContainer extends React.Component {
2727

2828
render() {
2929
const { userPublished } = this.props
30-
const { pagedPostsData, curView, curThread } = userPublished
30+
const { pagedData, curView, curThread } = userPublished
3131

32-
const { entries, totalCount, pageNumber, pageSize } = pagedPostsData
32+
const { entries, totalCount, pageNumber, pageSize } = pagedData
3333

3434
return (
3535
<div>
@@ -41,17 +41,19 @@ class UserPublishedContainer extends React.Component {
4141
lookLike="box"
4242
/>
4343
</ThreadWrapper>
44+
4445
<PublishedContents
4546
entries={entries}
4647
curView={curView}
4748
thread={curThread}
4849
/>
50+
4951
<Pagi
5052
left="-20px"
5153
pageNumber={pageNumber}
5254
pageSize={pageSize}
5355
totalCount={totalCount}
54-
onChange={logic.onPageChange}
56+
onChange={logic.reload}
5557
/>
5658
</div>
5759
)

containers/UserPublished/logic.js

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,44 @@ const debug = makeDebugger('L:UserPublished')
2323

2424
let store = null
2525

26-
export const loadPosts = (page = 1) => {
27-
const args = {
26+
const beforeQuery = page => {
27+
store.markState({ curView: TYPE.LOADING })
28+
// args
29+
return {
2830
userId: store.viewingUser.id,
2931
filter: pagedFilter(page),
3032
}
31-
32-
store.markState({ curView: TYPE.LOADING })
33+
}
34+
export const loadPosts = (page = 1) => {
35+
const args = beforeQuery(page)
3336
sr71$.query(S.publishedPosts, args)
3437
}
3538

36-
export function onPageChange(page) {
39+
export const loadJobs = (page = 1) => {
40+
const args = beforeQuery(page)
41+
sr71$.query(S.publishedJobs, args)
42+
}
43+
44+
export const loadVideos = (page = 1) => {
45+
const args = beforeQuery(page)
46+
sr71$.query(S.publishedVideos, args)
47+
}
48+
49+
export const loadRepos = (page = 1) => {
50+
const args = beforeQuery(page)
51+
sr71$.query(S.publishedRepos, args)
52+
}
53+
54+
export function reload(page) {
3755
switch (store.curThread) {
3856
case THREAD.JOB: {
39-
return debug('load job')
57+
return loadJobs(page)
58+
}
59+
case THREAD.VIDEO: {
60+
return loadVideos(page)
61+
}
62+
case THREAD.REPO: {
63+
return loadRepos(page)
4064
}
4165
default: {
4266
return loadPosts(page)
@@ -47,6 +71,7 @@ export function onPageChange(page) {
4771
export function onThreadChange(curThread) {
4872
// TODO: markRoute
4973
store.markState({ curThread })
74+
reload()
5075
}
5176

5277
// ###############################
@@ -56,13 +81,19 @@ export function onThreadChange(curThread) {
5681
const DataSolver = [
5782
{
5883
match: asyncRes('publishedPosts'),
59-
action: ({ publishedPosts: pagedPosts }) => {
60-
let curView = TYPE.RESULT
61-
if (pagedPosts.entries.length === 0) {
62-
curView = TYPE.RESULT_EMPTY
63-
}
64-
store.markState({ curView, pagedPosts })
65-
},
84+
action: ({ publishedPosts }) => store.markPagedData(publishedPosts),
85+
},
86+
{
87+
match: asyncRes('publishedJobs'),
88+
action: ({ publishedJobs }) => store.markPagedData(publishedJobs),
89+
},
90+
{
91+
match: asyncRes('publishedVideos'),
92+
action: ({ publishedVideos }) => store.markPagedData(publishedVideos),
93+
},
94+
{
95+
match: asyncRes('publishedRepos'),
96+
action: ({ publishedRepos }) => store.markPagedData(publishedRepos),
6697
},
6798
]
6899
const ErrSolver = [

containers/UserPublished/schema.js

Lines changed: 96 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
import gql from 'graphql-tag'
22

3-
const simpleMutation = gql`
4-
mutation($id: ID!) {
5-
post(id: $id) {
6-
id
7-
}
8-
}
9-
`
103
const publishedPosts = gql`
114
query($userId: ID!, $filter: PagedFilter!) {
125
publishedPosts(userId: $userId, filter: $filter) {
@@ -36,10 +29,105 @@ const publishedPosts = gql`
3629
}
3730
}
3831
`
32+
const publishedJobs = gql`
33+
query($userId: ID!, $filter: PagedFilter!) {
34+
publishedJobs(userId: $userId, filter: $filter) {
35+
entries {
36+
id
37+
title
38+
company
39+
companyLogo
40+
tags {
41+
id
42+
title
43+
color
44+
}
45+
author {
46+
id
47+
nickname
48+
avatar
49+
}
50+
views
51+
insertedAt
52+
updatedAt
53+
}
54+
totalPages
55+
totalCount
56+
pageSize
57+
pageNumber
58+
}
59+
}
60+
`
61+
const publishedVideos = gql`
62+
query($userId: ID!, $filter: PagedFilter!) {
63+
publishedVideos(userId: $userId, filter: $filter) {
64+
entries {
65+
id
66+
title
67+
poster
68+
desc
69+
duration
70+
source
71+
views
72+
originalAuthor
73+
originalAuthorLink
74+
author {
75+
id
76+
avatar
77+
nickname
78+
}
79+
insertedAt
80+
publishAt
81+
}
82+
totalPages
83+
totalCount
84+
pageSize
85+
pageNumber
86+
}
87+
}
88+
`
89+
const publishedRepos = gql`
90+
query($userId: ID!, $filter: PagedFilter!) {
91+
publishedRepos(userId: $userId, filter: $filter) {
92+
entries {
93+
id
94+
title
95+
ownerName
96+
desc
97+
license
98+
releaseTag
99+
contributors {
100+
avatar
101+
htmlUrl
102+
nickname
103+
}
104+
starCount
105+
forkCount
106+
primaryLanguage {
107+
name
108+
color
109+
}
110+
views
111+
author {
112+
id
113+
avatar
114+
nickname
115+
}
116+
insertedAt
117+
}
118+
totalPages
119+
totalCount
120+
pageSize
121+
pageNumber
122+
}
123+
}
124+
`
39125

40126
const schema = {
41-
simpleMutation,
42127
publishedPosts,
128+
publishedJobs,
129+
publishedVideos,
130+
publishedRepos,
43131
}
44132

45133
export default schema

0 commit comments

Comments
 (0)