Skip to content

Commit

Permalink
move tos, redux -> component state
Browse files Browse the repository at this point in the history
  • Loading branch information
wolverineks committed Jul 20, 2021
1 parent d0cc6e0 commit 2d16b3f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 28 deletions.
13 changes: 1 addition & 12 deletions src/actions/language.js
@@ -1,6 +1,6 @@
// @flow

import {writeAppSettings, APP_SETTINGS_KEYS, loadTOS} from '../helpers/appSettings'
import {writeAppSettings, APP_SETTINGS_KEYS} from '../helpers/appSettings'

import {type Dispatch} from 'redux'

Expand All @@ -16,20 +16,9 @@ export const changeLanguage = (languageCode: string) => (dispatch: Dispatch<any>
})
}

export const changeTOSLanguage = (tos: string) => (dispatch: Dispatch<any>) => {
dispatch({
path: ['tos'],
payload: tos,
reducer: (state, tos) => tos,
type: 'CHANGE_TOS_LANGUAGE',
})
}

export const changeAndSaveLanguage = (languageCode: string) => async (dispatch: Dispatch<any>) => {
await writeAppSettings(APP_SETTINGS_KEYS.LANG, languageCode)
const tos = await loadTOS(languageCode)

dispatch(changeTOSLanguage(tos))
dispatch(changeLanguage(languageCode))
}

Expand Down
27 changes: 12 additions & 15 deletions src/components/Common/TermsOfService.js
@@ -1,24 +1,21 @@
// @flow

import React from 'react'
import {connect} from 'react-redux'
import {compose} from 'redux'
import {useSelector} from 'react-redux'
import Markdown from 'react-native-easy-markdown'
import {loadTOS} from '../../helpers/appSettings'
import {ActivityIndicator} from 'react-native'
import {languageSelector} from '../../selectors'

import type {ComponentType} from 'react'
const TermsOfService = () => {
const [tos, setTos] = React.useState()
const languageCode = useSelector(languageSelector)

type Props = {
tos: string,
}
React.useEffect(() => {
loadTOS(languageCode).then(setTos)
}, [languageCode])

const TermsOfService = ({tos}: Props) => {
return <Markdown>{tos}</Markdown>
return tos ? <Markdown>{tos}</Markdown> : <ActivityIndicator size={'large'} color={'black'} />
}

export default (compose(
connect((state) => {
return {
tos: state.tos,
}
}),
)(TermsOfService): ComponentType<any>)
export default TermsOfService
1 change: 0 additions & 1 deletion src/state.js
Expand Up @@ -81,7 +81,6 @@ export type State = {
isAppInitialized: boolean,
isAuthenticated: boolean,
isKeyboardOpen: boolean,
tos: string,
appSettings: {
acceptedTos: boolean,
installationId: ?string,
Expand Down

0 comments on commit 2d16b3f

Please sign in to comment.