Advertisement
Guest User

App.js

a guest
Jul 19th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from 'react';
  2. import { API_URL } from 'react-native-dotenv';
  3. import { Platform, AsyncStorage } from 'react-native';
  4. import { createBottomTabNavigator, createStackNavigator, createSwitchNavigator } from 'react-navigation';
  5. import CustomTabBar from './Custom/CustomTabBar';
  6. import CustomHeader from './Custom/CustomHeader';
  7. import OneSignal from 'react-native-onesignal';
  8. import Login from './Login';
  9. import Register from './Register';
  10. import ForgotPassword from './ForgotPassword';
  11. import MyAccount from './More/MyAccount';
  12. import Privacy from './More/Privacy';
  13. import MyPromoCodes from './More/MyPromoCodes';
  14. import MyBookings from './More/MyBookings';
  15. import MyOrders from './More/MyOrders';
  16. import MyFavorites from './More/MyFavorites';
  17. import MyPreOrders from './More/MyPreOrders';
  18. import VenuePromo from './Promo/VenuePromo';
  19. import BookingPromo from './Promo/BookingPromo';
  20. import DeliveryPromo from './Promo/DeliveryPromo';
  21. import PreOrderPromo from './Promo/PreOrderPromo';
  22. import PickUpPromo from './Promo/PickUpPromo';
  23. import MenuPromo from './Promo/MenuPromo';
  24. import MediaPromo from './Promo/MediaPromo';
  25. import VicePost from './Vice/VicePost';
  26. import Venue from './Venue/Venue';
  27. import VenueMedia from './Venue/VenueMedia';
  28. import VenueMenu from './Venue/VenueMenu';
  29. import Booking from './Venue/Order/Booking';
  30. import PreOrder from './Venue/Order/PreOrder';
  31. import PickUp from './Venue/Order/PickUp';
  32. import Delivery from './Venue/Order/Delivery';
  33. import ViceUser from './Vice/ViceUser';
  34. import ViceVenue from './Vice/ViceVenue';
  35. import ViceMedia from './Vice/ViceMedia';
  36. import Review from './Vice/Review';
  37. import Payment from './Payment/Payment';
  38. import ChatMessaging from './Chat/ChatMessaging';
  39. import Filter from './Filter';
  40. import LoadingScreen from './LoadingScreen'
  41. import More from './More/More';
  42. import Vice from './Vice/Vice';
  43. import Venues from './Venue/Venues';
  44. import Promos from './Promo/Promos';
  45. import Chats from './Chat/Chats';
  46. import Search from './Search';
  47.  
  48. const PromosStack = createStackNavigator(
  49.   {
  50.     Promos: Promos,
  51.     VenuePromo: {
  52.       screen: VenuePromo,
  53.       path: 'venue_promo/:promo',
  54.     },
  55.     BookingPromo: {
  56.       screen: BookingPromo,
  57.       path: 'booking_promo/:promo'
  58.     },
  59.     DeliveryPromo: {
  60.       screen: DeliveryPromo,
  61.       path: 'delivery_promo/:promo'
  62.     },
  63.     PreOrderPromo: {
  64.       screen: PreOrderPromo,
  65.       path: 'pre_order_promo/:promo'
  66.     },
  67.     MenuPromo: {
  68.       screen: MenuPromo,
  69.       path: 'menu_promo/:promo'
  70.     },
  71.     MediaPromo: {
  72.       screen: MediaPromo,
  73.       path: 'media_promo/:promo'
  74.     },
  75.     PickUpPromo: {
  76.       screen: PickUpPromo,
  77.       path: 'pick_up_promo/:promo'
  78.     },
  79.     Filter: Filter,
  80.     Search: Search,
  81.   },
  82.   {
  83.     initialRouteName: 'Promos',
  84.     navigationOptions: {
  85.       header: (props) => <CustomHeader {...props} />,
  86.       headerTransparent: true,
  87.       headerTintColor: 'white',
  88.       headerStyle: {
  89.         borderBottomWidth: 0, // Remove the hairline bottom border
  90.         ...Platform.select({
  91.           android: {
  92.             shadowColor: 'transparent',
  93.             shadowOpacity: 0,
  94.             shadowRadius: 0,
  95.             shadowOffset: {
  96.               height: 0,
  97.               width: 0,
  98.             },
  99.             elevation: 0,
  100.           }
  101.         }),
  102.       },
  103.     }
  104.   }
  105. );
  106.  
  107. const ViceStack = createStackNavigator(
  108.   {
  109.     Vice: Vice,
  110.     ViceUser: {
  111.       screen: ViceUser,
  112.       path: 'vice_user/:from/:name'
  113.     },
  114.     ViceVenue: {
  115.       screen: ViceVenue,
  116.       path: 'vice_venue/:venue'
  117.     },
  118.     ViceMedia: {
  119.       screen: ViceMedia,
  120.       path: 'vice_media/:venue'
  121.     },
  122.     Venue: {
  123.       screen: Venue,
  124.       path: 'venue/:venue'
  125.     },
  126.     Review: Review,
  127.     Payment: Payment,
  128.     Filter: Filter,
  129.     Search: Search,
  130.   },
  131.   {
  132.     initialRouteName: 'Vice',
  133.     navigationOptions: {
  134.       header: (props) => <CustomHeader {...props} />,
  135.       headerTransparent: true,
  136.       headerTintColor: 'white',
  137.       headerStyle: {
  138.         borderBottomWidth: 0, // Remove the hairline bottom border
  139.         ...Platform.select({
  140.           android: {
  141.             shadowColor: 'transparent',
  142.             shadowOpacity: 0,
  143.             shadowRadius: 0,
  144.             shadowOffset: {
  145.               height: 0,
  146.               width: 0,
  147.             },
  148.             elevation: 0,
  149.           }
  150.         }),
  151.       }
  152.     }
  153.   }
  154. );
  155.  
  156. const VenuesStack = createStackNavigator(
  157.   {
  158.     Venues: Venues,
  159.     Venue: {
  160.       screen: Venue,
  161.       path: 'venue/:venue'
  162.     },
  163.     VenueMedia: {
  164.       screen: VenueMedia,
  165.       path: 'venue_media/:venue'
  166.     },
  167.     VenueMenu: {
  168.       screen: VenueMenu,
  169.       path: 'venue_menu/:venue'
  170.     },
  171.     Booking: {
  172.       screen: Booking,
  173.       path: 'booking/:venue'
  174.     },
  175.  
  176.     Delivery: {
  177.       screen: Delivery,
  178.       path: 'delivery:/venue'
  179.     },
  180.     PreOrder: {
  181.       screen: PreOrder,
  182.       path: 'pre_order/:venue'
  183.     },
  184.     PickUpPromo: {
  185.       screen: PickUpPromo,
  186.       path: 'pick_up_promo/:promo'
  187.     },
  188.     PickUp: {
  189.       screen: PickUp,
  190.       path: 'pick_up/:venue'
  191.     },
  192.     Post: {
  193.       screen: VicePost,
  194.       path: 'post/:post/:venue'
  195.     },
  196.     Review: Review,
  197.     Payment: Payment,
  198.     Filter: Filter,
  199.     Search: Search,
  200.   },
  201.   {
  202.     navigationOptions: {
  203.       initialRouteName: 'Venues',
  204.       header: (props) => <CustomHeader {...props} />,
  205.       headerTransparent: true,
  206.       headerTintColor: 'white',
  207.       headerStyle: {
  208.         borderBottomWidth: 0, // Remove the hairline bottom border
  209.         ...Platform.select({
  210.           android: {
  211.             shadowColor: 'transparent',
  212.             shadowOpacity: 0,
  213.             shadowRadius: 0,
  214.             shadowOffset: {
  215.               height: 0,
  216.               width: 0,
  217.             },
  218.             elevation: 0,
  219.           }
  220.         }),
  221.       },
  222.     }
  223.   }
  224. );
  225.  
  226. const ChatsStack = createStackNavigator(
  227.   {
  228.     Chats: Chats,
  229.     ChatMessaging: {
  230.       screen: ChatMessaging,
  231.       path: 'chat_messaging/:chat_id'
  232.     },
  233.     Review: Review,
  234.     Payment: Payment,
  235.     Search: Search,
  236.   },
  237.   {
  238.     initialRouteName: 'Chats',
  239.     navigationOptions: {
  240.       header: (props) => <CustomHeader {...props} />,
  241.       headerTransparent: true,
  242.       headerTintColor: 'white',
  243.       headerStyle: {
  244.         borderBottomWidth: 0, // Remove the hairline bottom border
  245.         ...Platform.select({
  246.           android: {
  247.             shadowColor: 'transparent',
  248.             shadowOpacity: 0,
  249.             shadowRadius: 0,
  250.             shadowOffset: {
  251.               height: 0,
  252.               width: 0,
  253.             },
  254.             elevation: 0,
  255.           }
  256.         }),
  257.       },
  258.     }
  259.   }
  260. );
  261.  
  262. const MoreStack = createStackNavigator(
  263.   {
  264.     More: More,
  265.     MyAccount: MyAccount,
  266.     Privacy: Privacy,
  267.     MyPromoCodes: MyPromoCodes,
  268.     MyBookings: MyBookings,
  269.     MyOrders: MyOrders,
  270.     MyFavorites: MyFavorites,
  271.     MyPreOrders: MyPreOrders,
  272.     ViceUser: {
  273.       screen: ViceUser,
  274.       path: 'vice_user/:from/:name'
  275.     },
  276.     Post: {
  277.       screen: VicePost,
  278.       path: 'post/:post/:venue'
  279.     },
  280.   },
  281.   {
  282.     initialRouteName: 'More',
  283.     navigationOptions: {
  284.       header: (props) => <CustomHeader {...props} />,
  285.       headerTransparent: true,
  286.       headerTintColor: 'white',
  287.       headerStyle: {
  288.         borderBottomWidth: 0, // Remove the hairline bottom border
  289.         ...Platform.select({
  290.           android: {
  291.             shadowColor: 'transparent',
  292.             shadowOpacity: 0,
  293.             shadowRadius: 0,
  294.             shadowOffset: {
  295.               height: 0,
  296.               width: 0,
  297.             },
  298.             elevation: 0,
  299.           }
  300.         }),
  301.       },
  302.     }
  303.   }
  304. );
  305.  
  306. const AppStack = createBottomTabNavigator(
  307.   {
  308.     Promos: PromosStack,
  309.     Vice: ViceStack,
  310.     Venues: VenuesStack,
  311.     Chats: ChatsStack,
  312.     More: MoreStack,
  313.   }, {
  314.     tabBarComponent: (props) => <CustomTabBar {...props} />,
  315.     initialRouteName: 'Promos',
  316.   });
  317.  
  318. const AuthStack = createStackNavigator(
  319.   {
  320.     Login: Login,
  321.     Register: Register,
  322.     ForgotPassword: ForgotPassword,
  323.   }
  324. );
  325.  
  326. const AppNavigator = createSwitchNavigator(
  327.   {
  328.     AuthLoading: LoadingScreen,
  329.     App: AppStack,
  330.     Auth: AuthStack,
  331.   },
  332.   {
  333.     initialRouteName: 'AuthLoading'
  334.   }
  335. );
  336.  
  337. const prefix = Platform.OS === 'android' ? 'atlacarte://atlacarte/' : 'atlacarte://';
  338.  
  339. export default class App extends React.Component {
  340.   constructor(props) {
  341.     super(props)
  342.   }
  343.  
  344.   componentWillMount() {
  345.     OneSignal.addEventListener('received', this.onReceived)
  346.     OneSignal.addEventListener('opened', this.onOpened)
  347.     OneSignal.addEventListener('ids', this.onIds)
  348.     OneSignal.inFocusDisplaying(2)
  349.   }
  350.  
  351.   componentWillUnmount() {
  352.     OneSignal.removeEventListener('received', this.onReceived)
  353.     OneSignal.removeEventListener('opened', this.onOpened)
  354.     OneSignal.removeEventListener('ids', this.onIds)
  355.   }
  356.  
  357.   onReceived(notification) {
  358.     console.log(`Notification received: ${notification}`)
  359.   }
  360.  
  361.   onOpened(openResult) {
  362.     if (openResult.notification.payload.additionalData["type"] === "chat_id") {
  363.       this.props.navigation.navigate('ChatMessaging', {
  364.         chat_id: openResult.notification.payload.additionalData["chat_id"],
  365.         from: openResult.notification.payload.title
  366.       })
  367.     } else if (openResult.notification.payload.additionalData["type"] === "chat-id") {
  368.       this.props.navigation.navigate('ChatMessaging', {
  369.         chat_id: openResult.notification.payload.additionalData["chat-id"],
  370.         from: openResult.notification.payload.title
  371.       })
  372.     } else {
  373.       this.props.navigation.navigate('Promos')
  374.     }
  375.   }
  376.  
  377.   async onIds(device) {
  378.     console.log(`Device info: ${device}`)
  379.  
  380.     const token = await AsyncStorage.getItem('bearer')
  381.  
  382.     if (token !== null) {
  383.       fetch(`${API_URL}/api/v1/user/me/setDevice/${device.userId}`, {
  384.         method: 'GET',
  385.         headers: {
  386.           'Accept': 'javascript/json',
  387.           'Authorization': `Bearer ${token}`,
  388.           'Content-Type': 'multipart/form-data'
  389.         },
  390.       })
  391.     }
  392.   }
  393.  
  394.   render() {
  395.     return <AppNavigator uriPrefix={prefix} />;
  396.   }
  397. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement