ordering-ui-react-native 0.8.6 → 0.8.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ordering-ui-react-native",
3
- "version": "0.8.6",
3
+ "version": "0.8.7",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -60,6 +60,7 @@
60
60
  "react-native-app-intro-slider": "^4.0.4",
61
61
  "react-native-awesome-alerts": "^1.4.2",
62
62
  "react-native-awesome-loading": "^1.0.15",
63
+ "react-native-background-timer": "^2.4.1",
63
64
  "react-native-bootsplash": "^3.2.3",
64
65
  "react-native-country-picker-modal": "^2.0.0",
65
66
  "react-native-credit-card-input": "^0.4.1",
@@ -1,6 +1,5 @@
1
1
  import React, { useState, useEffect } from 'react'
2
2
  import { OrderList, useLanguage, useOrder, ToastType, useToast } from 'ordering-components/native'
3
- import { useFocusEffect } from '@react-navigation/native'
4
3
  import { OText } from '../shared'
5
4
  import { NotFoundSource } from '../NotFoundSource'
6
5
  import { ActiveOrders } from '../ActiveOrders'
@@ -62,7 +61,7 @@ const OrdersOptionUI = (props: OrdersOptionParams) => {
62
61
  }
63
62
  setReorderLoading(false)
64
63
 
65
- } catch (err) {
64
+ } catch (err: any) {
66
65
  showToast(ToastType.Error, t('ERROR', err.message))
67
66
  setReorderLoading(false)
68
67
  }
@@ -100,16 +99,6 @@ const OrdersOptionUI = (props: OrdersOptionParams) => {
100
99
  return objectStatus && objectStatus
101
100
  }
102
101
 
103
- useFocusEffect(
104
- React.useCallback(() => {
105
- loadOrders && loadOrders()
106
- setIsLoadingFirstRender(false)
107
- return () => {
108
- setIsLoadingFirstRender(true)
109
- }
110
- }, [navigation])
111
- )
112
-
113
102
  useEffect(() => {
114
103
  setOrdersLength && setOrdersLength({
115
104
  ...ordersLength,
@@ -1,9 +1,11 @@
1
1
  import * as React from 'react';
2
+ import { AppState } from 'react-native'
2
3
  import { createStackNavigator } from "@react-navigation/stack";
3
- import { useSession, useOrder } from 'ordering-components/native';
4
+ import { useSession, useOrder, useWebsocket } from 'ordering-components/native';
4
5
  import BottomNavigator from '../navigators/BottomNavigator';
5
6
  import RootNavigator from '../navigators/RootNavigator';
6
7
  import CheckoutNavigator from '../navigators/CheckoutNavigator';
8
+ import BackgroundTimer from 'react-native-background-timer';
7
9
 
8
10
  import AddressList from '../pages/AddressList';
9
11
  import AddressForm from '../pages/AddressForm';
@@ -22,7 +24,30 @@ const Stack = createStackNavigator();
22
24
 
23
25
  const HomeNavigator = (e : any) => {
24
26
  const [orderState] = useOrder();
25
- const [{ auth }] = useSession();
27
+ const [{ auth, user }] = useSession();
28
+ const socket = useWebsocket();
29
+
30
+ const appState = React.useRef(AppState.currentState);
31
+ let interval: any
32
+
33
+ const _handleAppStateChange = (nextAppState: any) => {
34
+ if (appState.current.match(/inactive|background/) && nextAppState === 'active') {
35
+ BackgroundTimer.clearInterval(interval)
36
+ }else{
37
+ interval = BackgroundTimer.setInterval(()=>{
38
+ const ordersRoom = user?.level === 0 ? 'orders' : `orders_${user?.id}`
39
+ socket.join(ordersRoom)
40
+ }, 5000)
41
+ appState.current = nextAppState;
42
+ }
43
+ }
44
+
45
+ React.useEffect (() => {
46
+ AppState.addEventListener('change', _handleAppStateChange);
47
+ return () => {
48
+ AppState.removeEventListener('change', _handleAppStateChange);
49
+ };
50
+ },[])
26
51
 
27
52
  return (
28
53
  <Stack.Navigator>
@@ -0,0 +1 @@
1
+ declare module 'react-native-background-timer'
@@ -334,6 +334,11 @@ export const MessagesOption = (props: MessagesOptionParams) => {
334
334
  param: 'last_direct_message_at',
335
335
  direction: 'asc',
336
336
  },
337
+ paginationSettings: {
338
+ page: 1,
339
+ pageSize: 45,
340
+ controlType: 'infinity',
341
+ },
337
342
  UIComponent: MessagesOptionUI,
338
343
  };
339
344
 
@@ -270,8 +270,8 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
270
270
  // redirectToSettings();
271
271
  showToast(
272
272
  ToastType.Error,
273
- ('GEOLOCATION_SERVICE_PERMISSION_BLOCKED',
274
- 'Geolocation service permissions blocked.'),
273
+ t('GEOLOCATION_SERVICE_PERMISSION_BLOCKED',
274
+ 'Geolocation service permissions blocked.'),
275
275
  );
276
276
  } else {
277
277
  const response = await askLocationPermission();
@@ -618,18 +618,18 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
618
618
 
619
619
  {(order?.summary?.delivery_price > 0 ||
620
620
  order?.deliveryFee > 0) && (
621
- <Table>
622
- <OText mBottom={4}>
623
- {t('DELIVERY_FEE', 'Delivery Fee')}
624
- </OText>
621
+ <Table>
622
+ <OText mBottom={4}>
623
+ {t('DELIVERY_FEE', 'Delivery Fee')}
624
+ </OText>
625
625
 
626
- <OText mBottom={4}>
627
- {parsePrice(
628
- order?.summary?.delivery_price || order?.deliveryFee,
629
- )}
630
- </OText>
631
- </Table>
632
- )}
626
+ <OText mBottom={4}>
627
+ {parsePrice(
628
+ order?.summary?.delivery_price || order?.deliveryFee,
629
+ )}
630
+ </OText>
631
+ </Table>
632
+ )}
633
633
 
634
634
  <Table>
635
635
  <OText mBottom={4}>
@@ -754,7 +754,7 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
754
754
  <View style={{ height: 30 }} />
755
755
  </OrderDetailsContainer>
756
756
 
757
- {showFloatButtonsPickUp[order?.status] && !loading && (
757
+ {showFloatButtonsPickUp[order?.status] && (
758
758
  <FloatingButton
759
759
  disabled={loading}
760
760
  btnText={t('FAILED', 'Failed')}
@@ -12,7 +12,6 @@ import { Placeholder, PlaceholderLine, Fade } from 'rn-placeholder';
12
12
  import { OText, OIconButton, OButton } from '../shared';
13
13
  import { PreviousOrders } from '../PreviousOrders';
14
14
  import { NotFoundSource } from '../NotFoundSource';
15
- import { useFocusEffect } from '@react-navigation/native';
16
15
  import { FiltersTab, TabsContainer, Tag } from './styles';
17
16
  import { OrdersOptionParams } from '../../types';
18
17
 
@@ -131,7 +130,6 @@ const OrdersOptionUI = (props: OrdersOptionParams) => {
131
130
  const [tabsFilter, setTabsFilter] = useState(tabs[0].tags);
132
131
  const [tagsFilter, setTagsFilter] = useState(tabs[0].tags);
133
132
  const [loadingTag, setLoadingTag] = useState(false);
134
- const [isLoadingFirstRender, setIsLoadingFirstRender] = useState(false);
135
133
  const [reload, setReload] = useState(false);
136
134
  const [orientation, setOrientation] = useState(
137
135
  Dimensions.get('window').width < Dimensions.get('window').height
@@ -142,16 +140,6 @@ const OrdersOptionUI = (props: OrdersOptionParams) => {
142
140
  parseInt(parseFloat(String(Dimensions.get('window').width)).toFixed(0)),
143
141
  );
144
142
 
145
- useFocusEffect(
146
- React.useCallback(() => {
147
- loadOrders && loadOrders(true, rememberOrderStatus);
148
- setIsLoadingFirstRender(false);
149
- return () => {
150
- setIsLoadingFirstRender(true);
151
- };
152
- }, [navigation, rememberOrderStatus]),
153
- );
154
-
155
143
  const handleChangeTab = (tags: number[]) => {
156
144
  setTabsFilter(tags);
157
145
  setRememberOrderStatus(tags);
@@ -410,19 +398,15 @@ const OrdersOptionUI = (props: OrdersOptionParams) => {
410
398
  )}
411
399
 
412
400
  <ScrollView showsVerticalScrollIndicator={false} style={{ flex: 1 }}>
413
- {!reload &&
414
- !error &&
415
- orders.length > 0 &&
416
- !loadingTag &&
417
- !isLoadingFirstRender && (
418
- <PreviousOrders
419
- orders={ordersToShow}
420
- onNavigationRedirect={onNavigationRedirect}
421
- getOrderStatus={getOrderStatus}
422
- />
423
- )}
401
+ {!reload && !error && orders.length > 0 && !loadingTag && (
402
+ <PreviousOrders
403
+ orders={ordersToShow}
404
+ onNavigationRedirect={onNavigationRedirect}
405
+ getOrderStatus={getOrderStatus}
406
+ />
407
+ )}
424
408
 
425
- {(loading || isLoadingFirstRender) && (
409
+ {loading && (
426
410
  <>
427
411
  <View>
428
412
  {[...Array(5)].map((item, i) => (
@@ -458,7 +442,6 @@ const OrdersOptionUI = (props: OrdersOptionParams) => {
458
442
  pagination.totalPages &&
459
443
  !loading &&
460
444
  !!orders.length &&
461
- !isLoadingFirstRender &&
462
445
  pagination.currentPage < pagination.totalPages && (
463
446
  <OButton
464
447
  onClick={handleLoadMore}
@@ -486,7 +469,7 @@ export const OrdersOption = (props: OrdersOptionParams) => {
486
469
  useDefualtSessionManager: true,
487
470
  paginationSettings: {
488
471
  initialPage: 1,
489
- pageSize: 6,
472
+ pageSize: 45,
490
473
  controlType: 'infinity',
491
474
  },
492
475
 
@@ -1,5 +1,5 @@
1
1
  import React, { useEffect, useState } from 'react';
2
- import { View, StyleSheet, ScrollView } from 'react-native';
2
+ import { View, StyleSheet, ScrollView, ActivityIndicator } from 'react-native';
3
3
  import { useForm } from 'react-hook-form';
4
4
  import { launchImageLibrary } from 'react-native-image-picker';
5
5
  import { Placeholder, PlaceholderLine, Fade } from 'rn-placeholder';
@@ -45,6 +45,7 @@ const ProfileUI = (props: ProfileParams) => {
45
45
  cleanFormState,
46
46
  handleToggleAvalaibleStatusDriver,
47
47
  userState,
48
+ isAvailableLoading,
48
49
  } = props;
49
50
 
50
51
  const [{ user }] = useSession();
@@ -272,20 +273,24 @@ const ProfileUI = (props: ProfileParams) => {
272
273
  )}
273
274
  </OText>
274
275
 
275
- <ToggleSwitch
276
- isOn={userState?.result?.result?.available}
277
- onColor={theme.colors.primary}
278
- offColor={theme.colors.offColor}
279
- size="small"
280
- onToggle={() =>
281
- handleToggleAvalaibleStatusDriver &&
282
- handleToggleAvalaibleStatusDriver(
283
- !userState?.result?.result?.available,
284
- )
285
- }
286
- disabled={userState?.loading}
287
- animationSpeed={200}
288
- />
276
+ {isAvailableLoading ? (
277
+ <ActivityIndicator size="small" color={theme.colors.primary} />
278
+ ) : (
279
+ <ToggleSwitch
280
+ isOn={userState?.result?.result?.available}
281
+ onColor={theme.colors.primary}
282
+ offColor={theme.colors.offColor}
283
+ size="small"
284
+ onToggle={() =>
285
+ handleToggleAvalaibleStatusDriver &&
286
+ handleToggleAvalaibleStatusDriver(
287
+ !userState?.result?.result?.available,
288
+ )
289
+ }
290
+ disabled={userState?.loading}
291
+ animationSpeed={200}
292
+ />
293
+ )}
289
294
  </EnabledStatusDriver>
290
295
  )}
291
296
 
@@ -28,6 +28,7 @@ export interface ProfileParams {
28
28
  toggleIsEdit?: any;
29
29
  cleanFormState?: any;
30
30
  setFormState?: any;
31
+ isAvailableLoading?: boolean;
31
32
  handleChangeInput?: any;
32
33
  handleButtonUpdateClick?: any;
33
34
  handleToggleAvalaibleStatusDriver?: any;