1- import React , { memo } from 'react' ;
1+ import React , { memo , useCallback } from 'react' ;
22import isEqual from 'react-fast-compare' ;
3- import { useTranslation } from 'react-i18next' ;
4- import { FlatList , RefreshControl , SafeAreaView , View } from 'react-native' ;
5- import { dispatch } from '@common/redux' ;
6- import { scale } from '@common/scale' ;
7- import { actionsApp } from '@store/app_reducer' ;
8- import { Button , Spinner , Text , Thumbnail } from 'native-base' ;
9- import { useCategoryProducts } from '@lib/logic/product/useCategoryProducts' ;
10- import { removeCustomerToken } from '@lib/utils' ;
11- import { formatMoney } from '@utils/money/money' ;
12- import { useTheme } from '@react-navigation/native' ;
3+ import { useTranslation } from 'react-i18next' ;
4+ import {
5+ Alert ,
6+ FlatList ,
7+ RefreshControl ,
8+ SafeAreaView ,
9+ View ,
10+ } from 'react-native' ;
11+ import { dispatch } from '@common/redux' ;
12+ import { scale } from '@common/scale' ;
13+ import { actionsApp } from '@store/app_reducer' ;
14+ import { Button , Icon , Spinner , Text , Thumbnail } from 'native-base' ;
15+ import { useCategoryProducts } from '@lib/logic/product/useCategoryProducts' ;
16+ import { removeCustomerToken } from '@lib/utils' ;
17+ import { formatMoney } from '@utils/money/money' ;
18+ import { useTheme } from '@react-navigation/native' ;
1319import GenericTemplate from '@lib/components/GenericTemplate/GenericTemplate' ;
14- import { styles } from '@containers/launches/style' ;
15- import { NetworkStatus } from '@apollo/client' ;
20+ import { styles } from '@containers/launches/style' ;
21+ import { NetworkStatus } from '@apollo/client' ;
22+ import { NavigationService } from '@navigation/navigationService' ;
23+ import { APP_SCREEN } from '@navigation/screenTypes' ;
24+ import { ProductInListType } from '@lib/apollo/queries/productsFragment' ;
1625
1726const LaunchesScreen : React . FC = ( ) => {
18- const { t } = useTranslation ( ) ;
27+ const { t } = useTranslation ( ) ;
1928 const theme = useTheme ( ) ;
2029
2130 const {
@@ -26,13 +35,31 @@ const LaunchesScreen: React.FC = () => {
2635 loadMore,
2736 networkStatus,
2837 isLoadMore,
29- } = useCategoryProducts ( { categoryId : '2' } ) ;
38+ } = useCategoryProducts ( { categoryId : '2' } ) ;
3039
31- const onLogout = async ( ) => {
32- await removeCustomerToken ( ) ;
33- dispatch ( actionsApp . onLogout ( ) ) ;
40+ const onLogout = ( ) => {
41+ Alert . alert ( 'Logout' , t ( 'question:are_you_sure' ) , [
42+ {
43+ text : 'Cancel' ,
44+ onPress : ( ) => { } ,
45+ style : 'destructive' ,
46+ } ,
47+ {
48+ text : 'OK' ,
49+ onPress : async ( ) => {
50+ await removeCustomerToken ( ) ;
51+ dispatch ( actionsApp . onLogout ( ) ) ;
52+ } ,
53+ } ,
54+ ] ) ;
3455 } ;
3556
57+ const goToProductDetails = useCallback ( ( item : ProductInListType ) => {
58+ NavigationService . navigate ( APP_SCREEN . PRODUCT_DETAILS , {
59+ sku : item ?. sku ,
60+ } ) ;
61+ } , [ ] ) ;
62+
3663 const renderFooterComponent = ( ) => {
3764 return (
3865 ( networkStatus === NetworkStatus . fetchMore && isLoadMore && (
@@ -43,11 +70,13 @@ const LaunchesScreen: React.FC = () => {
4370 ) ;
4471 } ;
4572
46- const renderItem = ( { item } : { item : any ; index : number } ) => {
73+ const renderItem = ( { item} : { item : any ; index : number } ) => {
4774 return (
48- < View style = { styles ( theme ) . itemContainer } >
75+ < Button
76+ style = { styles ( theme ) . itemContainer }
77+ onPress = { ( ) => goToProductDetails ( item ) } >
4978 < Thumbnail
50- source = { { uri : item . image . url } }
79+ source = { { uri : item . image . url } }
5180 style = { {
5281 marginLeft : scale ( 10 ) ,
5382 marginTop : scale ( 5 ) ,
@@ -72,14 +101,14 @@ const LaunchesScreen: React.FC = () => {
72101 { formatMoney ( item ?. price_range ?. minimum_price ?. regular_price . value ) }
73102 </ Text >
74103 </ View >
75- </ View >
104+ </ Button >
76105 ) ;
77106 } ;
78107
79108 return (
80109 < SafeAreaView style = { styles ( theme ) . container } >
81110 < GenericTemplate
82- style = { { alignItems : 'center' } }
111+ style = { { alignItems : 'center' } }
83112 loading = { loading && ! refreshing && ! isLoadMore } >
84113 < Text style = { styles ( ) . header } > RN Graphql Boilerplate</ Text >
85114 < FlatList
@@ -100,12 +129,25 @@ const LaunchesScreen: React.FC = () => {
100129 } }
101130 ListFooterComponent = { renderFooterComponent }
102131 />
132+ < Button
133+ style = { {
134+ position : 'absolute' ,
135+ right : scale ( 10 ) ,
136+ height : scale ( 30 ) ,
137+ alignItems : 'center' ,
138+ width : scale ( 40 ) ,
139+ borderRadius : scale ( 10 ) ,
140+ } }
141+ onPress = { onLogout } >
142+ < Icon
143+ name = { 'log-out' }
144+ style = { {
145+ height : scale ( 25 ) ,
146+ width : scale ( 25 ) ,
147+ } }
148+ />
149+ </ Button >
103150 </ GenericTemplate >
104- < Button
105- style = { { alignSelf : 'center' , marginVertical : scale ( 10 ) } }
106- onPress = { onLogout } >
107- < Text style = { { color : 'white' } } > { t ( 'logout' ) } </ Text >
108- </ Button >
109151 </ SafeAreaView >
110152 ) ;
111153} ;
0 commit comments