gab-social/app/javascript/gabsocial/containers/gabsocial.js

114 lines
2.8 KiB
JavaScript
Raw Normal View History

2020-04-30 05:34:50 +01:00
'use strict'
import { Provider } from 'react-redux'
import configureStore from '../store/configureStore'
import { INTRODUCTION_VERSION } from '../actions/onboarding'
import { BrowserRouter, Route } from 'react-router-dom'
import { ScrollContext } from 'react-router-scroll-4'
import { IntlProvider, addLocaleData } from 'react-intl'
import { fetchCustomEmojis } from '../actions/custom_emojis'
import { hydrateStore } from '../actions/store'
import {
connectUserStream,
connectStatusUpdateStream,
2020-04-30 05:34:50 +01:00
} from '../actions/streaming'
import { getLocale } from '../locales'
import initialState from '../initial_state'
import { me } from '../initial_state'
import UI from '../features/ui'
// import Introduction from '../features/introduction'
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
const mapStateToProps = (state) => {
2020-04-30 05:34:50 +01:00
const account = state.getIn(['accounts', me])
const showIntroduction = account ? state.getIn(['settings', 'introductionVersion'], 0) < INTRODUCTION_VERSION : false
2019-07-02 08:10:25 +01:00
return {
showIntroduction,
2020-04-30 05:34:50 +01:00
}
}
2019-07-02 08:10:25 +01:00
@connect(mapStateToProps)
class GabSocialMount extends PureComponent {
2019-07-02 08:10:25 +01:00
static propTypes = {
showIntroduction: PropTypes.bool,
2020-04-30 05:34:50 +01:00
}
2019-07-02 08:10:25 +01:00
render () {
// Disabling introduction for launch
2020-04-30 05:34:50 +01:00
// const { showIntroduction } = this.props
//
// if (showIntroduction) {
2020-04-30 05:34:50 +01:00
// return <Introduction />
// }
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
}
}
export default class GabSocial extends 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
}
}