-
Notifications
You must be signed in to change notification settings - Fork 121
/
LibraryScreen.tsx
62 lines (50 loc) · 2.23 KB
/
LibraryScreen.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import React from 'react';
import { NavigationStackScreenProps } from 'react-navigation-stack/lib/typescript/types';
import AuthenticatedLock from '../components/AuthenticatedLock';
import BlockButton from '../components/BlockButton';
import { TouchableScale } from '../components/common';
import GuestInfo from '../components/GuestInfo';
import { withDelayedLoading } from '../components/hoc/withDelayedLoading';
import ScreenWrapper from '../components/ScreenWrapper';
import { getLibraryFavoriteIcon, getLibrarySettingsIcon, getLibraryWatchlistIcon } from '../helpers/icons';
import { librarySectionsKeys, sectionData } from '../redux/sections/sectionData';
import { LibrarySectionKey } from '../redux/sections/types';
import NavigationService from '../routes/NavigationService';
import { routeNames } from '../routes/routeNames';
import { SectionListScreenNavigationParams } from './movie/SectionListScreen';
/* ------------- Props and State ------------- */
type NavigationProps = NavigationStackScreenProps<{}>;
type Props = NavigationProps;
const librarySectionIcons: Record<LibrarySectionKey, JSX.Element> = {
myWatchlist: getLibraryWatchlistIcon(),
myFavorite: getLibraryFavoriteIcon(),
};
const navigateToSettings = () => {
NavigationService.navigate(routeNames.Settings);
};
/* ------------- Component ------------- */
class Library extends React.PureComponent<Props> {
static navigationOptions = {
headerRight: <TouchableScale onPress={navigateToSettings}>{getLibrarySettingsIcon()}</TouchableScale>,
};
renderLibrarySections = () => {
const { navigation } = this.props;
return librarySectionsKeys.map(sectionKey => {
const { title } = sectionData[sectionKey];
const onPress = () => {
const params: SectionListScreenNavigationParams = { sectionKey };
navigation.navigate(routeNames.SectionListScreen, params);
};
const Icon = librarySectionIcons[sectionKey];
return <BlockButton key={sectionKey} text={title} Icon={Icon} onPress={onPress} />;
});
};
render() {
return (
<ScreenWrapper>
<AuthenticatedLock placeholder={<GuestInfo />}>{this.renderLibrarySections()}</AuthenticatedLock>
</ScreenWrapper>
);
}
}
export default withDelayedLoading(Library);