@@ -49,12 +49,17 @@ const useDeviceType = () => {
49
49
const getCountryByTimezone = ( ) => {
50
50
const timezone = Intl . DateTimeFormat ( ) . resolvedOptions ( ) . timeZone ;
51
51
52
- if ( ! timezone ) {
52
+ if ( ! timezone || ! ( timezone in TIMEZONES ) ) {
53
53
return undefined ;
54
54
}
55
55
56
- const countryTimezone = TIMEZONES [ timezone as keyof typeof TIMEZONES ] ?. c [ 0 ] as keyof typeof COUNTRIES ;
57
- return countryTimezone ? COUNTRIES [ countryTimezone ] : undefined ;
56
+ const countryCodes = TIMEZONES [ timezone as keyof typeof TIMEZONES ] ?. c ;
57
+ if ( ! countryCodes || countryCodes . length === 0 ) {
58
+ return undefined ;
59
+ }
60
+
61
+ const countryCode = countryCodes [ 0 ] as keyof typeof COUNTRIES ;
62
+ return COUNTRIES [ countryCode ] ;
58
63
} ;
59
64
60
65
const getCurrentDay = ( ) => new Date ( ) . toLocaleString ( 'en-US' , { weekday : 'long' } ) ;
@@ -76,12 +81,12 @@ export const useFilterContent = (content: Content[]) => {
76
81
const currentDay = getCurrentDay ( ) ;
77
82
const country = getCountryByTimezone ( ) ;
78
83
79
- return content ?. filter ( ( item ) => {
80
- return (
81
- filterDefaultContent ( item ) ||
82
- filterContentByDevice ( item , isMobile , isTablet , isDesktop ) ||
83
- filterContentByWeekDay ( item , currentDay ) ||
84
- filterContentByCountry ( item , country )
85
- ) ;
86
- } ) ;
84
+ return content ?. filter ( ( item ) =>
85
+ [
86
+ filterDefaultContent ( item ) ,
87
+ filterContentByDevice ( item , isMobile , isTablet , isDesktop ) ,
88
+ filterContentByWeekDay ( item , currentDay ) ,
89
+ filterContentByCountry ( item , country ) ,
90
+ ] . some ( Boolean ) ,
91
+ ) ;
87
92
} ;
0 commit comments