index.tsx 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import React, { useState } from 'react';
  2. import { View, Text, FlatList, TouchableOpacity, StyleSheet, Dimensions } from 'react-native';
  3. import { useNavigation } from '@react-navigation/native';
  4. import { Colors } from '../../../theme';
  5. import { PageWrapper, WarningModal } from '../../../components';
  6. import { NAVIGATION_PAGES } from 'src/types';
  7. import { storage, StoreType } from '../../../storage';
  8. import FlagsIcon from '../../../../assets/icons/travels-section/flags.svg';
  9. import RegionsIcon from '../../../../assets/icons/travels-section/regions.svg';
  10. import MapLocationIcon from '../../../../assets/icons/travels-section/map-location.svg';
  11. import SeriesIcon from '../../../../assets/icons/travels-section/series.svg';
  12. import EarthIcon from '../../../../assets/icons/travels-section/earth.svg';
  13. import TripIcon from '../../../../assets/icons/travels-section/trip.svg';
  14. import ImagesIcon from '../../../../assets/icons/travels-section/images.svg';
  15. const TravelsScreen = () => {
  16. const [isModalVisible, setIsModalVisible] = useState(false);
  17. const token = storage.get('token', StoreType.STRING);
  18. const navigation = useNavigation();
  19. const buttons = [
  20. { label: 'Countries', icon: FlagsIcon, page: NAVIGATION_PAGES.COUNTRIES },
  21. { label: 'Regions', icon: RegionsIcon, page: NAVIGATION_PAGES.REGIONS },
  22. { label: 'DARE', icon: MapLocationIcon, page: NAVIGATION_PAGES.DARE },
  23. { label: 'Series', icon: SeriesIcon, page: NAVIGATION_PAGES.SERIES },
  24. { label: 'Earth', icon: EarthIcon, page: NAVIGATION_PAGES.EARTH },
  25. { label: 'Trips', icon: TripIcon, page: NAVIGATION_PAGES.TRIPS },
  26. { label: 'Photos', icon: ImagesIcon, page: NAVIGATION_PAGES.PHOTOS }
  27. ];
  28. const handlePress = (page: string) => {
  29. if (!token) {
  30. setIsModalVisible(true);
  31. } else {
  32. navigation.navigate(page as never);
  33. }
  34. };
  35. const renderItem = ({ item }: { item: { label: string; icon: any; page: string } }) => (
  36. <TouchableOpacity style={{ alignItems: 'center' }} onPress={() => handlePress(item.page)}>
  37. <View style={styles.button}>
  38. <item.icon
  39. fill={Colors.ORANGE}
  40. width={Dimensions.get('window').width < 380 ? 105 : 110}
  41. height={32}
  42. />
  43. <Text style={styles.label}>{item.label}</Text>
  44. </View>
  45. </TouchableOpacity>
  46. );
  47. return (
  48. <PageWrapper>
  49. <FlatList
  50. data={buttons}
  51. renderItem={renderItem}
  52. keyExtractor={(item, index) => 'key' + index}
  53. numColumns={2}
  54. contentContainerStyle={styles.container}
  55. style={{ flex: 1, paddingTop: 16 }}
  56. columnWrapperStyle={{ justifyContent: 'space-between' }}
  57. />
  58. <WarningModal
  59. type="unauthorized"
  60. isVisible={isModalVisible}
  61. onClose={() => setIsModalVisible(false)}
  62. />
  63. </PageWrapper>
  64. );
  65. };
  66. const styles = StyleSheet.create({
  67. container: {
  68. justifyContent: 'space-between',
  69. paddingHorizontal: Dimensions.get('window').width < 380 ? '5%' : 24,
  70. paddingVertical: 8,
  71. gap: 32,
  72. width: '100%'
  73. },
  74. button: {
  75. alignItems: 'center',
  76. justifyContent: 'center',
  77. paddingVertical: 16,
  78. paddingHorizontal: 8,
  79. backgroundColor: Colors.WHITE,
  80. borderRadius: 16,
  81. gap: 12
  82. },
  83. label: {
  84. color: Colors.DARK_BLUE,
  85. fontSize: 13,
  86. fontWeight: 'bold'
  87. }
  88. });
  89. export default TravelsScreen;