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

Commit 6a94f78

Browse files
authored
refactor(redesign): community sub/unSub to thread right side, sticky style (#1008)
* refactor(redesign): CommunityBadge concept * refactor(redesign): move subscribe/unsubscribe logic to JoinBadge * refactor(joinBadge): naming and re-org
1 parent 7c7c337 commit 6a94f78

File tree

22 files changed

+407
-116
lines changed

22 files changed

+407
-116
lines changed
Lines changed: 6 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,15 @@
11
import React from 'react'
22

3-
// import { ICON_CMD } from '@/config'
4-
// import { Wrapper } from './styles'
5-
import Tooltip from '@/components/Tooltip'
63
import { NumberTitle } from './styles'
7-
import { PopoverInfo, PopTitle, PopDesc } from './styles/subscribed_title'
84

9-
const SubscribedBtn = ({ community, onUndoSubscribe }) => {
10-
if (community.raw === 'home') {
11-
return (
12-
<NumberTitle small readOnly>
13-
已加入
14-
</NumberTitle>
15-
)
16-
}
17-
18-
return (
19-
<Tooltip
20-
placement="bottom"
21-
content={
22-
<PopoverInfo>
23-
<PopTitle>点击可退出</PopTitle>
24-
<PopDesc>退出后该社区将不会出现在你的左侧列表中</PopDesc>
25-
</PopoverInfo>
26-
}
27-
>
28-
<NumberTitle onClick={() => onUndoSubscribe(community)} small>
29-
已加入
30-
</NumberTitle>
31-
</Tooltip>
32-
)
33-
}
34-
35-
const SubscribedTitle = ({ community, onSubscribe, onUndoSubscribe }) => (
36-
<>
37-
{community.viewerHasSubscribed ? (
38-
<SubscribedBtn community={community} onUndoSubscribe={onUndoSubscribe} />
5+
const SubscribedTitle = ({ viewerHasSubscribed }) => (
6+
<React.Fragment>
7+
{viewerHasSubscribed ? (
8+
<NumberTitle>已加入</NumberTitle>
399
) : (
40-
<Tooltip
41-
placement="bottom"
42-
content={
43-
<PopoverInfo>
44-
<PopTitle>点击加入</PopTitle>
45-
<PopDesc>加入后该社区将会出现在你的左侧列表中</PopDesc>
46-
</PopoverInfo>
47-
}
48-
>
49-
<NumberTitle onClick={() => onSubscribe(community)}>加入</NumberTitle>
50-
</Tooltip>
10+
<NumberTitle>加入</NumberTitle>
5111
)}
52-
</>
12+
</React.Fragment>
5313
)
5414

5515
export default React.memo(SubscribedTitle)

src/components/CommunityStatesPad/index.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ const log = buildLog('c:CommunityStatesPad:index')
2929

3030
const CommunityStatesPad = ({
3131
community,
32-
onSubscribe,
33-
onUndoSubscribe,
3432
onShowEditorList,
3533
onShowSubscriberList,
3634
withoutFounding,
@@ -52,11 +50,7 @@ const CommunityStatesPad = ({
5250
<Wrapper>
5351
<NumberSection active={viewerHasSubscribed}>
5452
{!isMobile && (
55-
<SubscribedTitle
56-
community={community}
57-
onSubscribe={onSubscribe}
58-
onUndoSubscribe={onUndoSubscribe}
59-
/>
53+
<SubscribedTitle viewerHasSubscribed={viewerHasSubscribed} />
6054
)}
6155
<NumberGroup
6256
count={subscribersCount}
@@ -103,8 +97,6 @@ CommunityStatesPad.propTypes = {
10397
jobsCount: T.number,
10498
viewerHasSubscribed: T.bool,
10599
}),
106-
onSubscribe: T.func,
107-
onUndoSubscribe: T.func,
108100
onShowEditorList: T.func,
109101
onShowSubscriberList: T.func,
110102
withoutFounding: T.bool,
@@ -120,8 +112,6 @@ CommunityStatesPad.defaultProps = {
120112
jobsCount: 0,
121113
viewerHasSubscribed: false,
122114
},
123-
onSubscribe: log,
124-
onUndoSubscribe: log,
125115
onShowEditorList: log,
126116
onShowSubscriberList: log,
127117
withoutFounding: true,

src/components/Tooltip/ConfirmFooter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react'
22

3-
import { Button } from '@/components/Buttons'
3+
import Button from '@/components/Buttons/Button'
44
import { Space } from '@/components/Common'
55

66
import { FOOTER_BEHAVIOR } from './constant'

src/containers/digest/CommunityDigest/DigestView/ColumnView/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react'
22
import { contains } from 'ramda'
3+
import { Waypoint } from 'react-waypoint'
34

45
import { ICON_CMD } from '@/config'
56
import { NON_FILL_COMMUNITY } from '@/constant'
@@ -31,10 +32,9 @@ import {
3132

3233
import {
3334
tabOnChange,
34-
onSubscribe,
35-
onUndoSubscribe,
3635
onShowEditorList,
3736
onShowSubscriberList,
37+
setViewport,
3838
} from '../../logic'
3939

4040
const CommunityLogoHolder = `${ICON_CMD}/community_logo_holder.svg`
@@ -99,8 +99,6 @@ const ColumnView = ({
9999
<CommunityBrief content={community} descExpand={descExpand} />
100100
<CommunityStatesPad
101101
community={community}
102-
onSubscribe={onSubscribe}
103-
onUndoSubscribe={onUndoSubscribe}
104102
onShowEditorList={onShowEditorList}
105103
onShowSubscriberList={onShowSubscriberList}
106104
/>
@@ -116,6 +114,10 @@ const ColumnView = ({
116114
</TabBarWrapper>
117115
</BannerContentWrapper>
118116
</InnerWrapper>
117+
<Waypoint
118+
onEnter={() => setViewport(true)}
119+
onLeave={() => setViewport(false)}
120+
/>
119121
</Wrapper>
120122
)
121123
}

src/containers/digest/CommunityDigest/DigestView/RowView/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ import {
4040
import { tabOnChange } from '../../logic'
4141

4242
// import {
43-
// onSubscribe,
44-
// onUndoSubscribe,
4543
// onShowEditorList,
4644
// onShowSubscriberList,
4745
// } from '../../logic'

src/containers/digest/CommunityDigest/logic.js

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,6 @@ export const tabOnChange = (activeThread) => {
4141
send(EVENT.THREAD_CHANGE, { data: { activeThread, topic: subPath } })
4242
}
4343

44-
export const onSubscribe = (community) => {
45-
if (!store.isLogin) return store.authWarning()
46-
if (store.subscribeLoading) return false
47-
48-
// log('onSubscribe: ', community)
49-
store.mark({ subscribeLoading: true })
50-
sr71$.mutate(S.subscribeCommunity, { communityId: community.id })
51-
}
52-
53-
export const onUndoSubscribe = (community) => {
54-
if (!store.isLogin) return store.authWarning()
55-
if (store.subscribeLoading) return false
56-
57-
// log('onUndoSubscribe: ', community)
58-
store.mark({ subscribeLoading: true })
59-
sr71$.mutate(S.unsubscribeCommunity, { communityId: community.id })
60-
}
61-
6244
export const onShowEditorList = () => {
6345
const type = TYPE.USER_LISTER_COMMUNITY_EDITORS
6446
const data = {
@@ -85,8 +67,15 @@ export const toggleDescExpand = () => {
8567
store.mark({ descExpand: !descExpand })
8668
}
8769

88-
const markLoading = (maybe = true) =>
89-
store.mark({ loading: maybe, subscribeLoading: maybe })
70+
const markLoading = (maybe = true) => store.mark({ loading: maybe })
71+
72+
/**
73+
* set digest visiable in current viewport
74+
* @param {Boolean} inView
75+
*/
76+
export const setViewport = (inViewport) => {
77+
store.mark({ inViewport })
78+
}
9079

9180
// ###############################
9281
// Data & Error handlers
Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,12 @@
11
import gql from 'graphql-tag'
2-
import { P, F } from '@/schemas'
2+
import { P } from '@/schemas'
33

44
const community = gql`
55
${P.community}
66
`
77

8-
const subscribeCommunity = gql`
9-
mutation subscribeCommunity($communityId: ID!) {
10-
subscribeCommunity(communityId: $communityId) {
11-
${F.community}
12-
contributesDigest
13-
threads {
14-
title
15-
raw
16-
}
17-
}
18-
}
19-
`
20-
const unsubscribeCommunity = gql`
21-
mutation unsubscribeCommunity($communityId: ID!) {
22-
unsubscribeCommunity(communityId: $communityId) {
23-
id
24-
}
25-
}
26-
`
27-
288
const schema = {
299
community,
30-
subscribeCommunity,
31-
unsubscribeCommunity,
3210
}
3311

3412
export default schema

src/containers/digest/CommunityDigest/store.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ const log = buildLog('S:CommunityDigest')
1313
const CommunityDigest = T.model('CommunityDigest', {
1414
loading: T.optional(T.boolean, false),
1515
descExpand: T.optional(T.boolean, false),
16-
subscribeLoading: T.optional(T.boolean, false),
16+
17+
inViewport: T.optional(T.boolean, true),
1718
})
1819
.views((self) => ({
1920
get root() {

src/containers/thread/PostsThread/index.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { ICON } from '@/config'
1212
import { C11N, THREAD, ROUTE } from '@/constant'
1313
import { pluggedIn, buildLog } from '@/utils'
1414

15+
import CommunityJoinBadge from '@/containers/tool/CommunityJoinBadge'
1516
import TagsBar from '@/containers/unit/TagsBar'
1617

1718
import Sticky from '@/components/Sticky'
@@ -30,6 +31,7 @@ import {
3031
LeftPart,
3132
RightPart,
3233
FilterWrapper,
34+
BadgeWrapper,
3335
PublisherWrapper,
3436
StickyHolder,
3537
} from './styles'
@@ -97,6 +99,7 @@ const PostsThreadContainer = ({ postsThread: store }) => {
9799
accountInfo: {
98100
customization: { bannerLayout },
99101
},
102+
isCommunityDigestInViewport,
100103
} = store
101104

102105
const { subPath } = curRoute
@@ -147,7 +150,7 @@ const PostsThreadContainer = ({ postsThread: store }) => {
147150

148151
{bannerLayout === C11N.DIGEST && (
149152
<RightPart>
150-
<PublisherWrapper>
153+
<PublisherWrapper show={isCommunityDigestInViewport}>
151154
<DropdownButton
152155
type="primary"
153156
placement="bottom-end"
@@ -174,14 +177,12 @@ const PostsThreadContainer = ({ postsThread: store }) => {
174177
>
175178
{LabelText[subPath] || '发布帖子'}
176179
</DropdownButton>
177-
178-
{/* <PublishButton
179-
label={LabelText[subPath] || '发布帖子'}
180-
onPublish={onContentCreate}
181-
/> */}
182180
</PublisherWrapper>
183181

184-
<Sticky offsetTop={100}>
182+
<Sticky offsetTop={55}>
183+
<BadgeWrapper show={!isCommunityDigestInViewport}>
184+
<CommunityJoinBadge />
185+
</BadgeWrapper>
185186
<TagsBar
186187
thread={THREAD.POST}
187188
topic={topic}

src/containers/thread/PostsThread/store.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ const PostsThreadStore = T.model('PostsThreadStore', {
8484

8585
return !isEmpty(curFilter) || !isEmpty(pagedPosts.entries)
8686
},
87+
get isCommunityDigestInViewport() {
88+
return self.root.communityDigest.inViewport
89+
},
8790
}))
8891
.actions((self) => ({
8992
toastInfo(options) {

0 commit comments

Comments
 (0)