2020-04-30 05:34:50 +01:00
|
|
|
'use strict'
|
|
|
|
|
2020-08-17 21:07:16 +01:00
|
|
|
import React from 'react'
|
2020-04-30 05:34:50 +01:00
|
|
|
import { Provider } from 'react-redux'
|
|
|
|
import configureStore from '../store/configureStore'
|
|
|
|
import { BrowserRouter, Route } from 'react-router-dom'
|
2020-07-15 04:31:54 +01:00
|
|
|
import moment from 'moment-mini'
|
2020-04-30 05:34:50 +01:00
|
|
|
import { ScrollContext } from 'react-router-scroll-4'
|
|
|
|
import { IntlProvider, addLocaleData } from 'react-intl'
|
|
|
|
import { fetchCustomEmojis } from '../actions/custom_emojis'
|
|
|
|
import { hydrateStore } from '../actions/store'
|
2020-07-15 04:31:54 +01:00
|
|
|
import { MIN_ACCOUNT_CREATED_AT_ONBOARDING } from '../constants'
|
2019-08-28 06:31:25 +01:00
|
|
|
import {
|
|
|
|
connectUserStream,
|
|
|
|
connectStatusUpdateStream,
|
2020-04-30 05:34:50 +01:00
|
|
|
} from '../actions/streaming'
|
|
|
|
import { getLocale } from '../locales'
|
|
|
|
import initialState from '../initial_state'
|
2020-07-15 04:31:54 +01:00
|
|
|
import { me, isFirstSession } from '../initial_state'
|
2020-04-30 05:34:50 +01:00
|
|
|
import UI from '../features/ui'
|
2020-07-15 04:31:54 +01:00
|
|
|
import IntroductionPage from '../pages/introduction_page'
|
2020-04-30 05:34:50 +01:00
|
|
|
import ErrorBoundary from '../components/error_boundary'
|
|
|
|
import Display from './display'
|
2019-07-02 08:10:25 +01:00
|
|
|
|
2020-04-30 05:34:50 +01:00
|
|
|
const { localeData, messages } = getLocale()
|
|
|
|
addLocaleData(localeData)
|
2019-07-02 08:10:25 +01:00
|
|
|
|
2020-04-30 05:34:50 +01:00
|
|
|
export const store = configureStore()
|
|
|
|
const hydrateAction = hydrateStore(initialState)
|
2019-07-02 08:10:25 +01:00
|
|
|
|
2020-04-30 05:34:50 +01:00
|
|
|
store.dispatch(hydrateAction)
|
|
|
|
store.dispatch(fetchCustomEmojis())
|
2019-07-02 08:10:25 +01:00
|
|
|
|
2020-07-15 04:31:54 +01:00
|
|
|
const mapStateToProps = (state) => ({
|
|
|
|
accountCreatedAt: !!me ? state.getIn(['accounts', me, 'created_at']) : undefined,
|
|
|
|
shownOnboarding: state.getIn(['settings', 'shownOnboarding']),
|
|
|
|
})
|
|
|
|
|
|
|
|
@connect(mapStateToProps)
|
2020-08-17 21:07:16 +01:00
|
|
|
class GabSocialMount extends React.PureComponent {
|
2019-07-02 08:10:25 +01:00
|
|
|
|
2020-07-15 04:31:54 +01:00
|
|
|
static propTypes = {
|
|
|
|
shownOnboarding: PropTypes.bool.isRequired,
|
|
|
|
accountCreatedAt: PropTypes.string,
|
|
|
|
}
|
|
|
|
|
|
|
|
state = {
|
|
|
|
shownOnboarding: this.props.shownOnboarding,
|
|
|
|
shouldShow: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
if (!!me && this.props.accountCreatedAt) {
|
|
|
|
//If first time opening app, and is new user, show onboarding
|
|
|
|
const accountCreatedAtValue = moment(this.props.accountCreatedAt).valueOf()
|
|
|
|
const shouldShow = isFirstSession && !this.state.shownOnboarding && accountCreatedAtValue > MIN_ACCOUNT_CREATED_AT_ONBOARDING
|
|
|
|
|
|
|
|
if (shouldShow) this.setState({ shouldShow })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-02 08:10:25 +01:00
|
|
|
render () {
|
2020-07-15 04:31:54 +01:00
|
|
|
const { shownOnboarding, shouldShow } = this.state
|
|
|
|
|
|
|
|
if (!shownOnboarding && shouldShow) {
|
|
|
|
return (
|
|
|
|
<BrowserRouter>
|
|
|
|
<Route path='/' component={IntroductionPage} />
|
|
|
|
</BrowserRouter>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-07-02 08:10:25 +01:00
|
|
|
return (
|
|
|
|
<BrowserRouter>
|
|
|
|
<ScrollContext>
|
|
|
|
<Route path='/' component={UI} />
|
|
|
|
</ScrollContext>
|
|
|
|
</BrowserRouter>
|
2020-04-30 05:34:50 +01:00
|
|
|
)
|
2019-07-02 08:10:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-08-17 21:07:16 +01:00
|
|
|
export default class GabSocial extends React.PureComponent {
|
2019-07-02 08:10:25 +01:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
locale: PropTypes.string.isRequired,
|
2020-04-30 05:34:50 +01:00
|
|
|
}
|
2019-07-02 08:10:25 +01:00
|
|
|
|
|
|
|
componentDidMount() {
|
2020-04-11 23:29:19 +01:00
|
|
|
if (!!me) {
|
2020-04-30 05:34:50 +01:00
|
|
|
this.disconnect = store.dispatch(connectUserStream())
|
|
|
|
store.dispatch(connectStatusUpdateStream())
|
2020-04-11 23:29:19 +01:00
|
|
|
}
|
2020-05-04 19:44:37 +01:00
|
|
|
|
|
|
|
console.log('%c Gab Social ', [
|
|
|
|
, 'color: #30CE7D'
|
|
|
|
, 'display: block'
|
|
|
|
, 'line-height: 80px'
|
|
|
|
, 'font-family: system-ui, -apple-system, BlinkMacSystemFont, Roboto, Ubuntu, "Helvetica Neue", sans-serif'
|
|
|
|
, 'font-size: 36px'
|
|
|
|
, 'text-align: center'
|
|
|
|
, 'font-weight: bold'
|
|
|
|
].join(';'))
|
2019-07-02 08:10:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount () {
|
|
|
|
if (this.disconnect) {
|
2020-04-30 05:34:50 +01:00
|
|
|
this.disconnect()
|
|
|
|
this.disconnect = null
|
2019-07-02 08:10:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2020-04-30 05:34:50 +01:00
|
|
|
const { locale } = this.props
|
2019-07-02 08:10:25 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<IntlProvider locale={locale} messages={messages}>
|
|
|
|
<Provider store={store}>
|
2020-04-30 05:34:50 +01:00
|
|
|
<Display>
|
|
|
|
<ErrorBoundary>
|
|
|
|
<GabSocialMount />
|
|
|
|
</ErrorBoundary>
|
|
|
|
</Display>
|
2019-07-02 08:10:25 +01:00
|
|
|
</Provider>
|
|
|
|
</IntlProvider>
|
2020-04-30 05:34:50 +01:00
|
|
|
)
|
2019-07-02 08:10:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|