Created
January 7, 2022 18:16
-
-
Save xiongemi/c011923fd46b1493463501229106f95e to your computer and use it in GitHub Desktop.
film react native component
This file contains hidden or 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
import { AnyAction, ThunkDispatch } from '@reduxjs/toolkit'; | |
import { | |
filmsActions, | |
filmsSelectors, | |
RootState, | |
} from '@studio-ghibli-search-engine/store'; | |
const mapStateToProps = (state: RootState) => { | |
return { | |
getFilm: (id: string) => filmsSelectors.selectFilmById(id)(state), | |
}; | |
}; | |
const mapDispatchToProps = ( | |
dispatch: ThunkDispatch<RootState, void, AnyAction> | |
) => { | |
return { | |
fetchFilms() { | |
dispatch(filmsActions.fetchFilms()); | |
}, | |
}; | |
}; | |
type mapStateToPropsType = ReturnType<typeof mapStateToProps>; | |
type mapDispatchToPropsType = ReturnType<typeof mapDispatchToProps>; | |
type FilmProps = mapStateToPropsType & mapDispatchToPropsType; | |
export { mapStateToProps, mapDispatchToProps }; | |
export type { FilmProps }; |
This file contains hidden or 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
import { RouteProp, useRoute } from '@react-navigation/native'; | |
import { FilmEntity } from '@studio-ghibli-search-engine/models'; | |
import { getEnv } from '@studio-ghibli-search-engine/services'; | |
import React, { useEffect, useState } from 'react'; | |
import { SafeAreaView, ScrollView, Image, View } from 'react-native'; | |
import { | |
Button, | |
Divider, | |
Headline, | |
Paragraph, | |
Subheading, | |
Title, | |
} from 'react-native-paper'; | |
import { styles } from 'react-native-style-tachyons'; | |
import { connect } from 'react-redux'; | |
import Loading from '../shared/loading/loading'; | |
import { useLink } from '../shared/open-link/open-link'; | |
import { FilmProps, mapDispatchToProps, mapStateToProps } from './film.props'; | |
export function Film({ getFilm, fetchFilms }: FilmProps) { | |
const [film, setFilm] = useState<FilmEntity>(); | |
const route = useRoute<RouteProp<{ params: { id: string } }>>(); | |
const id = route.params?.id; | |
const openHboMax = useLink(getEnv('NX_HBO_STREAMING_URL'), 'HBO Max'); | |
const openNetflix = useLink(getEnv('NX_NETFLIX_STREAMING_URL'), 'Netflix'); | |
useEffect(() => { | |
fetchFilms(); | |
}, [fetchFilms]); | |
useEffect(() => { | |
setFilm(getFilm(id)); | |
}, [id, getFilm]); | |
return film ? ( | |
<SafeAreaView> | |
<ScrollView contentInsetAdjustmentBehavior="automatic"> | |
<View style={[styles.pa3]}> | |
<Image | |
style={{ height: 200, width: '100%', resizeMode: 'contain' }} | |
source={{ uri: film.movieBanner }} | |
/> | |
<Headline>{film.title}</Headline> | |
<Subheading> | |
{film.originalTitle} / {film.originalTitleRomanised} | |
</Subheading> | |
<Paragraph>Release: {film.releaseDate}</Paragraph> | |
<Paragraph>Director: {film.director}</Paragraph> | |
<Paragraph>Producer: {film.producer}</Paragraph> | |
<Paragraph>Running Time: {film.runningTime} minutes</Paragraph> | |
<Paragraph>Rotten Tomatoes Score: {film.rtScore}</Paragraph> | |
<Divider /> | |
<Title>Plot</Title> | |
<Paragraph>{film.description}</Paragraph> | |
<Divider /> | |
<Button onPress={openHboMax}>Watch on HBO Max</Button> | |
<Button onPress={openNetflix}>Watch on Netflix</Button> | |
</View> | |
</ScrollView> | |
</SafeAreaView> | |
) : ( | |
<Loading /> | |
); | |
} | |
export default connect(mapStateToProps, mapDispatchToProps)(Film); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment