@@ -3,7 +3,7 @@ import { useQuery } from '@tanstack/react-query';
3
3
import dayjs from 'dayjs' ;
4
4
import { NetworkStateType , useNetworkState } from 'expo-network' ;
5
5
import { Link } from 'expo-router' ;
6
- import { includes } from 'lodash' ;
6
+ import { includes , sample } from 'lodash' ;
7
7
import React , { useCallback , useEffect , useMemo , useState } from 'react' ;
8
8
import { useTranslation } from 'react-i18next' ;
9
9
import { ScrollView , View } from 'react-native' ;
@@ -16,19 +16,20 @@ import Animated, {
16
16
FadeOutDown ,
17
17
StretchInY ,
18
18
} from 'react-native-reanimated' ;
19
+ import { toast } from 'sonner-native' ;
20
+ import tw , { useDeviceContext } from 'twrnc' ;
19
21
import AppText from '@/components/AppText' ;
20
22
import AppTouchable from '@/components/AppTouchable' ;
21
23
import ErrorBadge from '@/components/ErrorBagde' ;
22
- import { type PeriodType } from '@/components/Events/PeriodBottomSheet' ;
23
24
import AppointmentCard from '@/components/Home/AppointmentCard' ;
24
25
import AttendanceCount from '@/components/Home/AttendanceCount' ;
25
26
import BalanceBottomSheet from '@/components/Home/BalanceBottomSheet' ;
26
27
import BalanceCard from '@/components/Home/BalanceCard' ;
27
28
import BirthdayBottomSheet from '@/components/Home/BirthdayBottomSheet' ;
28
29
import BirthdayCard from '@/components/Home/BirthdayCard' ;
29
- import CalendarEmptyState from '@/components/Home/CalendarEmptyState' ;
30
30
import CalendarEventCard from '@/components/Home/CalendarEventCard' ;
31
31
import DevicesCard from '@/components/Home/DevicesCard' ;
32
+ import HomeCalendarEmptyState from '@/components/Home/HomeCalendarEmptyState' ;
32
33
import HomeLayout from '@/components/Home/HomeLayout' ;
33
34
import MembershipBottomSheet from '@/components/Home/MembershipBottomSheet' ;
34
35
import MembershipCard from '@/components/Home/MembershipCard' ;
@@ -56,8 +57,6 @@ import {
56
57
import useAuthStore from '@/stores/auth' ;
57
58
import useSettingsStore from '@/stores/settings' ;
58
59
import useToastStore from '@/stores/toast' ;
59
- import { toast } from 'sonner-native' ;
60
- import tw , { useDeviceContext } from 'twrnc' ;
61
60
62
61
const MAX_WIDTH = 672 ; // tw`max-w-2xl`
63
62
@@ -167,6 +166,7 @@ export default function HomeScreen() {
167
166
data : calendarEvents ,
168
167
isLoading : isLoadingCalendarEvents ,
169
168
isFetching : isFetchingCalendarEvents ,
169
+ dataUpdatedAt : calendarEventsUpdatedAt ,
170
170
refetch : refreshCalendarEvents ,
171
171
error : calendarEventsError ,
172
172
} = useQuery ( {
@@ -186,18 +186,6 @@ export default function HomeScreen() {
186
186
) ;
187
187
} , [ calendarEvents , activeSince ] ) ;
188
188
189
- const firstPeriodWithEvents : PeriodType = useMemo ( ( ) => {
190
- const [ nextEvent ] = nextCalendarEvents ?. filter ( ( { end } ) => dayjs ( ) . isBefore ( end ) ) || [ ] ;
191
- if ( nextEvent ) {
192
- if ( dayjs ( nextEvent . start ) . isSame ( dayjs ( ) , 'week' ) ) {
193
- return 'week' ;
194
- } else if ( dayjs ( nextEvent . start ) . isSame ( dayjs ( ) , 'month' ) ) {
195
- return 'month' ;
196
- }
197
- }
198
- return null ;
199
- } , [ nextCalendarEvents ] ) ;
200
-
201
189
const onRefresh = useCallback ( ( ) => {
202
190
return Promise . all ( [
203
191
authStore . user ?. id && refetchProfile ( ) ,
@@ -210,10 +198,10 @@ export default function HomeScreen() {
210
198
211
199
const onSuccessiveTaps = useCallback ( ( ) => {
212
200
toastStore . add ( {
213
- message : t ( 'home.onSuccessiveTaps.message' ) ,
201
+ message : ` ${ sample ( t ( 'home.onSuccessiveTaps.message' , { returnObjects : true } ) ) } ` ,
214
202
type : 'info' ,
215
203
action : {
216
- label : t ( 'home.onSuccessiveTaps.action' ) ,
204
+ label : ` ${ sample ( t ( 'home.onSuccessiveTaps.action' , { returnObjects : true } ) ) } ` ,
217
205
onPress : async ( ) => {
218
206
toast . dismiss ( ) ;
219
207
contact ( ) ;
@@ -337,6 +325,7 @@ export default function HomeScreen() {
337
325
error = {
338
326
currentMembersError && ! isSilentError ( currentMembersError ) ? currentMembersError : null
339
327
}
328
+ lastFetch = { currentMembersUpdatedAt }
340
329
loading = { isLoadingCurrentMembers }
341
330
members = { currentMembers }
342
331
style = { tw `mt-4` }
@@ -478,19 +467,11 @@ export default function HomeScreen() {
478
467
</ Animated . View >
479
468
) )
480
469
) : (
481
- < CalendarEmptyState
482
- description = { t ( 'home.calendar.empty.label' ) }
483
- style = { tw `w-full h-full mt-4` } >
484
- < Link
485
- asChild
486
- href = { [ '/events' , firstPeriodWithEvents && `period=${ firstPeriodWithEvents } ` ]
487
- . filter ( Boolean )
488
- . join ( '?' ) } >
489
- < AppText style = { tw `text-base font-normal text-amber-500 text-center mt-4` } >
490
- { t ( 'home.calendar.empty.action' ) }
491
- </ AppText >
492
- </ Link >
493
- </ CalendarEmptyState >
470
+ < HomeCalendarEmptyState
471
+ events = { nextCalendarEvents }
472
+ lastFetch = { calendarEventsUpdatedAt }
473
+ style = { tw `w-full h-full mt-4` }
474
+ />
494
475
) }
495
476
</ ScrollView >
496
477
</ Animated . View >
0 commit comments