Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions homeflow/app.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ module.exports = {
"usageDescription": "StreamSync would like to access your clinical health records to import medications, lab results, and conditions — reducing manual data entry."
}
],
[
"expo-notifications",
{
"icon": "./assets/images/icon.png",
"color": "#8C1515"
}
],
"expo-apple-authentication",
[
"@react-native-google-signin/google-signin",
Expand Down
4 changes: 4 additions & 0 deletions homeflow/app/(onboarding)/permissions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
areClinicalRecordsAvailable,
requestClinicalPermissions,
} from '@/lib/services/healthkit';
import { requestNotificationPermissions } from '@/lib/services/notification-service';
import {
OnboardingProgressBar,
PermissionCard,
Expand Down Expand Up @@ -136,6 +137,9 @@ export default function PermissionsScreen() {
const handleContinue = async () => {
setIsLoading(true);
try {
// Request notification permissions alongside health permissions
await requestNotificationPermissions();

await OnboardingService.updateData({
permissions: {
healthKit: healthKitStatus as 'granted' | 'denied' | 'not_determined',
Expand Down
65 changes: 65 additions & 0 deletions homeflow/app/(tabs)/profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { useRouter, Href } from 'expo-router';
import { SafeAreaView } from 'react-native-safe-area-context';
import { IconSymbol } from '@/components/ui/icon-symbol';
import { useAuth } from '@/hooks/use-auth';
import { triggerTestNotification, requestNotificationPermissions } from '@/lib/services/notification-service';
import {
CONSENT_PROFILE_SUMMARY,
DATA_PERMISSIONS_SUMMARY,
Expand Down Expand Up @@ -230,6 +231,56 @@ export default function ProfileScreen() {
</View>
<IconSymbol name="chevron.right" size={14} color={c.textTertiary} />
</TouchableOpacity>

<View style={[styles.rowDivider, { backgroundColor: c.separator, marginVertical: 4 }]} />

<TouchableOpacity
style={[styles.devButton, { backgroundColor: c.secondaryFill }]}
onPress={async () => {
try {
const granted = await requestNotificationPermissions();
if (!granted) {
Alert.alert('Permission Denied', 'Enable notifications in Settings → HomeFlow → Notifications.');
return;
}
await triggerTestNotification('healthkit');
Alert.alert('Sent', 'HealthKit reminder notification fired. Background the app to see the banner.');
} catch (e: any) {
Alert.alert('Error', e?.message ?? 'Failed to send notification.');
}
}}
activeOpacity={0.7}
>
<IconSymbol name="heart.fill" size={16} color={c.semanticWarning} />
<Text style={[styles.devButtonText, { color: c.semanticWarning }]}>
Test HealthKit Reminder
</Text>
</TouchableOpacity>

<View style={[styles.rowDivider, { backgroundColor: c.separator, marginVertical: 4 }]} />

<TouchableOpacity
style={[styles.devButton, { backgroundColor: c.secondaryFill }]}
onPress={async () => {
try {
const granted = await requestNotificationPermissions();
if (!granted) {
Alert.alert('Permission Denied', 'Enable notifications in Settings → HomeFlow → Notifications.');
return;
}
await triggerTestNotification('throne');
Alert.alert('Sent', 'Throne reminder notification fired. Background the app to see the banner.');
} catch (e: any) {
Alert.alert('Error', e?.message ?? 'Failed to send notification.');
}
}}
activeOpacity={0.7}
>
<IconSymbol name="drop.fill" size={16} color={c.semanticWarning} />
<Text style={[styles.devButtonText, { color: c.semanticWarning }]}>
Test Throne Reminder
</Text>
</TouchableOpacity>
</View>
)}

Expand Down Expand Up @@ -422,6 +473,20 @@ const styles = StyleSheet.create({
fontWeight: '500',
},

// Dev tools
devButton: {
flexDirection: 'row',
alignItems: 'center',
gap: 10,
borderRadius: 10,
paddingHorizontal: 14,
paddingVertical: 12,
},
devButtonText: {
fontSize: 14,
fontWeight: '500',
},

// Sign out
signOutButton: {
flexDirection: 'row',
Expand Down
4 changes: 4 additions & 0 deletions homeflow/app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { bootstrapHealthKitSync } from '@/src/services/healthkitSync';

import { useOnboardingStatus } from '@/hooks/use-onboarding-status';
import { useAuth } from '@/hooks/use-auth';
import { useDataSyncCheck } from '@/hooks/use-data-sync-check';
import { LoadingScreen } from '@/components/ui/loading-screen';
import { ErrorBoundary } from '@/components/error-boundary';
import { StandardProvider, useStandard } from '@/lib/services/standard-context';
Expand Down Expand Up @@ -55,6 +56,9 @@ function RootLayoutNav() {
);
}, [user?.id]);

// Run 48-hour data sync check only when user is fully in the app
useDataSyncCheck(!!onboardingComplete && isAuthenticated);

// While checking onboarding/auth status, show loading
if (onboardingComplete === null || authLoading) {
return <LoadingScreen />;
Expand Down
31 changes: 31 additions & 0 deletions homeflow/hooks/use-data-sync-check.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* useDataSyncCheck
*
* Runs the 48-hour data sync check whenever the app comes to the foreground.
* Only active when the user is authenticated and onboarding is complete.
*/

import { useEffect, useRef } from 'react';
import { AppState, type AppStateStatus } from 'react-native';
import { checkAndScheduleReminders } from '@/lib/services/notification-service';

export function useDataSyncCheck(active: boolean): void {
const appState = useRef<AppStateStatus>(AppState.currentState);

useEffect(() => {
if (!active) return;

// Run on mount
checkAndScheduleReminders().catch(() => {});

// Run every time the app comes back to the foreground
const subscription = AppState.addEventListener('change', (nextState) => {
if (appState.current.match(/inactive|background/) && nextState === 'active') {
checkAndScheduleReminders().catch(() => {});
}
appState.current = nextState;
});

return () => subscription.remove();
}, [active]);
}
Loading
Loading