gab-social/app/javascript/gabsocial/components/sidebar.js

256 lines
7.8 KiB
JavaScript
Raw Normal View History

2020-02-19 23:57:07 +00:00
import ImmutablePropTypes from 'react-immutable-proptypes'
import ImmutablePureComponent from 'react-immutable-pure-component'
import { injectIntl, defineMessages } from 'react-intl'
2020-04-09 20:18:14 +01:00
import * as Constants from '../constants'
2020-02-19 23:57:07 +00:00
import Button from './button'
import { closeSidebar } from '../actions/sidebar'
2020-02-24 21:56:07 +00:00
import { openModal } from '../actions/modal'
2020-03-14 17:31:29 +00:00
import { openPopover } from '../actions/popover'
2020-02-19 23:57:07 +00:00
import { me } from '../initial_state'
import { makeGetAccount } from '../selectors'
2020-04-09 20:18:14 +01:00
import Responsive from '../features/ui/util/responsive_component'
2020-02-19 23:57:07 +00:00
import SidebarSectionTitle from './sidebar_section_title'
import SidebarSectionItem from './sidebar_section_item'
2020-02-22 23:26:23 +00:00
import SidebarHeader from './sidebar_header'
2020-02-19 23:57:07 +00:00
const messages = defineMessages({
followers: { id: 'account.followers', defaultMessage: 'Followers' },
follows: { id: 'account.follows', defaultMessage: 'Follows' },
profile: { id: 'account.profile', defaultMessage: 'Profile' },
preferences: { id: 'navigation_bar.preferences', defaultMessage: 'Preferences' },
follow_requests: { id: 'navigation_bar.follow_requests', defaultMessage: 'Follow requests' },
blocks: { id: 'navigation_bar.blocks', defaultMessage: 'Blocked users' },
domain_blocks: { id: 'navigation_bar.domain_blocks', defaultMessage: 'Hidden domains' },
mutes: { id: 'navigation_bar.mutes', defaultMessage: 'Muted users' },
filters: { id: 'navigation_bar.filters', defaultMessage: 'Muted words' },
logout: { id: 'navigation_bar.logout', defaultMessage: 'Logout' },
2020-04-08 02:06:59 +01:00
lists: { id: 'column.lists', defaultMessage: 'Lists' },
2020-02-19 23:57:07 +00:00
apps: { id: 'tabs_bar.apps', defaultMessage: 'Apps' },
more: { id: 'sidebar.more', defaultMessage: 'More' },
pro: { id: 'promo.gab_pro', defaultMessage: 'Upgrade to GabPRO' },
trends: { id: 'promo.trends', defaultMessage: 'Trends' },
search: { id: 'tabs_bar.search', defaultMessage: 'Search' },
shop: { id: 'tabs_bar.shop', defaultMessage: 'Store - Buy Merch' },
donate: { id: 'tabs_bar.donate', defaultMessage: 'Make a Donation' },
})
2020-04-11 23:29:19 +01:00
const mapStateToProps = (state) => {
2020-02-19 23:57:07 +00:00
const getAccount = makeGetAccount()
return {
account: getAccount(state, me),
2020-04-08 02:06:59 +01:00
moreOpen: state.getIn(['popover', 'popoverType']) === 'SIDEBAR_MORE',
2020-03-14 17:31:29 +00:00
notificationCount: state.getIn(['notifications', 'unread']),
homeItemsQueueCount: state.getIn(['timelines', 'home', 'totalQueuedItemsCount']),
2020-03-25 03:08:43 +00:00
showCommunityTimeline: state.getIn(['settings', 'community', 'shows', 'inSidebar']),
2020-02-19 23:57:07 +00:00
}
}
const mapDispatchToProps = (dispatch) => ({
onClose() {
dispatch(closeSidebar())
},
2020-03-14 17:31:29 +00:00
openSidebarMorePopover(props) {
dispatch(openPopover('SIDEBAR_MORE', props))
},
2020-02-24 21:56:07 +00:00
onOpenComposeModal() {
2020-03-12 16:09:15 +00:00
dispatch(openModal('COMPOSE'))
2020-02-24 21:56:07 +00:00
},
2020-02-19 23:57:07 +00:00
})
2020-02-24 21:56:07 +00:00
export default
@connect(mapStateToProps, mapDispatchToProps)
2020-02-19 23:57:07 +00:00
@injectIntl
class Sidebar extends ImmutablePureComponent {
static propTypes = {
intl: PropTypes.object.isRequired,
account: ImmutablePropTypes.map,
2020-03-25 03:08:43 +00:00
showCommunityTimeline: PropTypes.bool,
2020-04-07 02:53:23 +01:00
moreOpen: PropTypes.bool,
2020-02-19 23:57:07 +00:00
onClose: PropTypes.func.isRequired,
2020-02-24 21:56:07 +00:00
onOpenComposeModal: PropTypes.func.isRequired,
2020-03-14 17:31:29 +00:00
openSidebarMorePopover: PropTypes.func.isRequired,
notificationCount: PropTypes.number.isRequired,
homeItemsQueueCount: PropTypes.number.isRequired,
2020-02-19 23:57:07 +00:00
}
2020-02-24 21:56:07 +00:00
handleOpenComposeModal = () => {
this.props.onOpenComposeModal()
}
2020-03-14 17:31:29 +00:00
handleOpenSidebarMorePopover =() => {
this.props.openSidebarMorePopover({
targetRef: this.moreBtnRef,
position: 'top',
})
}
setMoreButtonRef = n => {
this.moreBtnRef = n
}
2020-02-19 23:57:07 +00:00
render() {
2020-03-25 03:08:43 +00:00
const {
intl,
account,
notificationCount,
homeItemsQueueCount,
2020-04-07 02:53:23 +01:00
showCommunityTimeline,
2020-04-08 02:06:59 +01:00
moreOpen,
2020-03-25 03:08:43 +00:00
} = this.props
2020-02-19 23:57:07 +00:00
2020-02-28 15:20:47 +00:00
// : todo :
2020-02-19 23:57:07 +00:00
if (!me || !account) return null
const acct = account.get('acct')
const isPro = account.get('is_pro')
2020-04-08 02:06:59 +01:00
console.log('showCommunityTimeline:', showCommunityTimeline)
2020-03-25 03:08:43 +00:00
2020-02-19 23:57:07 +00:00
const menuItems = [
{
title: 'Home',
icon: 'home',
2020-03-31 17:04:50 +01:00
to: '/home',
2020-03-14 17:31:29 +00:00
count: homeItemsQueueCount,
2020-02-19 23:57:07 +00:00
},
2020-03-25 03:08:43 +00:00
{
title: 'Community',
icon: 'community',
to: '/timeline/all',
hidden: !showCommunityTimeline,
},
2020-02-19 23:57:07 +00:00
{
title: 'Notifications',
icon: 'notifications',
to: '/notifications',
2020-03-14 17:31:29 +00:00
count: notificationCount,
2020-03-02 22:26:25 +00:00
},
2020-03-25 03:08:43 +00:00
{
title: 'Search',
icon: 'search-alt',
to: '/search',
hidden: true, // : todo : show only when search on top is not visible
},
2020-02-19 23:57:07 +00:00
{
title: 'Groups',
icon: 'group',
to: '/groups',
},
{
title: 'Lists',
icon: 'list',
to: '/lists',
},
{
title: 'Chat',
icon: 'chat',
2020-03-14 17:31:29 +00:00
href: 'https://chat.gab.com',
2020-02-19 23:57:07 +00:00
},
{
title: 'More',
icon: 'more',
2020-03-14 17:31:29 +00:00
onClick: this.handleOpenSidebarMorePopover,
2020-04-07 02:53:23 +01:00
buttonRef: this.setMoreButtonRef,
active: moreOpen,
2020-02-19 23:57:07 +00:00
},
]
const shortcutItems = [
2020-03-28 00:17:32 +00:00
// {
// title: 'Meme Group',
// icon: 'group',
// to: '/',
// count: 0,
// },
// {
// title: '@andrew',
// image: 'http://localhost:3000/system/accounts/avatars/000/000/001/original/260e8c96c97834da.jpeg?1562898139',
// to: '/',
// count: 3,
// },
2020-02-19 23:57:07 +00:00
]
const exploreItems = [
{
title: 'Apps',
icon: 'apps',
2020-03-14 17:31:29 +00:00
href: 'https://apps.gab.com',
2020-02-19 23:57:07 +00:00
},
{
title: 'Shop',
icon: 'shop',
2020-03-14 17:31:29 +00:00
href: 'https://shop.dissenter.com',
2020-02-19 23:57:07 +00:00
},
{
title: 'Trends',
icon: 'trends',
2020-03-14 17:31:29 +00:00
href: 'https://trends.gab.com',
2020-02-19 23:57:07 +00:00
},
{
title: 'Dissenter',
icon: 'dissenter',
2020-03-14 17:31:29 +00:00
href: 'https://dissenter.com',
2020-02-19 23:57:07 +00:00
},
]
return (
<header role='banner' className={[_s.default, _s.flexGrow1, _s.z3, _s.alignItemsEnd].join(' ')}>
<div className={[_s.default, _s.width240PX].join(' ')}>
<div className={[_s.default, _s.positionFixed, _s.top0, _s.height100PC].join(' ')}>
2020-04-09 20:18:14 +01:00
<div className={[_s.default, _s.height100PC, _s.alignItemsStart, _s.width240PX, _s.pr15, _s.py10, _s.overflowYScroll].join(' ')}>
2020-02-19 23:57:07 +00:00
2020-02-22 23:26:23 +00:00
<SidebarHeader />
2020-02-19 23:57:07 +00:00
2020-03-11 23:56:18 +00:00
<nav aria-label='Primary' role='navigation' className={[_s.default, _s.width100PC, _s.mb15].join(' ')}>
2020-02-19 23:57:07 +00:00
<SidebarSectionTitle>Menu</SidebarSectionTitle>
{
2020-03-25 03:08:43 +00:00
menuItems.map((menuItem, i) => {
if (menuItem.hidden) return null
return (
<SidebarSectionItem {...menuItem} key={`sidebar-item-menu-${i}`} />
)
})
2020-02-19 23:57:07 +00:00
}
2020-04-07 02:53:23 +01:00
{ /* <SidebarSectionTitle>Shortcuts</SidebarSectionTitle> */ }
2020-02-19 23:57:07 +00:00
{
shortcutItems.map((shortcutItem, i) => (
<SidebarSectionItem {...shortcutItem} key={`sidebar-item-shortcut-${i}`} />
))
}
<SidebarSectionTitle>Explore</SidebarSectionTitle>
{
exploreItems.map((exploreItem, i) => (
<SidebarSectionItem {...exploreItem} key={`sidebar-item-explore-${i}`} />
))
}
</nav>
2020-04-09 20:18:14 +01:00
<Responsive min={Constants.BREAKPOINT_SMALL}>
<Button
block
onClick={this.handleOpenComposeModal}
className={[_s.py15, _s.fontSize15PX, _s.fontWeightBold].join(' ')}
>
Gab
</Button>
</Responsive>
<Responsive max={Constants.BREAKPOINT_SMALL}>
<Button
onClick={this.handleOpenComposeModal}
className={_s.py15}
icon='pencil'
/>
</Responsive>
2020-02-19 23:57:07 +00:00
</div>
</div>
</div>
</header>
)
}
}