-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Later on improve the logic, but now start with the boilerplate
- Loading branch information
1 parent
41e0515
commit 5740430
Showing
7 changed files
with
131 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React from 'react'; | ||
import RN from 'react-native'; | ||
import * as RD from '@devexperts/remote-data-ts'; | ||
|
||
import { StackScreenProps } from '@react-navigation/stack'; | ||
import { StackRoutes } from '..'; | ||
|
||
import * as redux from 'redux'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { selectClientVersions } from 'src/state/reducers/minimumVersion'; | ||
|
||
import * as actions from '../../state/actions'; | ||
|
||
import colors from '../components/colors'; | ||
|
||
export type VersionCheckRoute = { | ||
VersionCheck: {}; | ||
}; | ||
|
||
type Props = StackScreenProps<StackRoutes, 'VersionCheck'>; | ||
|
||
const VersionCheck = ({ navigation }: Props) => { | ||
const dispatch = useDispatch<redux.Dispatch<actions.Action>>(); | ||
React.useEffect(() => { | ||
dispatch({ type: 'minimumVersion/get/start', payload: undefined }); | ||
}, []); | ||
|
||
const versionState = useSelector(selectClientVersions); | ||
|
||
React.useEffect(() => { | ||
if (RD.isSuccess(versionState)) { | ||
navigation.replace('Splash', {}); | ||
} | ||
}, [versionState]); | ||
|
||
return <RN.View style={styles.background} />; | ||
}; | ||
|
||
const styles = RN.StyleSheet.create({ | ||
background: { | ||
backgroundColor: colors.purplePale, | ||
flex: 1, | ||
}, | ||
}); | ||
|
||
export default VersionCheck; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import * as t from 'io-ts'; | ||
import * as TE from 'fp-ts/lib/TaskEither'; | ||
|
||
import * as http from '../lib/http'; | ||
|
||
import * as config from './config'; | ||
|
||
const clientVersions = t.strict({ | ||
ylitse_ios: t.string, | ||
ylitse_android: t.string, | ||
}); | ||
|
||
const versionsResponse = t.strict({ | ||
resources: clientVersions, | ||
}); | ||
|
||
export type ClientVersions = t.TypeOf<typeof clientVersions>; | ||
|
||
export const fetchVersions: () => TE.TaskEither<string, ClientVersions> = () => | ||
http.validateResponse( | ||
http.get(`${config.baseUrl}/version/clients`), | ||
versionsResponse, | ||
response => response.resources, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Reducer } from 'redux-automaton'; | ||
import * as RD from '@devexperts/remote-data-ts'; | ||
import * as automaton from 'redux-automaton'; | ||
import * as actions from '../actions'; | ||
import * as T from 'fp-ts/lib/Task'; | ||
|
||
import * as minimumVersionApi from '../../api/minimumVersion'; | ||
import { cmd } from '../middleware'; | ||
|
||
import { Action } from '../actions'; | ||
import { AppState } from '../types'; | ||
|
||
import { pipe } from 'fp-ts/lib/function'; | ||
|
||
export const initialState = RD.initial; | ||
|
||
export const reducer: Reducer<AppState['minimumVersion'], Action> = ( | ||
state = initialState, | ||
action, | ||
) => { | ||
switch (action.type) { | ||
case 'minimumVersion/get/start': { | ||
if (RD.isPending(state)) { | ||
return state; | ||
} | ||
|
||
return automaton.loop( | ||
RD.pending, | ||
cmd( | ||
pipe( | ||
minimumVersionApi.fetchVersions(), | ||
T.map(actions.make('minimumVersion/get/end')), | ||
), | ||
), | ||
); | ||
} | ||
|
||
case 'minimumVersion/get/end': { | ||
return pipe(action.payload, RD.fromEither); | ||
} | ||
|
||
default: { | ||
return state; | ||
} | ||
} | ||
}; | ||
|
||
export const selectClientVersions = ({ minimumVersion }: AppState) => | ||
minimumVersion; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters