2020-04-30 05:34:50 +01:00
'use strict'
2020-08-17 21:07:16 +01:00
import React from 'react'
2020-08-17 21:59:29 +01:00
import PropTypes from 'prop-types'
2020-08-17 21:39:25 +01:00
import { connect } from 'react-redux'
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'
2020-11-09 19:28:43 +00:00
import { fetchPromotions } from '../actions/promotions'
2020-12-03 22:13:11 +00:00
import { fetchChatConversationUnreadCount } from '../actions/chat_conversations'
2020-04-30 05:34:50 +01:00
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-12-03 04:22:51 +00:00
connectChatMessagesStream ,
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 ( ) )
2020-11-09 19:28:43 +00:00
store . dispatch ( fetchPromotions ( ) )
2020-12-03 22:13:11 +00:00
store . dispatch ( fetchChatConversationUnreadCount ( ) )
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 } / >
< / B r o w s e r R o u t e r >
)
}
2019-07-02 08:10:25 +01:00
return (
< BrowserRouter >
< ScrollContext >
< Route path = '/' component = { UI } / >
< / S c r o l l C o n t e x t >
< / B r o w s e r R o u t e r >
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-12-03 04:22:51 +00:00
store . dispatch ( connectChatMessagesStream ( me ) )
2020-04-11 23:29:19 +01:00
}
2020-05-04 19:44:37 +01:00
2020-09-01 01:52:43 +01:00
console . log ( '%cGab Social ' , [
2020-05-04 19:44:37 +01:00
, 'color: #30CE7D'
, 'display: block'
, 'line-height: 80px'
, 'font-family: system-ui, -apple-system, BlinkMacSystemFont, Roboto, Ubuntu, "Helvetica Neue", sans-serif'
, 'font-size: 36px'
2020-09-01 01:52:43 +01:00
, 'text-align: left'
, 'font-weight: 800'
] . join ( ';' ) )
console . log ( '%cThis is a browser feature intended for developers.\nIf someone told you to copy and paste something here it is a scam and will give them access to your Gab account. ' , [
, 'color: #000'
, 'display: block'
, 'line-height: 30px'
, 'font-family: system-ui, -apple-system, BlinkMacSystemFont, Roboto, Ubuntu, "Helvetica Neue", sans-serif'
, 'font-size: 20px'
, 'text-align: left'
, 'font-weight: 600'
2020-05-04 19:44:37 +01:00
] . 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 / >
< / E r r o r B o u n d a r y >
< / D i s p l a y >
2019-07-02 08:10:25 +01:00
< / P r o v i d e r >
< / I n t l P r o v i d e r >
2020-04-30 05:34:50 +01:00
)
2019-07-02 08:10:25 +01:00
}
}