2020-12-06 04:47:48 +00:00
|
|
|
import React from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import { connect } from 'react-redux'
|
2020-12-08 05:07:04 +00:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes'
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component'
|
2020-12-09 04:15:33 +00:00
|
|
|
import {
|
|
|
|
sortableContainer,
|
|
|
|
sortableElement,
|
|
|
|
} from 'react-sortable-hoc'
|
|
|
|
import { me, meUsername} from '../initial_state'
|
2020-12-09 04:57:51 +00:00
|
|
|
import {
|
|
|
|
GAB_DECK_MAX_ITEMS,
|
2020-12-21 18:25:05 +00:00
|
|
|
URL_GAB_PRO,
|
2020-12-09 04:57:51 +00:00
|
|
|
MODAL_PRO_UPGRADE,
|
|
|
|
} from '../constants'
|
2020-12-08 05:07:04 +00:00
|
|
|
import {
|
|
|
|
deckConnect,
|
|
|
|
deckDisconnect,
|
2020-12-09 04:15:33 +00:00
|
|
|
updateDeckColumnAtIndex,
|
2020-12-08 05:07:04 +00:00
|
|
|
} from '../actions/deck'
|
2020-12-09 04:57:51 +00:00
|
|
|
import { saveSettings } from '../actions/settings'
|
|
|
|
import { openModal } from '../actions/modal'
|
2020-12-06 04:47:48 +00:00
|
|
|
import WrappedBundle from './ui/util/wrapped_bundle'
|
|
|
|
import DeckColumn from '../components/deck_column'
|
2020-12-09 04:57:51 +00:00
|
|
|
import Text from '../components/text'
|
2020-12-21 18:25:05 +00:00
|
|
|
import Button from '../components/button'
|
2020-12-06 04:47:48 +00:00
|
|
|
import {
|
|
|
|
AccountTimeline,
|
2020-12-08 05:07:04 +00:00
|
|
|
Compose,
|
2020-12-16 07:39:07 +00:00
|
|
|
GroupTimeline,
|
2020-12-09 04:15:33 +00:00
|
|
|
LikedStatuses,
|
2020-12-16 07:39:07 +00:00
|
|
|
ListTimeline,
|
2020-12-06 04:47:48 +00:00
|
|
|
HomeTimeline,
|
|
|
|
Notifications,
|
|
|
|
HashtagTimeline,
|
2020-12-09 04:15:33 +00:00
|
|
|
BookmarkedStatuses,
|
|
|
|
ProTimeline,
|
2020-12-09 04:57:51 +00:00
|
|
|
News,
|
|
|
|
ExploreTimeline,
|
2020-12-06 04:47:48 +00:00
|
|
|
} from './ui/util/async_components'
|
|
|
|
|
|
|
|
class Deck extends React.PureComponent {
|
|
|
|
|
|
|
|
static contextTypes = {
|
|
|
|
router: PropTypes.object,
|
|
|
|
}
|
|
|
|
|
2020-12-08 05:07:04 +00:00
|
|
|
componentDidMount () {
|
|
|
|
this.props.dispatch(deckConnect())
|
2020-12-09 04:57:51 +00:00
|
|
|
if (!this.props.isPro) this.handleOnOpenProUpgradeModal()
|
2020-12-08 05:07:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
this.props.dispatch(deckDisconnect())
|
2020-12-06 04:47:48 +00:00
|
|
|
}
|
|
|
|
|
2020-12-09 04:57:51 +00:00
|
|
|
handleOnOpenProUpgradeModal = () => {
|
|
|
|
this.props.dispatch(openModal(MODAL_PRO_UPGRADE))
|
|
|
|
}
|
|
|
|
|
2020-12-09 04:15:33 +00:00
|
|
|
onSortEnd = ({oldIndex, newIndex}) => {
|
|
|
|
this.props.dispatch(updateDeckColumnAtIndex(oldIndex, newIndex))
|
|
|
|
}
|
|
|
|
|
|
|
|
onShouldCancelStart = (event) => {
|
|
|
|
if (event.target) {
|
|
|
|
if (!event.target.hasAttribute('data-sort-header')) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
getDeckColumn = (deckColumn, index) => {
|
2020-12-09 20:02:43 +00:00
|
|
|
if (!deckColumn || !this.props.isPro) return null
|
2020-12-09 04:15:33 +00:00
|
|
|
|
2020-12-16 22:29:06 +00:00
|
|
|
let Component, noRefresh, accountId, icon = null
|
2020-12-09 04:15:33 +00:00
|
|
|
let componentParams = {}
|
2020-12-16 22:29:06 +00:00
|
|
|
let title, subtitle = ''
|
2020-12-09 04:15:33 +00:00
|
|
|
|
|
|
|
switch (deckColumn) {
|
|
|
|
case 'notifications':
|
|
|
|
title = 'Notifications'
|
|
|
|
icon = 'notifications'
|
|
|
|
Component = Notifications
|
|
|
|
break
|
|
|
|
case 'home':
|
|
|
|
title = 'Home'
|
|
|
|
icon = 'home'
|
|
|
|
Component = HomeTimeline
|
|
|
|
break
|
|
|
|
case 'compose':
|
|
|
|
title = 'Compose'
|
|
|
|
icon = 'pencil'
|
|
|
|
Component = Compose
|
2020-12-16 22:29:06 +00:00
|
|
|
noRefresh = true
|
2020-12-09 04:15:33 +00:00
|
|
|
break
|
|
|
|
case 'likes':
|
|
|
|
title = 'Likes'
|
|
|
|
icon = 'like'
|
|
|
|
Component = LikedStatuses
|
|
|
|
componentParams = { params: { username: meUsername }}
|
|
|
|
break
|
|
|
|
case 'bookmarks':
|
|
|
|
title = 'Bookmarks'
|
|
|
|
icon = 'bookmark'
|
|
|
|
Component = BookmarkedStatuses
|
|
|
|
componentParams = { params: { username: meUsername }}
|
|
|
|
break
|
|
|
|
case 'pro':
|
|
|
|
title = 'Pro Timeline'
|
|
|
|
icon = 'pro'
|
|
|
|
Component = ProTimeline
|
|
|
|
break
|
2020-12-09 04:57:51 +00:00
|
|
|
case 'news':
|
|
|
|
title = 'News'
|
|
|
|
icon = 'news'
|
|
|
|
Component = News
|
|
|
|
componentParams = { isSmall: true }
|
|
|
|
break
|
|
|
|
case 'explore':
|
|
|
|
title = 'Explore'
|
|
|
|
icon = 'explore'
|
|
|
|
Component = ExploreTimeline
|
|
|
|
break
|
2020-12-09 04:15:33 +00:00
|
|
|
default:
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Component) {
|
|
|
|
if (deckColumn.indexOf('user.') > -1) {
|
2020-12-16 22:29:06 +00:00
|
|
|
const userAccountId = deckColumn.replace('user.', '')
|
|
|
|
title = 'User'
|
|
|
|
Component = AccountTimeline
|
|
|
|
componentParams = { id: userAccountId }
|
|
|
|
accountId = userAccountId
|
2020-12-09 04:15:33 +00:00
|
|
|
} else if (deckColumn.indexOf('list.') > -1) {
|
2020-12-16 07:39:07 +00:00
|
|
|
const listId = deckColumn.replace('list.', '')
|
|
|
|
title = 'List'
|
|
|
|
subtitle = listId
|
|
|
|
icon = 'list'
|
|
|
|
Component = ListTimeline
|
|
|
|
componentParams = { params: { id: listId }}
|
2020-12-09 04:15:33 +00:00
|
|
|
} else if (deckColumn.indexOf('group.') > -1) {
|
2020-12-16 07:39:07 +00:00
|
|
|
const groupId = deckColumn.replace('group.', '')
|
|
|
|
title = 'Group'
|
|
|
|
subtitle = groupId
|
|
|
|
icon = 'group'
|
|
|
|
Component = GroupTimeline
|
|
|
|
componentParams = { params: { id: groupId }}
|
2020-12-09 04:57:51 +00:00
|
|
|
} else if (deckColumn.indexOf('news.') > -1) {
|
2020-12-16 07:39:07 +00:00
|
|
|
// : todo :
|
2020-12-09 04:57:51 +00:00
|
|
|
} else if (deckColumn.indexOf('hashtag.') > -1) {
|
2020-12-16 07:39:07 +00:00
|
|
|
const hashtag = deckColumn.replace('hashtag.', '')
|
|
|
|
title = 'Hashtag'
|
|
|
|
subtitle = hashtag
|
|
|
|
icon = 'apps'
|
|
|
|
Component = HashtagTimeline
|
|
|
|
componentParams = { params: { id: hashtag }}
|
2020-12-09 04:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Component) return null
|
|
|
|
|
|
|
|
return (
|
|
|
|
<SortableItem
|
|
|
|
key={`deck-column-${index}`}
|
|
|
|
index={index}
|
|
|
|
sortIndex={index}
|
|
|
|
>
|
2020-12-16 22:29:06 +00:00
|
|
|
<DeckColumn
|
|
|
|
title={title}
|
|
|
|
subtitle={subtitle}
|
|
|
|
icon={icon}
|
|
|
|
index={index}
|
|
|
|
noRefresh={noRefresh}
|
|
|
|
accountId={accountId}
|
|
|
|
>
|
2020-12-09 04:15:33 +00:00
|
|
|
<WrappedBundle component={Component} componentParams={componentParams} />
|
|
|
|
</DeckColumn>
|
|
|
|
</SortableItem>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-12-06 04:47:48 +00:00
|
|
|
render () {
|
2020-12-09 04:57:51 +00:00
|
|
|
const { gabDeckOrder, isPro } = this.props
|
2020-12-06 04:47:48 +00:00
|
|
|
|
2020-12-09 04:15:33 +00:00
|
|
|
const isEmpty = gabDeckOrder.size === 0
|
|
|
|
|
2020-12-21 18:25:05 +00:00
|
|
|
const title = (
|
|
|
|
<span className={[_s.d, _s.flexRow, _s.jcCenter, _s.aiCenter].join(' ')}>
|
|
|
|
<span className={[_s.d, _s.mr2].join(' ')}>
|
|
|
|
Gab Deck for Gab
|
|
|
|
</span>
|
|
|
|
<span className={[_s.bgPro, _s.cBlack, _s.radiusSmall, _s.px5, _s.py5].join(' ')}>PRO</span>
|
|
|
|
</span>
|
|
|
|
)
|
|
|
|
|
2020-12-06 04:47:48 +00:00
|
|
|
return (
|
2020-12-09 04:15:33 +00:00
|
|
|
<SortableContainer
|
|
|
|
axis='x'
|
|
|
|
lockAxis='x'
|
|
|
|
onSortEnd={this.onSortEnd}
|
|
|
|
shouldCancelStart={this.onShouldCancelStart}
|
|
|
|
>
|
|
|
|
{
|
2020-12-09 04:57:51 +00:00
|
|
|
(isEmpty || !isPro) &&
|
2020-12-09 04:15:33 +00:00
|
|
|
<React.Fragment>
|
2020-12-09 04:57:51 +00:00
|
|
|
<DeckColumn title='Compose' icon='pencil' noButtons>
|
2020-12-09 04:15:33 +00:00
|
|
|
<WrappedBundle component={Compose} />
|
|
|
|
</DeckColumn>
|
2020-12-21 18:25:05 +00:00
|
|
|
{
|
2020-12-09 04:57:51 +00:00
|
|
|
!isPro &&
|
2020-12-21 18:25:05 +00:00
|
|
|
<DeckColumn title={title} icon='pro' noButtons>
|
2020-12-09 04:57:51 +00:00
|
|
|
<div className={[_s.d, _s.px15, _s.py15].join(' ')}>
|
|
|
|
<Text>
|
2020-12-21 18:25:05 +00:00
|
|
|
GabDeck is a unique way to customize your Gab experience. Upgrade to GabPRO to unlock the GabDeck.
|
2020-12-09 04:57:51 +00:00
|
|
|
</Text>
|
2020-12-21 18:25:05 +00:00
|
|
|
<div className={[_s.mt15, _s.d, _s.flexRow].join(' ')}>
|
|
|
|
<Button href={URL_GAB_PRO}>
|
|
|
|
<Text color='inherit' className={_s.px10}>
|
|
|
|
Upgrade to GabPRO
|
|
|
|
</Text>
|
|
|
|
</Button>
|
|
|
|
</div>
|
2020-12-09 04:57:51 +00:00
|
|
|
</div>
|
|
|
|
</DeckColumn>
|
|
|
|
}
|
2020-12-21 18:25:05 +00:00
|
|
|
<DeckColumn title='Explore' icon='explore' noButtons>
|
|
|
|
<WrappedBundle component={ExploreTimeline} />
|
|
|
|
</DeckColumn>
|
|
|
|
<DeckColumn title='News' icon='news' noButtons>
|
|
|
|
<WrappedBundle component={News} componentParams={{ isSmall: true }} />
|
|
|
|
</DeckColumn>
|
2020-12-09 04:15:33 +00:00
|
|
|
<DeckColumn />
|
|
|
|
</React.Fragment>
|
|
|
|
}
|
|
|
|
{
|
2020-12-09 04:57:51 +00:00
|
|
|
!isEmpty && isPro &&
|
2020-12-09 20:02:43 +00:00
|
|
|
gabDeckOrder.map((deckOption, i) => this.getDeckColumn(deckOption, i))
|
2020-12-09 04:15:33 +00:00
|
|
|
}
|
|
|
|
</SortableContainer>
|
2020-12-06 04:47:48 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-12-09 04:15:33 +00:00
|
|
|
const SortableItem = sortableElement(({children}) => (
|
|
|
|
<div>
|
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
))
|
|
|
|
|
|
|
|
const SortableContainer = sortableContainer(({children}) => (
|
|
|
|
<div className={[_s.d, _s.flexRow, _s.listStyleNone].join(' ')}>
|
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
))
|
|
|
|
|
2020-12-06 04:47:48 +00:00
|
|
|
const mapStateToProps = (state) => ({
|
2020-12-09 04:57:51 +00:00
|
|
|
isPro: state.getIn(['accounts', me, 'is_pro']),
|
2020-12-08 05:07:04 +00:00
|
|
|
gabDeckOrder: state.getIn(['settings', 'gabDeckOrder']),
|
2020-12-06 04:47:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
Deck.propTypes = {
|
2020-12-09 04:57:51 +00:00
|
|
|
isPro: PropTypes.bool.isRequired,
|
2020-12-08 05:07:04 +00:00
|
|
|
gabDeckOrder: ImmutablePropTypes.list,
|
2020-12-06 04:47:48 +00:00
|
|
|
}
|
|
|
|
|
2020-12-08 05:07:04 +00:00
|
|
|
export default connect(mapStateToProps)(Deck)
|