Added shortcut star buttons to GroupHeader, ProfileHeader

• Added:
- shortcut star buttons to GroupHeader, ProfileHeader
This commit is contained in:
mgabdev 2020-09-02 17:53:57 -05:00
parent 2202cea0e1
commit 9ca6b6a884
2 changed files with 118 additions and 22 deletions

View File

@ -7,6 +7,10 @@ import { defineMessages, injectIntl } from 'react-intl'
import { openPopover, closePopover } from '../actions/popover' import { openPopover, closePopover } from '../actions/popover'
import { openModal } from '../actions/modal' import { openModal } from '../actions/modal'
import { joinGroup, leaveGroup } from '../actions/groups' import { joinGroup, leaveGroup } from '../actions/groups'
import {
addShortcut,
removeShortcut,
} from '../actions/shortcuts'
import { import {
PLACEHOLDER_MISSING_HEADER_SRC, PLACEHOLDER_MISSING_HEADER_SRC,
BREAKPOINT_EXTRA_SMALL, BREAKPOINT_EXTRA_SMALL,
@ -32,7 +36,24 @@ class GroupHeader extends ImmutablePureComponent {
handleOnOpenGroupOptions = () => { handleOnOpenGroupOptions = () => {
const { relationships } = this.props const { relationships } = this.props
const isAdmin = !!relationships ? relationships.get('admin') : false const isAdmin = !!relationships ? relationships.get('admin') : false
this.props.onOpenGroupOptions(this.infoBtn, this.props.group, isAdmin) const isModerator = !!relationships ? relationships.get('moderator') : false
this.props.onOpenGroupOptions(this.infoBtn, this.props.group, {
isAdmin,
isModerator,
})
}
handleToggleShortcut = () => {
const { group, isShortcut } = this.props
const groupId = !!group ? group.get('id') : null
if (!groupId) return
if (isShortcut) {
this.props.onRemoveShortcut(groupId)
} else {
this.props.onAddShortcut(groupId)
}
} }
setInfoBtn = (c) => { setInfoBtn = (c) => {
@ -45,6 +66,7 @@ class GroupHeader extends ImmutablePureComponent {
group, group,
intl, intl,
isXS, isXS,
isShortcut,
relationships, relationships,
} = this.props } = this.props
@ -52,12 +74,13 @@ class GroupHeader extends ImmutablePureComponent {
const coverSrcMissing = coverSrc.indexOf(PLACEHOLDER_MISSING_HEADER_SRC) > -1 || !coverSrc const coverSrcMissing = coverSrc.indexOf(PLACEHOLDER_MISSING_HEADER_SRC) > -1 || !coverSrc
const title = !!group ? group.get('title') : undefined const title = !!group ? group.get('title') : undefined
const slug = !!group ? !!group.get('slug') ? `g/${group.get('slug')}` : undefined : undefined const slug = !!group ? !!group.get('slug') ? `g/${group.get('slug')}` : undefined : undefined
const isPrivate = !!group ? group.get('is_private') : false
let isAdmin = false let isAdminOrMod = false
let actionButtonTitle let actionButtonTitle
let actionButtonOptions = {} let actionButtonOptions = {}
if (relationships) { if (relationships) {
isAdmin = relationships.get('admin') isAdminOrMod = relationships.get('admin') || relationships.get('moderator')
const isMember = relationships.get('member') const isMember = relationships.get('member')
actionButtonTitle = intl.formatMessage(isMember ? messages.member : messages.join) actionButtonTitle = intl.formatMessage(isMember ? messages.member : messages.join)
@ -79,13 +102,20 @@ class GroupHeader extends ImmutablePureComponent {
// }, // },
] ]
if (isAdmin && group) { if (isAdminOrMod && group) {
tabs.push({ tabs.push({
to: `/groups/${group.get('id')}/members`, to: `/groups/${group.get('id')}/members`,
title: 'Members', title: 'Members',
}) })
} }
if (isAdminOrMod && group && isPrivate) {
tabs.push({
to: `/groups/${group.get('id')}/requests`,
title: 'Requests',
})
}
if (isXS && group) { if (isXS && group) {
tabs.push({ tabs.push({
to: `/groups/${group.get('id')}/about`, to: `/groups/${group.get('id')}/about`,
@ -193,14 +223,13 @@ class GroupHeader extends ImmutablePureComponent {
color='brand' color='brand'
backgroundColor='none' backgroundColor='none'
className={[_s.mr10, _s.px10].join(' ')} className={[_s.mr10, _s.px10].join(' ')}
icon='star-outline' icon={isShortcut ? 'star' : 'star-outline'}
onClick={this.handleOnOpenGroupOptions} onClick={this.handleToggleShortcut}
buttonRef={this.setInfoBtn}
/> />
<Button <Button
color='primary' color='primary'
backgroundColor='tertiary' backgroundColor='tertiary'
className={[_s.mr10, _s.px10].join(' ')} className={[_s.mr15, _s.px10].join(' ')}
icon='ellipsis' icon='ellipsis'
onClick={this.handleOnOpenGroupOptions} onClick={this.handleOnOpenGroupOptions}
buttonRef={this.setInfoBtn} buttonRef={this.setInfoBtn}
@ -240,6 +269,15 @@ const messages = defineMessages({
group_admin: { id: 'groups.detail.role_admin', defaultMessage: 'You\'re an admin' } group_admin: { id: 'groups.detail.role_admin', defaultMessage: 'You\'re an admin' }
}) })
const mapStateToProps = (state, { group }) => {
const groupId = group ? group.get('id') : null
const shortcuts = state.getIn(['shortcuts', 'items'])
const isShortcut = !!shortcuts.find((s) => {
return s.get('shortcut_id') == groupId && s.get('shortcut_type') === 'group'
})
return { isShortcut }
}
const mapDispatchToProps = (dispatch, { intl }) => ({ const mapDispatchToProps = (dispatch, { intl }) => ({
onToggleMembership(group, relationships) { onToggleMembership(group, relationships) {
@ -249,15 +287,20 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
dispatch(joinGroup(group.get('id'))) dispatch(joinGroup(group.get('id')))
} }
}, },
onOpenGroupOptions(targetRef, group, options) {
onOpenGroupOptions(targetRef, group, isAdmin) {
dispatch(openPopover('GROUP_OPTIONS', { dispatch(openPopover('GROUP_OPTIONS', {
targetRef, targetRef,
group, group,
isAdmin, ...options,
position: 'left', position: 'left',
})) }))
}, },
onAddShortcut(groupId) {
dispatch(addShortcut('group', groupId))
},
onRemoveShortcut(groupId) {
dispatch(removeShortcut(null, 'group', groupId))
},
}) })
@ -265,10 +308,13 @@ GroupHeader.propTypes = {
group: ImmutablePropTypes.map, group: ImmutablePropTypes.map,
children: PropTypes.any, children: PropTypes.any,
intl: PropTypes.object.isRequired, intl: PropTypes.object.isRequired,
isShortcut: PropTypes.bool.isRequired,
isXS: PropTypes.bool, isXS: PropTypes.bool,
onAddShortcut: PropTypes.func.isRequired,
onToggleMembership: PropTypes.func.isRequired, onToggleMembership: PropTypes.func.isRequired,
onRemoveShortcut: PropTypes.func.isRequired,
onOpenGroupOptions: PropTypes.func.isRequired, onOpenGroupOptions: PropTypes.func.isRequired,
relationships: ImmutablePropTypes.map, relationships: ImmutablePropTypes.map,
} }
export default injectIntl(connect(null, mapDispatchToProps)(GroupHeader)) export default injectIntl(connect(mapStateToProps, mapDispatchToProps)(GroupHeader))

View File

@ -12,6 +12,10 @@ import {
MODAL_EDIT_PROFILE, MODAL_EDIT_PROFILE,
BREAKPOINT_EXTRA_SMALL, BREAKPOINT_EXTRA_SMALL,
} from '../constants' } from '../constants'
import {
addShortcut,
removeShortcut,
} from '../actions/shortcuts'
import { openModal } from '../actions/modal' import { openModal } from '../actions/modal'
import { openPopover } from '../actions/popover' import { openPopover } from '../actions/popover'
import { me } from '../initial_state' import { me } from '../initial_state'
@ -46,6 +50,19 @@ class ProfileHeader extends ImmutablePureComponent {
}) })
} }
handleToggleShortcut = () => {
const { account, isShortcut } = this.props
const accountId = !!account ? account.get('id') : null
if (!accountId) return
if (isShortcut) {
this.props.onRemoveShortcut(accountId)
} else {
this.props.onAddShortcut(accountId)
}
}
onStickyStateChange = (status) => { onStickyStateChange = (status) => {
if (status.status === Sticky.STATUS_FIXED) { if (status.status === Sticky.STATUS_FIXED) {
this.setState({ stickied: true }) this.setState({ stickied: true })
@ -63,6 +80,7 @@ class ProfileHeader extends ImmutablePureComponent {
account, account,
children, children,
intl, intl,
isShortcut,
isXS isXS
} = this.props } = this.props
const { stickied } = this.state const { stickied } = this.state
@ -210,7 +228,16 @@ class ProfileHeader extends ImmutablePureComponent {
account && account.get('id') !== me && !!me && account && account.get('id') !== me && !!me &&
<div className={[_s.d, _s.flexRow, _s.py5].join(' ')}> <div className={[_s.d, _s.flexRow, _s.py5].join(' ')}>
<div className={[_s.d, _s.flexRow, _s.mr10].join(' ')}> <Button
icon={isShortcut ? 'star' : 'star-outline'}
iconSize='18px'
color='brand'
backgroundColor='none'
className={[_s.jcCenter, _s.aiCenter, _s.px10, _s.mr15].join(' ')}
onClick={this.handleToggleShortcut}
/>
<div className={[_s.d, _s.flexRow, _s.mr15].join(' ')}>
<AccountActionButton account={account} /> <AccountActionButton account={account} />
</div> </div>
@ -222,7 +249,7 @@ class ProfileHeader extends ImmutablePureComponent {
iconClassName={_s.inheritFill} iconClassName={_s.inheritFill}
color='brand' color='brand'
backgroundColor='none' backgroundColor='none'
className={[_s.jcCenter, _s.aiCenter, _s.px10].join(' ')} className={[_s.jcCenter, _s.aiCenter, _s.ml10, _s.px10].join(' ')}
onClick={this.handleOpenMore} onClick={this.handleOpenMore}
buttonRef={this.setOpenMoreNodeRef} buttonRef={this.setOpenMoreNodeRef}
/> />
@ -323,10 +350,18 @@ class ProfileHeader extends ImmutablePureComponent {
{ {
account && account.get('id') !== me && account && account.get('id') !== me &&
<div className={[_s.d, _s.flexRow, _s.mlAuto, _s.py5].join(' ')}> <div className={[_s.d, _s.flexRow, _s.mlAuto, _s.pb2, _s.pt7].join(' ')}>
{ {
!!me && !!me &&
<div> <div className={[_s.d, _s.flexRow, _s.mr5, _s.aiCenter, _s.jcCenter].join(' ')}>
<Button
icon={isShortcut ? 'star' : 'star-outline'}
iconSize='18px'
color='brand'
backgroundColor='none'
className={[_s.jcCenter, _s.aiCenter, _s.px10, _s.mr10].join(' ')}
onClick={this.handleToggleShortcut}
/>
<Button <Button
isOutline isOutline
icon='ellipsis' icon='ellipsis'
@ -334,14 +369,14 @@ class ProfileHeader extends ImmutablePureComponent {
iconClassName={_s.inheritFill} iconClassName={_s.inheritFill}
color='brand' color='brand'
backgroundColor='none' backgroundColor='none'
className={[_s.jcCenter, _s.aiCenter, _s.mr10, _s.px10].join(' ')} className={[_s.jcCenter, _s.aiCenter, _s.mr15, _s.px10].join(' ')}
onClick={this.handleOpenMore} onClick={this.handleOpenMore}
buttonRef={this.setOpenMoreNodeRef} buttonRef={this.setOpenMoreNodeRef}
/> />
</div> </div>
} }
<div className={[_s.d, _s.flexRow, _s.pb3].join(' ')}> <div className={[_s.d, _s.flexRow, _s.pb2].join(' ')}>
<AccountActionButton account={account} /> <AccountActionButton account={account} />
</div> </div>
@ -359,6 +394,15 @@ class ProfileHeader extends ImmutablePureComponent {
} }
const mapStateToProps = (state, { account }) => {
const accountId = account ? account.get('id') : null
const shortcuts = state.getIn(['shortcuts', 'items'])
const isShortcut = !!shortcuts.find((s) => {
return s.get('shortcut_id') == accountId && s.get('shortcut_type') === 'account'
})
return { isShortcut }
}
const messages = defineMessages({ const messages = defineMessages({
followers: { id: 'account.followers', defaultMessage: 'Followers' }, followers: { id: 'account.followers', defaultMessage: 'Followers' },
follows: { id: 'account.follows', defaultMessage: 'Following' }, follows: { id: 'account.follows', defaultMessage: 'Following' },
@ -374,24 +418,30 @@ const messages = defineMessages({
}) })
const mapDispatchToProps = (dispatch) => ({ const mapDispatchToProps = (dispatch) => ({
openProfileOptionsPopover(props) { openProfileOptionsPopover(props) {
dispatch(openPopover(POPOVER_PROFILE_OPTIONS, props)) dispatch(openPopover(POPOVER_PROFILE_OPTIONS, props))
}, },
onEditProfile() { onEditProfile() {
dispatch(openModal(MODAL_EDIT_PROFILE)) dispatch(openModal(MODAL_EDIT_PROFILE))
}, },
onAddShortcut(accountId) {
dispatch(addShortcut('account', accountId))
},
onRemoveShortcut(accountId) {
dispatch(removeShortcut(null, 'account', accountId))
},
}); });
ProfileHeader.propTypes = { ProfileHeader.propTypes = {
account: ImmutablePropTypes.map, account: ImmutablePropTypes.map,
children: PropTypes.any, children: PropTypes.any,
intl: PropTypes.object.isRequired, intl: PropTypes.object.isRequired,
onAddShortcut: PropTypes.func.isRequired,
onEditProfile: PropTypes.func.isRequired, onEditProfile: PropTypes.func.isRequired,
onRemoveShortcut: PropTypes.func.isRequired,
openProfileOptionsPopover: PropTypes.func.isRequired, openProfileOptionsPopover: PropTypes.func.isRequired,
isShortcut: PropTypes.bool.isRequired,
isXS: PropTypes.bool, isXS: PropTypes.bool,
} }
export default injectIntl(connect(null, mapDispatchToProps)(ProfileHeader)) export default injectIntl(connect(mapStateToProps, mapDispatchToProps)(ProfileHeader))