Skip to content

Commit 7b462f4

Browse files
committed
Merge remote-tracking branch 'origin/fix-minor-changes' into feat-proxy-optimization
2 parents 5593fa5 + c5edbf9 commit 7b462f4

File tree

4 files changed

+58
-48
lines changed

4 files changed

+58
-48
lines changed

app/(tabs)/index.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,16 @@ export default function Home() {
199199
}
200200
}, [layoutLoaded, isLoading, isFetching]);
201201

202+
// Show onboarding screen even while loading
203+
if (!isOnboardingComplete) {
204+
return (
205+
<View style={{ flex: 1, backgroundColor: isDarkMode ? '#171717' : '#fff' }}>
206+
<Stack.Screen options={{ title: 'Home' }} />
207+
<OnboardingScreen isOnboardingComplete={isOnboardingComplete} />
208+
</View>
209+
);
210+
}
211+
202212
if (isLoading) {
203213
return (
204214
<View
@@ -261,8 +271,6 @@ export default function Home() {
261271
<View style={{ flex: 1, backgroundColor: isDarkMode ? '#171717' : '#fff' }}>
262272
<Stack.Screen options={{ title: 'Home' }} />
263273
<Container disableBottomPadding onLayout={onLayoutRootView}>
264-
<OnboardingScreen isOnboardingComplete={isOnboardingComplete} />
265-
266274
{isLoading ? (
267275
<View className="flex-1 items-center justify-center">
268276
<ActivityIndicator size="small" />

app/location/components/LocationHeader.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { useDatabase } from '~/hooks/useDatabase';
88
import { useLocationDetails } from '~/hooks/useLocationDetails';
99
import { location as location_schema, menu } from '~/services/database/schema';
1010
import { useSettingsStore } from '~/store/useSettingsStore';
11-
import { useLocationName, useMealTimes } from '~/utils/locations';
11+
import { useLocationName } from '~/utils/locations';
1212
import { generateSchedule, isLocationOpen } from '~/utils/time';
1313
import { cn } from '~/utils/utils';
1414
import DateNavigator from './DateNavigator';
@@ -46,7 +46,6 @@ const LocationHeader = React.memo(
4646

4747
const { useColloquialNames } = useSettingsStore();
4848
const displayName = useLocationName(location, useColloquialNames);
49-
const mealTimes = useMealTimes(location);
5049

5150
const isDarkMode = useSettingsStore((state) => state.isDarkMode);
5251

@@ -182,9 +181,7 @@ const LocationHeader = React.memo(
182181
<FilterBar
183182
selectedItem={selectedMenu as string}
184183
setSelectedItem={setSelectedMenu}
185-
useTimeOfDayDefault={filters.length > 1}
186184
items={filters}
187-
mealTimes={mealTimes || undefined}
188185
showFilterButton
189186
/>
190187
</View>

components/FilterBar.tsx

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
import * as Haptics from 'expo-haptics';
22
import { Filter } from 'lucide-react-native';
3-
import { useEffect, useMemo } from 'react';
3+
import { useMemo } from 'react';
44
import { ScrollView, Text, TouchableOpacity, View } from 'react-native';
55
import { SheetManager } from 'react-native-actions-sheet';
66

77
import type { FilterType } from '~/app/(tabs)';
88
import { useFiltersStore } from '~/store/useFiltersStore';
99
import { useSettingsStore } from '~/store/useSettingsStore';
1010
import { COLORS } from '~/utils/colors';
11-
import type { MealTimes } from '~/utils/locations';
12-
import { timeOfDay } from '~/utils/time';
1311
import { cn } from '~/utils/utils';
1412

1513
type FilterBarProps = {
1614
selectedItem: string;
1715
setSelectedItem: (item: FilterType) => void;
1816
items: { id: string; title: string }[]; // Accepts dynamic items array
19-
mealTimes?: MealTimes;
2017
showFilterButton?: boolean;
21-
useTimeOfDayDefault?: boolean;
2218
};
2319

2420
// Define the proper meal order
@@ -32,9 +28,7 @@ const FilterBar = ({
3228
selectedItem,
3329
setSelectedItem,
3430
items: filterItems,
35-
mealTimes,
3631
showFilterButton = false,
37-
useTimeOfDayDefault = false,
3832
}: FilterBarProps) => {
3933
const isDarkMode = useSettingsStore((state) => state.isDarkMode);
4034

@@ -47,34 +41,6 @@ const FilterBar = ({
4741
});
4842
}, [filterItems]);
4943

50-
// When enabled, set default filter based on timeOfDay if none is selected.
51-
useEffect(() => {
52-
// If there's only one item, automatically select it
53-
if (filterItems.length === 1 && !selectedItem) {
54-
setSelectedItem(filterItems[0].id as FilterType);
55-
return;
56-
}
57-
58-
if (useTimeOfDayDefault && !selectedItem) {
59-
const tod = mealTimes ? timeOfDay(new Date(), mealTimes) : timeOfDay(new Date());
60-
let defaultFilter = '';
61-
62-
if (tod === 'morning') defaultFilter = 'Breakfast';
63-
else if (tod === 'afternoon') defaultFilter = 'Lunch';
64-
else if (tod === 'evening') defaultFilter = 'Dinner';
65-
66-
// Find item with matching title
67-
const matchingItem = filterItems.find((item) => item.title === defaultFilter);
68-
69-
if (matchingItem) {
70-
setSelectedItem(matchingItem.id as FilterType);
71-
} else {
72-
// Fallback to first item if no match
73-
setSelectedItem(filterItems[0]?.id as FilterType);
74-
}
75-
}
76-
}, [filterItems, selectedItem, useTimeOfDayDefault, setSelectedItem, mealTimes]);
77-
7844
const onPressItem = async (id: FilterType) => {
7945
setSelectedItem(id as FilterType);
8046
await Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light);

hooks/useMenuData.tsx

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,17 @@ import {
66
type Location,
77
} from '~/services/database/database';
88
import { getTodayInCentralTime } from '~/utils/date';
9+
import { getMealTimes } from '~/utils/locations';
10+
import { timeOfDay } from '~/utils/time';
911
import { useDatabase } from './useDatabase';
1012

13+
// Define the proper meal order
14+
const MEAL_ORDER = {
15+
Breakfast: 1,
16+
Lunch: 2,
17+
Dinner: 3,
18+
};
19+
1120
export function useMenuData(location: string, date?: string) {
1221
const db = useDatabase();
1322
const queryClient = useQueryClient();
@@ -32,8 +41,43 @@ export function useMenuData(location: string, date?: string) {
3241
enabled: !!location,
3342
});
3443

35-
// Auto-select first menu if none selected
36-
const defaultMenu = selectedMenu || menuNames[0];
44+
// Smart menu selection logic
45+
const defaultMenu = useMemo(() => {
46+
// If user has manually selected a menu, use that
47+
if (selectedMenu) return selectedMenu;
48+
49+
// If no menus available, return null
50+
if (menuNames.length === 0) return null;
51+
52+
// If there's only one menu, automatically select it
53+
if (menuNames.length === 1) {
54+
return menuNames[0];
55+
}
56+
57+
// Use time-of-day logic to determine appropriate menu
58+
const mealTimes = getMealTimes(db, location);
59+
const tod = mealTimes ? timeOfDay(new Date(), mealTimes) : timeOfDay(new Date());
60+
let targetMenu = '';
61+
62+
if (tod === 'morning') targetMenu = 'Breakfast';
63+
else if (tod === 'afternoon') targetMenu = 'Lunch';
64+
else if (tod === 'evening') targetMenu = 'Dinner';
65+
66+
// Find menu with matching title
67+
const matchingMenu = menuNames.find((menuName) => menuName === targetMenu);
68+
69+
if (matchingMenu) {
70+
return matchingMenu;
71+
} else {
72+
// Sort menus by meal order and fallback to first available
73+
const sortedMenus = [...menuNames].sort((a, b) => {
74+
const orderA = MEAL_ORDER[a as keyof typeof MEAL_ORDER] || 999;
75+
const orderB = MEAL_ORDER[b as keyof typeof MEAL_ORDER] || 999;
76+
return orderA - orderB;
77+
});
78+
return sortedMenus[0];
79+
}
80+
}, [selectedMenu, menuNames, location, db]);
3781

3882
// Prefetch all menu data for instant switching
3983
useEffect(() => {
@@ -64,11 +108,6 @@ export function useMenuData(location: string, date?: string) {
64108
enabled: !!location && !!defaultMenu,
65109
});
66110

67-
// Reset selected menu when date changes
68-
useEffect(() => {
69-
setSelectedMenu(null);
70-
}, []);
71-
72111
// Track menu switching state
73112
useEffect(() => {
74113
if (defaultMenu && prevSelectedMenuRef.current !== defaultMenu) {

0 commit comments

Comments
 (0)