Skip to content

Commit 83a8a86

Browse files
feat: clean up code
1 parent 370abd6 commit 83a8a86

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

packages/ui-react/src/hooks/useFilteredContent.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,17 @@ const useDeviceType = () => {
4949
const getCountryByTimezone = () => {
5050
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
5151

52-
if (!timezone) {
52+
if (!timezone || !(timezone in TIMEZONES)) {
5353
return undefined;
5454
}
5555

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];
5863
};
5964

6065
const getCurrentDay = () => new Date().toLocaleString('en-US', { weekday: 'long' });
@@ -76,12 +81,12 @@ export const useFilterContent = (content: Content[]) => {
7681
const currentDay = getCurrentDay();
7782
const country = getCountryByTimezone();
7883

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+
);
8792
};

0 commit comments

Comments
 (0)