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

Commit cc444bf

Browse files
authored
refactor(publish-workflow): add illegal & non-author alert (#1188)
* refactor(user-page): load works only when use is maker * refactor(comments): audition concept * refactor(article-editor): not author warning * refactor(article-editor): add IllegalWarning concept * refactor(article-editor): extract IllegalWarning to widget * refactor(works): basic publish rules * refactor(works): publish rules ux * refactor(works): publish text adjust * refactor(works): teammates manage * refactor(works): allow allow author edit
1 parent 5ae49dc commit cc444bf

File tree

60 files changed

+819
-212
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+819
-212
lines changed

src/containers/content/UserContent/logic.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ const loadEditableCommunities = () => {
7878
sr71$.query(S.editableCommunities, { login, filter })
7979
}
8080

81+
const loadPublishedWorks = (): void => {
82+
const { viewingUser: user } = store
83+
if (!user.isMaker) return
84+
85+
const filter = { page: 1, size: 10 }
86+
sr71$.query(S.pagedPublishedWorks, { login: user.login, filter })
87+
}
88+
8189
const DataSolver = [
8290
{
8391
match: asyncRes('follow'),
@@ -91,6 +99,13 @@ const DataSolver = [
9199
match: asyncRes('editableCommunities'),
92100
action: ({ editableCommunities }) => {
93101
store.mark({ pagedEditableCommunities: editableCommunities })
102+
loadPublishedWorks()
103+
},
104+
},
105+
{
106+
match: asyncRes('pagedPublishedWorks'),
107+
action: ({ pagedPublishedWorks }) => {
108+
store.mark({ pagedWorks: pagedPublishedWorks })
94109
},
95110
},
96111
{

src/containers/content/UserContent/schema.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,27 @@ const editableCommunities = gql`
3636
}
3737
`
3838

39+
const pagedPublishedWorks = `
40+
query($login: String!, $filter: PagedFilter!) {
41+
pagedPublishedWorks(login: $login, filter: $filter) {
42+
entries {
43+
id
44+
title
45+
cover
46+
desc
47+
homeLink
48+
}
49+
${F.pagi}
50+
}
51+
}
52+
`
53+
3954
const schema = {
4055
follow,
4156
undoFollow,
4257
user,
4358
editableCommunities,
59+
pagedPublishedWorks,
4460
}
4561

4662
export default schema

src/containers/editor/ArticleEditor/index.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import { METRIC } from '@/constant'
1010
import { buildLog } from '@/utils/logger'
1111
import { pluggedIn } from '@/utils/mobx'
1212

13-
import { ArchiveAlert } from '@/widgets/dynamic'
13+
import { ArchiveAlert, IllegalWarning } from '@/widgets/dynamic'
1414

15+
import NoticeBar from '@/widgets/NoticeBar'
1516
import CommunityTagSetter from '@/containers/tool/CommunityTagSetter'
1617
import RichEditor from '@/containers/editor/RichEditor'
1718
import CommunityBadgeSelector from '@/widgets/CommunityBadgeSelector'
@@ -53,8 +54,11 @@ const ArticleEditorContainer: FC<TProps> = ({
5354
texts,
5455
thread,
5556
editData,
57+
viewingArticle,
58+
allowEdit,
5659
} = store
5760

61+
const { meta } = viewingArticle
5862
const { title, body } = editData
5963

6064
const initEditor = mode === 'publish' || body !== '{}'
@@ -70,6 +74,14 @@ const ArticleEditorContainer: FC<TProps> = ({
7074
/>
7175
)}
7276
<ContentWrapper>
77+
{!allowEdit && (
78+
<NoticeBar
79+
type="notice"
80+
content="只有作者可以编辑本内容。"
81+
left={25}
82+
/>
83+
)}
84+
7385
{isArchived && (
7486
<ArchiveAlert date={archivedAt} top={12} bottom={20} left={25} />
7587
)}
@@ -94,6 +106,13 @@ const ArticleEditorContainer: FC<TProps> = ({
94106
</ContentWrapper>
95107
<div>
96108
<CommunityBadgeSelector community={communityData} mode={mode} />
109+
110+
{mode === 'update' && !meta.isLegal && (
111+
<IllegalWarning
112+
illegalReason={meta.illegalReason}
113+
illegalWords={meta.illegalWords}
114+
/>
115+
)}
97116
<PublishRules thread={thread} />
98117
</div>
99118
</InnerWrapper>

src/containers/editor/ArticleEditor/schema.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ const post = gql`
176176
copyRight
177177
archivedAt
178178
isArchived
179+
author {
180+
${F.author}
181+
}
179182
180183
originalCommunity {
181184
${F.community}
@@ -187,6 +190,9 @@ const post = gql`
187190
188191
meta {
189192
thread
193+
isLegal
194+
illegalReason
195+
illegalWords
190196
}
191197
192198
document {
@@ -206,6 +212,10 @@ const job = gql`
206212
archivedAt
207213
isArchived
208214
215+
author {
216+
${F.author}
217+
}
218+
209219
originalCommunity {
210220
${F.community}
211221
}
@@ -216,6 +226,9 @@ const job = gql`
216226
217227
meta {
218228
thread
229+
isLegal
230+
illegalReason
231+
illegalWords
219232
}
220233
221234
document {
@@ -244,6 +257,9 @@ const radar = gql`
244257
245258
meta {
246259
thread
260+
isLegal
261+
illegalReason
262+
illegalWords
247263
}
248264
249265
document {

src/containers/editor/ArticleEditor/store.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type {
1414
TTag,
1515
TArticleThread,
1616
TSubmitState,
17+
TAccount,
1718
} from '@/spec'
1819
import { ARTICLE_THREAD } from '@/constant'
1920

@@ -51,10 +52,22 @@ const ArticleEditor = T.model('ArticleEditor', {
5152
const root = getParent(self) as TRootStore
5253
return root.account.isLogin
5354
},
55+
get accountInfo(): TAccount {
56+
const root = getParent(self) as TRootStore
57+
return root.account.accountInfo
58+
},
5459
get viewingArticle(): TArticle {
5560
const root = getParent(self) as TRootStore
5661
return toJS(root.viewing.viewingArticle)
5762
},
63+
get allowEdit(): boolean {
64+
const slf = self as TStore
65+
const { mode, accountInfo, viewingArticle } = slf
66+
67+
return (
68+
mode === 'update' && accountInfo.login === viewingArticle.author?.login
69+
)
70+
},
5871
get thread(): TArticleThread {
5972
const root = getParent(self) as TRootStore
6073
return toJS(root.viewing.viewingThread)
@@ -138,7 +151,17 @@ const ArticleEditor = T.model('ArticleEditor', {
138151
},
139152
get submitState(): TSubmitState {
140153
const slf = self as TStore
141-
return pick(['publishing', 'publishDone', 'isReady', 'isArchived'], slf)
154+
return pick(
155+
[
156+
'publishing',
157+
'publishDone',
158+
'isReady',
159+
'isArchived',
160+
'mode',
161+
'isArticleAuthor',
162+
],
163+
slf,
164+
)
142165
},
143166
}))
144167
.actions((self) => ({

src/containers/editor/WorksEditor/Content/BasicInfoPart/index.tsx

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { FC, memo } from 'react'
22
import { filter, includes } from 'ramda'
33

4-
import type { TSelectOption } from '@/spec'
4+
import type { TSelectOption, TUser } from '@/spec'
55

66
import Checker from '@/widgets/Checker'
77
import Select from '@/widgets/Select'
@@ -32,6 +32,10 @@ import {
3232
checkerOnChange,
3333
addSocial,
3434
citiesOnChange,
35+
searchUser,
36+
addTeammate,
37+
removeTeammate,
38+
closeSearchedUsers,
3539
} from '../../logic'
3640

3741
const cityOptions = [
@@ -53,9 +57,14 @@ const cityOptions = [
5357
type TProps = {
5458
inputData: TInputData
5559
socialOptions: TSelectOption[]
60+
searchedUsers: TUser[]
5661
}
5762

58-
const BasicInfoPart: FC<TProps> = ({ inputData, socialOptions }) => {
63+
const BasicInfoPart: FC<TProps> = ({
64+
inputData,
65+
socialOptions,
66+
searchedUsers,
67+
}) => {
5968
const {
6069
cover,
6170
title,
@@ -198,7 +207,16 @@ const BasicInfoPart: FC<TProps> = ({ inputData, socialOptions }) => {
198207
<Section>
199208
<Label>团队成员</Label>
200209
<TeamsWrapper>
201-
<UserList users={teammates} layout="create-works" withSetter />
210+
<UserList
211+
users={teammates}
212+
layout="create-works"
213+
onAdd={addTeammate}
214+
onRemove={removeTeammate}
215+
onClose={closeSearchedUsers}
216+
onSearch={searchUser}
217+
searchedUsers={searchedUsers}
218+
withSetter
219+
/>
202220
</TeamsWrapper>
203221
</Section>
204222
</Wrapper>

src/containers/editor/WorksEditor/Content/NamePart.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { FC, memo, useEffect, useRef } from 'react'
22

33
import { TEditMode } from '@/spec'
4-
import type { TInputData } from '../spec'
4+
import { nilOrEmpty } from '@/utils/validator'
5+
6+
import PublishRules from './PublishRules'
57

8+
import type { TInputData } from '../spec'
69
import { Wrapper, Input, Title, Desc } from '../styles/content/name_part'
710
import { inputOnChange } from '../logic'
811

@@ -26,12 +29,13 @@ const NamePart: FC<TProps> = ({ mode, inputData }) => {
2629
return (
2730
<Wrapper ref={ref}>
2831
{mode === 'publish' ? <Title>发布作品</Title> : <Title>更新作品</Title>}
29-
<Desc>你(们)的作品名称是</Desc>
32+
<Desc>你(们)的作品名字是</Desc>
3033
<Input
3134
value={title || ''}
3235
onChange={(e) => inputOnChange(e, 'title')}
3336
autoFocus
3437
/>
38+
{nilOrEmpty(title) && <PublishRules />}
3539
</Wrapper>
3640
)
3741
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { FC, memo, useState, Fragment, useCallback } from 'react'
2+
import Link from 'next/link'
3+
4+
import { ROUTE } from '@/constant'
5+
6+
import {
7+
Wrapper,
8+
ToggleTitle,
9+
Section,
10+
DoTitle,
11+
DoNotTitle,
12+
Ul,
13+
Li,
14+
Bold,
15+
Strike,
16+
TextLink,
17+
} from '../styles/content/publish_rules'
18+
19+
const PublishRules: FC = () => {
20+
const [showDetail, setShowDetail] = useState(false)
21+
22+
const toggleDetail = useCallback(() => {
23+
setShowDetail(!showDetail)
24+
}, [showDetail])
25+
26+
return (
27+
<Wrapper>
28+
<ToggleTitle onClick={toggleDetail} showDetail={showDetail}>
29+
{!showDetail ? (
30+
<Fragment>发布须知</Fragment>
31+
) : (
32+
<Fragment>收起</Fragment>
33+
)}
34+
</ToggleTitle>
35+
{showDetail && (
36+
<Fragment>
37+
<Section>
38+
<DoTitle>欢迎发布:</DoTitle>
39+
<Ul>
40+
<Li>
41+
各平台能提高开发者 / 设计师 / 产品生产力的软件工具,插件或服务。
42+
</Li>
43+
<Li>你参与编写和设计的库,框架等各种作品。</Li>
44+
<Li>字体,图标,UI/UX模板手稿等人机交互类的设计资源或服务。</Li>
45+
<Li> 各类辅助管理工具或服务。 </Li>
46+
<Li>品牌,运营,增长,统计等工具或服务。</Li>
47+
<Li>硬件产品,物联网,VR, 机器人等类似项目。</Li>
48+
</Ul>
49+
</Section>
50+
<Section>
51+
<DoNotTitle>不适合发布:</DoNotTitle>
52+
<Ul>
53+
<Li>
54+
你没有参与的项目。如果你是个喜欢收集的 Hunter,
55+
<Link href={`/${ROUTE.COOL_GUIDE}`} passHref>
56+
<TextLink>酷导航</TextLink>
57+
</Link>
58+
是最合适的地方。
59+
</Li>
60+
<Li>
61+
Markdown 类项目, 包括但不限于排行榜, 资料收集,
62+
面经题库,课程培训等。
63+
</Li>
64+
<Li>聚合类项目,包括但不限于 xx 导航,xx 热榜等。</Li>
65+
<Li>后台管理模板,xx 商城系统,xx 手脚架。</Li>
66+
<Li>
67+
和开发者(广义上包括 IT 从业者)关系不大的项目。
68+
简单来讲,如果你要发布的项目主要目标用户不是 IT
69+
从业者,那么通常就不适合。 这里是垂直社区,
70+
<Bold>不是 APP 应用商店</Bold>
71+
</Li>
72+
<Li>
73+
三天或一周时间写的 <Strike>Demo</Strike> 项目, 天才例外。
74+
</Li>
75+
</Ul>
76+
</Section>
77+
</Fragment>
78+
)}
79+
</Wrapper>
80+
)
81+
}
82+
83+
export default memo(PublishRules)

0 commit comments

Comments
 (0)