fix: tab bar not visible on Android #21

Merged
Ichitux merged 5 commits from fix/android-tab-bar-visibility into main 2026-07-07 21:53:18 +00:00
15 changed files with 455 additions and 119 deletions
@@ -0,0 +1 @@
{"pid":1390854,"startedAt":1783459832497}
+34 -6
View File
@@ -1,8 +1,11 @@
import { Tabs } from 'expo-router'; import { Tabs } from 'expo-router';
import { Ionicons } from '@expo/vector-icons'; import { Ionicons } from '@expo/vector-icons';
import { View, StyleSheet, Platform } from 'react-native'; import { View, StyleSheet, Platform, useWindowDimensions } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { colors, shadows } from '../../constants/theme'; import { colors, shadows } from '../../constants/theme';
const TABLET_MIN_WIDTH = 768;
function ScanIcon({ color, size }: { color: string; size: number }) { function ScanIcon({ color, size }: { color: string; size: number }) {
return ( return (
<View style={styles.fabContainer}> <View style={styles.fabContainer}>
@@ -14,16 +17,31 @@ function ScanIcon({ color, size }: { color: string; size: number }) {
} }
export default function TabLayout() { export default function TabLayout() {
const insets = useSafeAreaInsets();
const { width } = useWindowDimensions();
const isTablet = width >= TABLET_MIN_WIDTH;
const bottomPadding = Platform.OS === 'ios' ? insets.bottom : 8;
return ( return (
<Tabs <Tabs
screenOptions={{ screenOptions={{
tabBarActiveTintColor: colors.primary, tabBarActiveTintColor: colors.primary,
tabBarInactiveTintColor: colors.textSecondary, tabBarInactiveTintColor: colors.textSecondary,
tabBarStyle: styles.tabBar, tabBarStyle: {
tabBarLabelStyle: styles.tabBarLabel, ...(isTablet ? styles.tabBarTablet : styles.tabBar),
height: (isTablet ? 64 : 60) + bottomPadding,
paddingBottom: bottomPadding,
},
tabBarLabelStyle: {
...styles.tabBarLabel,
...(isTablet ? styles.tabBarLabelTablet : {}),
},
headerStyle: styles.header, headerStyle: styles.header,
headerTintColor: colors.primary, headerTintColor: colors.primary,
headerTitleStyle: styles.headerTitle, headerTitleStyle: {
...styles.headerTitle,
...(isTablet ? styles.headerTitleTablet : {}),
},
}} }}
> >
<Tabs.Screen <Tabs.Screen
@@ -84,14 +102,21 @@ const styles = StyleSheet.create({
tabBar: { tabBar: {
backgroundColor: colors.card, backgroundColor: colors.card,
borderTopColor: colors.border, borderTopColor: colors.border,
height: Platform.OS === 'ios' ? 88 : 64,
paddingBottom: Platform.OS === 'ios' ? 24 : 8,
paddingTop: 8, paddingTop: 8,
}, },
tabBarTablet: {
backgroundColor: colors.card,
borderTopColor: colors.border,
paddingTop: 10,
paddingHorizontal: 24,
},
tabBarLabel: { tabBarLabel: {
fontSize: 11, fontSize: 11,
fontWeight: '500', fontWeight: '500',
}, },
tabBarLabelTablet: {
fontSize: 13,
},
header: { header: {
backgroundColor: colors.card, backgroundColor: colors.card,
shadowColor: '#000', shadowColor: '#000',
@@ -105,6 +130,9 @@ const styles = StyleSheet.create({
fontWeight: '600', fontWeight: '600',
fontSize: 17, fontSize: 17,
}, },
headerTitleTablet: {
fontSize: 20,
},
fabContainer: { fabContainer: {
position: 'absolute', position: 'absolute',
top: -16, top: -16,
+42 -9
View File
@@ -1,9 +1,11 @@
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { View, Text, StyleSheet, FlatList, TouchableOpacity, Alert } from 'react-native'; import { View, Text, StyleSheet, FlatList, TouchableOpacity, Alert, useWindowDimensions } from 'react-native';
import { Ionicons } from '@expo/vector-icons'; import { Ionicons } from '@expo/vector-icons';
import { colors, spacing, borderRadius, shadows } from '../../constants/theme'; import { colors, spacing, borderRadius, shadows } from '../../constants/theme';
import { LoadingSpinner } from '../../components/LoadingSpinner'; import { LoadingSpinner } from '../../components/LoadingSpinner';
const TABLET_MIN_WIDTH = 768;
interface NotificationItem { interface NotificationItem {
scope: string; scope: string;
id: number; id: number;
@@ -16,6 +18,8 @@ interface NotificationItem {
} }
export default function AlertsScreen() { export default function AlertsScreen() {
const { width } = useWindowDimensions();
const isTablet = width >= TABLET_MIN_WIDTH;
const [items, setItems] = useState<NotificationItem[]>([]); const [items, setItems] = useState<NotificationItem[]>([]);
const [isLoading, setIsLoading] = useState(true); const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState<string | null>(null); const [error, setError] = useState<string | null>(null);
@@ -127,15 +131,15 @@ export default function AlertsScreen() {
return ( return (
<View style={styles.container}> <View style={styles.container}>
<View style={styles.header}> <View style={[styles.header, isTablet && styles.headerTablet]}>
<Text style={styles.title}>Notificaciones Guardadas</Text> <Text style={[styles.title, isTablet && styles.titleTablet]}>Notificaciones Guardadas</Text>
<Text style={styles.subtitle}> <Text style={[styles.subtitle, isTablet && styles.subtitleTablet]}>
Recibe avisos cuando medicamentos sin stock se repongan Recibe avisos cuando medicamentos sin stock se repongan
</Text> </Text>
</View> </View>
{error && ( {error && (
<View style={styles.errorContainer}> <View style={[styles.errorContainer, isTablet && styles.errorContainerTablet]}>
<Text style={styles.errorText}>{error}</Text> <Text style={styles.errorText}>{error}</Text>
<TouchableOpacity onPress={loadNotifications} style={styles.retryButton}> <TouchableOpacity onPress={loadNotifications} style={styles.retryButton}>
<Text style={styles.retryText}>Reintentar</Text> <Text style={styles.retryText}>Reintentar</Text>
@@ -145,9 +149,9 @@ export default function AlertsScreen() {
{!error && items.length === 0 && ( {!error && items.length === 0 && (
<View style={styles.emptyContainer}> <View style={styles.emptyContainer}>
<Ionicons name="notifications-off-outline" size={64} color={colors.border} /> <Ionicons name="notifications-off-outline" size={isTablet ? 80 : 64} color={colors.border} />
<Text style={styles.emptyTitle}>Sin notificaciones</Text> <Text style={[styles.emptyTitle, isTablet && styles.emptyTitleTablet]}>Sin notificaciones</Text>
<Text style={styles.emptyText}> <Text style={[styles.emptyText, isTablet && styles.emptyTextTablet]}>
Toca la campana en una farmacia sin stock para recibir notificaciones cuando se reponga. Toca la campana en una farmacia sin stock para recibir notificaciones cuando se reponga.
</Text> </Text>
</View> </View>
@@ -158,7 +162,7 @@ export default function AlertsScreen() {
data={items} data={items}
keyExtractor={(item) => `${item.scope}:${item.id}`} keyExtractor={(item) => `${item.scope}:${item.id}`}
renderItem={renderItem} renderItem={renderItem}
contentContainerStyle={styles.list} contentContainerStyle={[styles.list, isTablet && styles.listTablet]}
showsVerticalScrollIndicator={false} showsVerticalScrollIndicator={false}
/> />
)} )}
@@ -176,22 +180,39 @@ const styles = StyleSheet.create({
paddingTop: spacing.lg, paddingTop: spacing.lg,
paddingBottom: spacing.md, paddingBottom: spacing.md,
}, },
headerTablet: {
maxWidth: 700,
alignSelf: 'center',
width: '100%',
},
title: { title: {
fontSize: 22, fontSize: 22,
fontWeight: 'bold', fontWeight: 'bold',
color: colors.text, color: colors.text,
}, },
titleTablet: {
fontSize: 28,
},
subtitle: { subtitle: {
fontSize: 14, fontSize: 14,
color: colors.textSecondary, color: colors.textSecondary,
marginTop: spacing.xs, marginTop: spacing.xs,
lineHeight: 20, lineHeight: 20,
}, },
subtitleTablet: {
fontSize: 16,
lineHeight: 24,
},
list: { list: {
paddingHorizontal: spacing.lg, paddingHorizontal: spacing.lg,
paddingBottom: spacing.xl, paddingBottom: spacing.xl,
gap: spacing.sm, gap: spacing.sm,
}, },
listTablet: {
maxWidth: 700,
alignSelf: 'center',
width: '100%',
},
item: { item: {
flexDirection: 'row', flexDirection: 'row',
alignItems: 'center', alignItems: 'center',
@@ -249,6 +270,10 @@ const styles = StyleSheet.create({
alignItems: 'center', alignItems: 'center',
gap: spacing.sm, gap: spacing.sm,
}, },
errorContainerTablet: {
maxWidth: 700,
alignSelf: 'center',
},
errorText: { errorText: {
fontSize: 14, fontSize: 14,
color: colors.danger, color: colors.danger,
@@ -275,10 +300,18 @@ const styles = StyleSheet.create({
fontWeight: '600', fontWeight: '600',
color: colors.text, color: colors.text,
}, },
emptyTitleTablet: {
fontSize: 24,
},
emptyText: { emptyText: {
fontSize: 14, fontSize: 14,
color: colors.textSecondary, color: colors.textSecondary,
textAlign: 'center', textAlign: 'center',
lineHeight: 20, lineHeight: 20,
}, },
emptyTextTablet: {
fontSize: 16,
maxWidth: 400,
lineHeight: 24,
},
}); });
+41 -12
View File
@@ -1,51 +1,55 @@
import React from 'react'; import React from 'react';
import { View, Text, StyleSheet, TouchableOpacity, Image } from 'react-native'; import { View, Text, StyleSheet, TouchableOpacity, Image, useWindowDimensions } from 'react-native';
import { Ionicons } from '@expo/vector-icons'; import { Ionicons } from '@expo/vector-icons';
import { useRouter } from 'expo-router'; import { useRouter } from 'expo-router';
import { colors, spacing, borderRadius, shadows } from '../../constants/theme'; import { colors, spacing, borderRadius, shadows } from '../../constants/theme';
const TABLET_MIN_WIDTH = 768;
export default function HomeScreen() { export default function HomeScreen() {
const router = useRouter(); const router = useRouter();
const { width } = useWindowDimensions();
const isTablet = width >= TABLET_MIN_WIDTH;
return ( return (
<View style={styles.container}> <View style={styles.container}>
<View style={styles.hero}> <View style={[styles.hero, isTablet && styles.heroTablet]}>
<Image <Image
source={require('../../assets/farmaclic_logo.png')} source={require('../../assets/farmaclic_logo.png')}
style={styles.logo} style={[styles.logo, isTablet && styles.logoTablet]}
resizeMode="contain" resizeMode="contain"
/> />
<Text style={styles.brandName}>FarmaClic</Text> <Text style={[styles.brandName, isTablet && styles.brandNameTablet]}>FarmaClic</Text>
<Text style={styles.description}> <Text style={[styles.description, isTablet && styles.descriptionTablet]}>
Encuentra tus medicamentos en farmacias cercanas Encuentra tus medicamentos en farmacias cercanas
</Text> </Text>
</View> </View>
<View style={styles.cards}> <View style={[styles.cards, isTablet && styles.cardsTablet]}>
<TouchableOpacity <TouchableOpacity
style={styles.card} style={[styles.card, isTablet && styles.cardTablet]}
activeOpacity={0.85} activeOpacity={0.85}
onPress={() => router.push('/(tabs)')} onPress={() => router.push('/(tabs)')}
> >
<View style={[styles.cardIcon, styles.cardIconSearch]}> <View style={[styles.cardIcon, styles.cardIconSearch]}>
<Ionicons name="search" size={24} color={colors.onPrimaryContainer} /> <Ionicons name="search" size={isTablet ? 28 : 24} color={colors.onPrimaryContainer} />
</View> </View>
<View style={styles.cardContent}> <View style={styles.cardContent}>
<Text style={styles.cardLabel}>Buscar Medicamento</Text> <Text style={[styles.cardLabel, isTablet && styles.cardLabelTablet]}>Buscar Medicamento</Text>
<Ionicons name="chevron-forward" size={20} color={colors.onPrimaryContainer} style={{ opacity: 0.7 }} /> <Ionicons name="chevron-forward" size={20} color={colors.onPrimaryContainer} style={{ opacity: 0.7 }} />
</View> </View>
</TouchableOpacity> </TouchableOpacity>
<TouchableOpacity <TouchableOpacity
style={[styles.card, styles.cardScan]} style={[styles.card, styles.cardScan, isTablet && styles.cardTablet]}
activeOpacity={0.85} activeOpacity={0.85}
onPress={() => router.push('/scanner')} onPress={() => router.push('/scanner')}
> >
<View style={[styles.cardIcon, styles.cardIconScan]}> <View style={[styles.cardIcon, styles.cardIconScan]}>
<Ionicons name="scan" size={24} color="#ffffff" /> <Ionicons name="scan" size={isTablet ? 28 : 24} color="#ffffff" />
</View> </View>
<View style={styles.cardContent}> <View style={styles.cardContent}>
<Text style={[styles.cardLabel, styles.cardLabelScan]}>Escanear TSI</Text> <Text style={[styles.cardLabel, styles.cardLabelScan, isTablet && styles.cardLabelTablet]}>Escanear TSI</Text>
<Ionicons name="chevron-forward" size={20} color="#ffffff" style={{ opacity: 0.7 }} /> <Ionicons name="chevron-forward" size={20} color="#ffffff" style={{ opacity: 0.7 }} />
</View> </View>
</TouchableOpacity> </TouchableOpacity>
@@ -68,17 +72,27 @@ const styles = StyleSheet.create({
gap: spacing.sm, gap: spacing.sm,
marginBottom: spacing.md, marginBottom: spacing.md,
}, },
heroTablet: {
marginBottom: spacing.xl,
},
logo: { logo: {
width: 120, width: 120,
height: 120, height: 120,
marginBottom: spacing.xs, marginBottom: spacing.xs,
}, },
logoTablet: {
width: 160,
height: 160,
},
brandName: { brandName: {
fontSize: 28, fontSize: 28,
fontWeight: 'bold', fontWeight: 'bold',
color: colors.text, color: colors.text,
letterSpacing: -0.5, letterSpacing: -0.5,
}, },
brandNameTablet: {
fontSize: 36,
},
description: { description: {
fontSize: 16, fontSize: 16,
color: colors.textSecondary, color: colors.textSecondary,
@@ -86,11 +100,19 @@ const styles = StyleSheet.create({
maxWidth: 260, maxWidth: 260,
lineHeight: 24, lineHeight: 24,
}, },
descriptionTablet: {
fontSize: 18,
maxWidth: 400,
lineHeight: 28,
},
cards: { cards: {
width: '100%', width: '100%',
maxWidth: 320, maxWidth: 320,
gap: spacing.md, gap: spacing.md,
}, },
cardsTablet: {
maxWidth: 480,
},
card: { card: {
flexDirection: 'row', flexDirection: 'row',
alignItems: 'center', alignItems: 'center',
@@ -101,6 +123,10 @@ const styles = StyleSheet.create({
minHeight: 64, minHeight: 64,
...shadows.card, ...shadows.card,
}, },
cardTablet: {
padding: spacing.lg,
minHeight: 72,
},
cardScan: { cardScan: {
backgroundColor: colors.scanButton, backgroundColor: colors.scanButton,
}, },
@@ -131,6 +157,9 @@ const styles = StyleSheet.create({
color: colors.onPrimaryContainer, color: colors.onPrimaryContainer,
lineHeight: 24, lineHeight: 24,
}, },
cardLabelTablet: {
fontSize: 20,
},
cardLabelScan: { cardLabelScan: {
color: '#ffffff', color: '#ffffff',
}, },
+22 -4
View File
@@ -1,5 +1,5 @@
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import { View, FlatList, StyleSheet, Text, TouchableOpacity } from 'react-native'; import { View, FlatList, StyleSheet, Text, TouchableOpacity, useWindowDimensions } from 'react-native';
import { Ionicons } from '@expo/vector-icons'; import { Ionicons } from '@expo/vector-icons';
import { useRouter } from 'expo-router'; import { useRouter } from 'expo-router';
import { SearchBar } from '../../components/SearchBar'; import { SearchBar } from '../../components/SearchBar';
@@ -11,8 +11,12 @@ import { colors, spacing, borderRadius } from '../../constants/theme';
import { Medicine } from '../../types'; import { Medicine } from '../../types';
import { config } from '../../constants/config'; import { config } from '../../constants/config';
const TABLET_MIN_WIDTH = 768;
export default function HomeScreen() { export default function HomeScreen() {
const router = useRouter(); const router = useRouter();
const { width } = useWindowDimensions();
const isTablet = width >= TABLET_MIN_WIDTH;
const [query, setQuery] = useState(''); const [query, setQuery] = useState('');
const [results, setResults] = useState<Medicine[]>([]); const [results, setResults] = useState<Medicine[]>([]);
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
@@ -49,7 +53,7 @@ export default function HomeScreen() {
return ( return (
<View style={styles.container}> <View style={styles.container}>
<View style={styles.searchContainer}> <View style={[styles.searchContainer, isTablet && styles.searchContainerTablet]}>
<SearchBar <SearchBar
onSearch={handleSearch} onSearch={handleSearch}
value={query} value={query}
@@ -66,7 +70,7 @@ export default function HomeScreen() {
{isLoading && <LoadingSpinner message="Buscando medicamentos..." />} {isLoading && <LoadingSpinner message="Buscando medicamentos..." />}
{error && ( {error && (
<View style={styles.errorContainer}> <View style={[styles.errorContainer, isTablet && styles.errorContainerTablet]}>
<Text style={styles.errorText}>{error}</Text> <Text style={styles.errorText}>{error}</Text>
</View> </View>
)} )}
@@ -81,7 +85,7 @@ export default function HomeScreen() {
data={results} data={results}
keyExtractor={(item) => item.nregistro} keyExtractor={(item) => item.nregistro}
renderItem={({ item }) => <MedicineCard medicine={item} />} renderItem={({ item }) => <MedicineCard medicine={item} />}
contentContainerStyle={styles.list} contentContainerStyle={[styles.list, isTablet && styles.listTablet]}
showsVerticalScrollIndicator={false} showsVerticalScrollIndicator={false}
/> />
</View> </View>
@@ -98,6 +102,11 @@ const styles = StyleSheet.create({
alignItems: 'center', alignItems: 'center',
paddingRight: spacing.lg, paddingRight: spacing.lg,
}, },
searchContainerTablet: {
maxWidth: 700,
alignSelf: 'center',
width: '100%',
},
scannerButton: { scannerButton: {
width: 44, width: 44,
height: 44, height: 44,
@@ -114,12 +123,21 @@ const styles = StyleSheet.create({
list: { list: {
paddingBottom: spacing.xl, paddingBottom: spacing.xl,
}, },
listTablet: {
maxWidth: 700,
alignSelf: 'center',
width: '100%',
},
errorContainer: { errorContainer: {
padding: spacing.md, padding: spacing.md,
marginHorizontal: spacing.lg, marginHorizontal: spacing.lg,
backgroundColor: colors.dangerContainer, backgroundColor: colors.dangerContainer,
borderRadius: borderRadius.lg, borderRadius: borderRadius.lg,
}, },
errorContainerTablet: {
maxWidth: 700,
alignSelf: 'center',
},
errorText: { errorText: {
color: colors.danger, color: colors.danger,
textAlign: 'center', textAlign: 'center',
+59 -13
View File
@@ -1,11 +1,13 @@
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import { View, Text, StyleSheet, TouchableOpacity, Alert, TextInput, ScrollView, Image, ActivityIndicator, Modal, Pressable } from 'react-native'; import { View, Text, StyleSheet, TouchableOpacity, Alert, TextInput, ScrollView, Image, ActivityIndicator, Modal, Pressable, useWindowDimensions } from 'react-native';
import { useRouter } from 'expo-router'; import { useRouter } from 'expo-router';
import { Ionicons } from '@expo/vector-icons'; import { Ionicons } from '@expo/vector-icons';
import * as ImagePicker from 'expo-image-picker'; import * as ImagePicker from 'expo-image-picker';
import { useAuth } from '../../hooks/useAuth'; import { useAuth } from '../../hooks/useAuth';
import { colors, spacing, borderRadius } from '../../constants/theme'; import { colors, spacing, borderRadius } from '../../constants/theme';
const TABLET_MIN_WIDTH = 768;
const AVATARS = [ const AVATARS = [
require('../../assets/avatars/avatar1.png'), require('../../assets/avatars/avatar1.png'),
require('../../assets/avatars/avatar2.png'), require('../../assets/avatars/avatar2.png'),
@@ -44,6 +46,8 @@ interface Address {
export default function ProfileScreen() { export default function ProfileScreen() {
const router = useRouter(); const router = useRouter();
const { width } = useWindowDimensions();
const isTablet = width >= TABLET_MIN_WIDTH;
const { user, isAuthenticated, isLoading, logout, isAdmin } = useAuth(); const { user, isAuthenticated, isLoading, logout, isAdmin } = useAuth();
const [firstName, setFirstName] = useState(user?.first_name || ''); const [firstName, setFirstName] = useState(user?.first_name || '');
@@ -388,16 +392,16 @@ export default function ProfileScreen() {
return ( return (
<View style={styles.container}> <View style={styles.container}>
<View style={styles.authPrompt}> <View style={styles.authPrompt}>
<Ionicons name="person-outline" size={64} color={colors.textSecondary} /> <Ionicons name="person-outline" size={isTablet ? 80 : 64} color={colors.textSecondary} />
<Text style={styles.authTitle}>Inicia Sesión</Text> <Text style={[styles.authTitle, isTablet && styles.authTitleTablet]}>Inicia Sesión</Text>
<Text style={styles.authSubtitle}> <Text style={[styles.authSubtitle, isTablet && styles.authSubtitleTablet]}>
Inicia sesión para acceder a todas las funcionalidades Inicia sesión para acceder a todas las funcionalidades
</Text> </Text>
<TouchableOpacity <TouchableOpacity
style={styles.button} style={[styles.button, isTablet && styles.buttonTablet]}
onPress={() => router.push('/auth/login')} onPress={() => router.push('/auth/login')}
> >
<Text style={styles.buttonText}>Iniciar Sesión</Text> <Text style={[styles.buttonText, isTablet && styles.buttonTextTablet]}>Iniciar Sesión</Text>
</TouchableOpacity> </TouchableOpacity>
<TouchableOpacity <TouchableOpacity
style={styles.linkButton} style={styles.linkButton}
@@ -413,12 +417,12 @@ export default function ProfileScreen() {
return ( return (
<ScrollView style={styles.container}> <ScrollView style={styles.container}>
{/* Avatar Section */} {/* Avatar Section */}
<View style={styles.avatarSection}> <View style={[styles.avatarSection, isTablet && styles.avatarSectionTablet]}>
<TouchableOpacity style={styles.avatarContainer} onPress={() => setShowAvatarModal(true)}> <TouchableOpacity style={[styles.avatarContainer, isTablet && styles.avatarContainerTablet]} onPress={() => setShowAvatarModal(true)}>
{avatarUrl ? ( {avatarUrl ? (
<Image source={{ uri: avatarUrl }} style={styles.avatarImage} /> <Image source={{ uri: avatarUrl }} style={[styles.avatarImage, isTablet && styles.avatarImageTablet]} />
) : ( ) : (
<Ionicons name="person" size={40} color={colors.primary} /> <Ionicons name="person" size={isTablet ? 50 : 40} color={colors.primary} />
)} )}
<View style={styles.avatarOverlay}> <View style={styles.avatarOverlay}>
<Ionicons name="camera" size={24} color="white" /> <Ionicons name="camera" size={24} color="white" />
@@ -428,7 +432,7 @@ export default function ProfileScreen() {
</View> </View>
{/* Read-only Name Section */} {/* Read-only Name Section */}
<View style={styles.infoSection}> <View style={[styles.infoSection, isTablet && styles.infoSectionTablet]}>
<View style={styles.infoCard}> <View style={styles.infoCard}>
<Text style={styles.infoLabel}>Nombre</Text> <Text style={styles.infoLabel}>Nombre</Text>
<Text style={styles.infoValue}>{firstName || '—'}</Text> <Text style={styles.infoValue}>{firstName || '—'}</Text>
@@ -440,7 +444,7 @@ export default function ProfileScreen() {
</View> </View>
{/* Menu Section */} {/* Menu Section */}
<View style={styles.menuSection}> <View style={[styles.menuSection, isTablet && styles.menuSectionTablet]}>
<TouchableOpacity style={styles.menuItem} onPress={openConfig}> <TouchableOpacity style={styles.menuItem} onPress={openConfig}>
<Ionicons name="settings" size={24} color={colors.textSecondary} /> <Ionicons name="settings" size={24} color={colors.textSecondary} />
<Text style={styles.menuText}>Configuración</Text> <Text style={styles.menuText}>Configuración</Text>
@@ -480,7 +484,7 @@ export default function ProfileScreen() {
</View> </View>
{/* Logout Button */} {/* Logout Button */}
<TouchableOpacity style={styles.logoutButton} onPress={handleLogout}> <TouchableOpacity style={[styles.logoutButton, isTablet && styles.logoutButtonTablet]} onPress={handleLogout}>
<Ionicons name="log-out" size={20} color={colors.danger} /> <Ionicons name="log-out" size={20} color={colors.danger} />
<Text style={styles.logoutText}>Cerrar Sesión</Text> <Text style={styles.logoutText}>Cerrar Sesión</Text>
</TouchableOpacity> </TouchableOpacity>
@@ -814,6 +818,9 @@ const styles = StyleSheet.create({
color: colors.text, color: colors.text,
marginTop: spacing.lg, marginTop: spacing.lg,
}, },
authTitleTablet: {
fontSize: 32,
},
authSubtitle: { authSubtitle: {
fontSize: 16, fontSize: 16,
color: colors.textSecondary, color: colors.textSecondary,
@@ -821,11 +828,18 @@ const styles = StyleSheet.create({
marginTop: spacing.sm, marginTop: spacing.sm,
marginBottom: spacing.xl, marginBottom: spacing.xl,
}, },
authSubtitleTablet: {
fontSize: 18,
maxWidth: 400,
},
avatarSection: { avatarSection: {
alignItems: 'center', alignItems: 'center',
padding: spacing.xl, padding: spacing.xl,
backgroundColor: colors.card, backgroundColor: colors.card,
}, },
avatarSectionTablet: {
paddingVertical: spacing.xxl,
},
avatarContainer: { avatarContainer: {
width: 100, width: 100,
height: 100, height: 100,
@@ -835,11 +849,21 @@ const styles = StyleSheet.create({
alignItems: 'center', alignItems: 'center',
overflow: 'hidden', overflow: 'hidden',
}, },
avatarContainerTablet: {
width: 140,
height: 140,
borderRadius: 70,
},
avatarImage: { avatarImage: {
width: 100, width: 100,
height: 100, height: 100,
borderRadius: 50, borderRadius: 50,
}, },
avatarImageTablet: {
width: 140,
height: 140,
borderRadius: 70,
},
avatarOverlay: { avatarOverlay: {
position: 'absolute', position: 'absolute',
top: 0, top: 0,
@@ -862,6 +886,11 @@ const styles = StyleSheet.create({
marginTop: spacing.sm, marginTop: spacing.sm,
gap: spacing.md, gap: spacing.md,
}, },
infoSectionTablet: {
maxWidth: 600,
alignSelf: 'center',
width: '100%',
},
infoCard: { infoCard: {
backgroundColor: colors.surfaceLow, backgroundColor: colors.surfaceLow,
padding: spacing.md, padding: spacing.md,
@@ -886,6 +915,11 @@ const styles = StyleSheet.create({
marginTop: spacing.sm, marginTop: spacing.sm,
backgroundColor: colors.card, backgroundColor: colors.card,
}, },
menuSectionTablet: {
maxWidth: 600,
alignSelf: 'center',
width: '100%',
},
menuItem: { menuItem: {
flexDirection: 'row', flexDirection: 'row',
alignItems: 'center', alignItems: 'center',
@@ -932,11 +966,18 @@ const styles = StyleSheet.create({
paddingVertical: spacing.md, paddingVertical: spacing.md,
paddingHorizontal: spacing.xl, paddingHorizontal: spacing.xl,
}, },
buttonTablet: {
paddingVertical: spacing.lg,
paddingHorizontal: spacing.xl * 1.5,
},
buttonText: { buttonText: {
color: colors.textInverse, color: colors.textInverse,
fontSize: 16, fontSize: 16,
fontWeight: '600', fontWeight: '600',
}, },
buttonTextTablet: {
fontSize: 18,
},
linkButton: { linkButton: {
marginTop: spacing.md, marginTop: spacing.md,
}, },
@@ -955,6 +996,11 @@ const styles = StyleSheet.create({
borderWidth: 1, borderWidth: 1,
borderColor: colors.danger, borderColor: colors.danger,
}, },
logoutButtonTablet: {
maxWidth: 600,
alignSelf: 'center',
width: '100%',
},
logoutText: { logoutText: {
marginLeft: spacing.sm, marginLeft: spacing.sm,
color: colors.danger, color: colors.danger,
+36 -9
View File
@@ -1,29 +1,33 @@
import React from 'react'; import React from 'react';
import { View, Text, StyleSheet, TouchableOpacity } from 'react-native'; import { View, Text, StyleSheet, TouchableOpacity, useWindowDimensions } from 'react-native';
import { Ionicons } from '@expo/vector-icons'; import { Ionicons } from '@expo/vector-icons';
import { useRouter } from 'expo-router'; import { useRouter } from 'expo-router';
import { colors, spacing, borderRadius, shadows } from '../../constants/theme'; import { colors, spacing, borderRadius, shadows } from '../../constants/theme';
const TABLET_MIN_WIDTH = 768;
export default function ScanTabScreen() { export default function ScanTabScreen() {
const router = useRouter(); const router = useRouter();
const { width } = useWindowDimensions();
const isTablet = width >= TABLET_MIN_WIDTH;
return ( return (
<View style={styles.container}> <View style={styles.container}>
<View style={styles.content}> <View style={[styles.content, isTablet && styles.contentTablet]}>
<View style={styles.iconContainer}> <View style={[styles.iconContainer, isTablet && styles.iconContainerTablet]}>
<Ionicons name="scan" size={64} color={colors.scanButton} /> <Ionicons name="scan" size={isTablet ? 80 : 64} color={colors.scanButton} />
</View> </View>
<Text style={styles.title}>Escanear TSI</Text> <Text style={[styles.title, isTablet && styles.titleTablet]}>Escanear TSI</Text>
<Text style={styles.description}> <Text style={[styles.description, isTablet && styles.descriptionTablet]}>
Escanea el código de barras de tu tarjeta sanitaria para encontrar tus medicamentos Escanea el código de barras de tu tarjeta sanitaria para encontrar tus medicamentos
</Text> </Text>
<TouchableOpacity <TouchableOpacity
style={[styles.button, shadows.scanButton]} style={[styles.button, shadows.scanButton, isTablet && styles.buttonTablet]}
activeOpacity={0.85} activeOpacity={0.85}
onPress={() => router.push('/scanner')} onPress={() => router.push('/scanner')}
> >
<Ionicons name="scan" size={24} color="#ffffff" /> <Ionicons name="scan" size={isTablet ? 28 : 24} color="#ffffff" />
<Text style={styles.buttonText}>Iniciar escaneo</Text> <Text style={[styles.buttonText, isTablet && styles.buttonTextTablet]}>Iniciar escaneo</Text>
</TouchableOpacity> </TouchableOpacity>
</View> </View>
</View> </View>
@@ -42,6 +46,9 @@ const styles = StyleSheet.create({
paddingHorizontal: spacing.xl, paddingHorizontal: spacing.xl,
gap: spacing.md, gap: spacing.md,
}, },
contentTablet: {
gap: spacing.lg,
},
iconContainer: { iconContainer: {
width: 100, width: 100,
height: 100, height: 100,
@@ -51,11 +58,19 @@ const styles = StyleSheet.create({
justifyContent: 'center', justifyContent: 'center',
marginBottom: spacing.sm, marginBottom: spacing.sm,
}, },
iconContainerTablet: {
width: 140,
height: 140,
borderRadius: 70,
},
title: { title: {
fontSize: 22, fontSize: 22,
fontWeight: 'bold', fontWeight: 'bold',
color: colors.text, color: colors.text,
}, },
titleTablet: {
fontSize: 28,
},
description: { description: {
fontSize: 15, fontSize: 15,
color: colors.textSecondary, color: colors.textSecondary,
@@ -63,6 +78,11 @@ const styles = StyleSheet.create({
lineHeight: 22, lineHeight: 22,
maxWidth: 280, maxWidth: 280,
}, },
descriptionTablet: {
fontSize: 17,
maxWidth: 420,
lineHeight: 26,
},
button: { button: {
flexDirection: 'row', flexDirection: 'row',
alignItems: 'center', alignItems: 'center',
@@ -73,9 +93,16 @@ const styles = StyleSheet.create({
paddingHorizontal: spacing.xl, paddingHorizontal: spacing.xl,
marginTop: spacing.md, marginTop: spacing.md,
}, },
buttonTablet: {
paddingVertical: spacing.lg,
paddingHorizontal: spacing.xl * 1.5,
},
buttonText: { buttonText: {
fontSize: 17, fontSize: 17,
fontWeight: '600', fontWeight: '600',
color: '#ffffff', color: '#ffffff',
}, },
buttonTextTablet: {
fontSize: 20,
},
}); });
+43 -40
View File
@@ -3,6 +3,7 @@ import { Stack } from 'expo-router';
import { StatusBar } from 'expo-status-bar'; import { StatusBar } from 'expo-status-bar';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { GestureHandlerRootView } from 'react-native-gesture-handler'; import { GestureHandlerRootView } from 'react-native-gesture-handler';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { useAuthStore } from '../store/authStore'; import { useAuthStore } from '../store/authStore';
import { registerForPushNotifications, addNotificationListener, addNotificationResponseListener } from '../services/notifications'; import { registerForPushNotifications, addNotificationListener, addNotificationResponseListener } from '../services/notifications';
import { colors } from '../constants/theme'; import { colors } from '../constants/theme';
@@ -35,47 +36,49 @@ export default function RootLayout() {
return ( return (
<GestureHandlerRootView style={{ flex: 1 }}> <GestureHandlerRootView style={{ flex: 1 }}>
<QueryClientProvider client={queryClient}> <SafeAreaProvider>
<Stack <QueryClientProvider client={queryClient}>
screenOptions={{ <Stack
headerStyle: { backgroundColor: colors.card }, screenOptions={{
headerTintColor: colors.primary, headerStyle: { backgroundColor: colors.card },
headerTitleStyle: { color: colors.text, fontWeight: '600' }, headerTintColor: colors.primary,
}} headerTitleStyle: { color: colors.text, fontWeight: '600' },
>
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
<Stack.Screen
name="medicine/[id]"
options={{ title: 'Medicamento' }}
/>
<Stack.Screen
name="pharmacy/[id]"
options={{ title: 'Farmacia' }}
/>
<Stack.Screen
name="scanner"
options={{
title: 'Escanear',
headerShown: false,
}} }}
/> >
<Stack.Screen <Stack.Screen name="(tabs)" options={{ headerShown: false }} />
name="auth/login" <Stack.Screen
options={{ name="medicine/[id]"
title: 'Iniciar Sesión', options={{ title: 'Medicamento' }}
headerShown: false, />
}} <Stack.Screen
/> name="pharmacy/[id]"
<Stack.Screen options={{ title: 'Farmacia' }}
name="auth/register" />
options={{ <Stack.Screen
title: 'Registrarse', name="scanner"
headerShown: false, options={{
}} title: 'Escanear',
/> headerShown: false,
</Stack> }}
<StatusBar style="auto" /> />
</QueryClientProvider> <Stack.Screen
name="auth/login"
options={{
title: 'Iniciar Sesión',
headerShown: false,
}}
/>
<Stack.Screen
name="auth/register"
options={{
title: 'Registrarse',
headerShown: false,
}}
/>
</Stack>
<StatusBar style="auto" />
</QueryClientProvider>
</SafeAreaProvider>
</GestureHandlerRootView> </GestureHandlerRootView>
); );
} }
@@ -1,26 +1,34 @@
import React from 'react'; import React from 'react';
import { View, Text, StyleSheet, TouchableOpacity } from 'react-native'; import { View, Text, StyleSheet, TouchableOpacity, useWindowDimensions } from 'react-native';
import { useRouter } from 'expo-router'; import { useRouter } from 'expo-router';
import { Ionicons } from '@expo/vector-icons'; import { Ionicons } from '@expo/vector-icons';
import { colors, spacing, borderRadius } from '../constants/theme'; import { colors, spacing, borderRadius } from '../constants/theme';
import { StockBadge } from './StockBadge'; import { StockBadge } from './StockBadge';
import { Medicine } from '../types'; import { Medicine } from '../types';
const TABLET_MIN_WIDTH = 768;
interface MedicineCardProps { interface MedicineCardProps {
medicine: Medicine; medicine: Medicine;
} }
export function MedicineCard({ medicine }: MedicineCardProps) { export function MedicineCard({ medicine }: MedicineCardProps) {
const router = useRouter(); const router = useRouter();
const { width } = useWindowDimensions();
const isTablet = width >= TABLET_MIN_WIDTH;
const handlePress = () => { const handlePress = () => {
router.push(`/medicine/${medicine.nregistro}`); router.push(`/medicine/${medicine.nregistro}`);
}; };
return ( return (
<TouchableOpacity style={styles.card} onPress={handlePress} activeOpacity={0.7}> <TouchableOpacity
style={[styles.card, isTablet && styles.cardTablet]}
onPress={handlePress}
activeOpacity={0.7}
>
<View style={styles.header}> <View style={styles.header}>
<Text style={styles.name} numberOfLines={2}> <Text style={[styles.name, isTablet && styles.nameTablet]} numberOfLines={2}>
{medicine.nombre} {medicine.nombre}
</Text> </Text>
<StockBadge stock={medicine.stock} /> <StockBadge stock={medicine.stock} />
@@ -33,14 +41,14 @@ export function MedicineCard({ medicine }: MedicineCardProps) {
<View style={styles.footer}> <View style={styles.footer}>
<View style={styles.priceContainer}> <View style={styles.priceContainer}>
<Ionicons name="pricetag" size={14} color={colors.textSecondary} /> <Ionicons name="pricetag" size={14} color={colors.textSecondary} />
<Text style={styles.price}> <Text style={[styles.price, isTablet && styles.priceTablet]}>
{medicine.precio ? `${medicine.precio.toFixed(2)}` : 'Sin precio'} {medicine.precio ? `${medicine.precio.toFixed(2)}` : 'Sin precio'}
</Text> </Text>
</View> </View>
<View style={styles.labContainer}> <View style={styles.labContainer}>
<Ionicons name="business" size={14} color={colors.textSecondary} /> <Ionicons name="business" size={14} color={colors.textSecondary} />
<Text style={styles.laboratorio} numberOfLines={1}> <Text style={[styles.laboratorio, isTablet && styles.laboratorioTablet]} numberOfLines={1}>
{medicine.laboratorio} {medicine.laboratorio}
</Text> </Text>
</View> </View>
@@ -62,6 +70,12 @@ const styles = StyleSheet.create({
shadowRadius: 8, shadowRadius: 8,
elevation: 2, elevation: 2,
}, },
cardTablet: {
padding: spacing.lg,
maxWidth: 700,
alignSelf: 'center',
width: '100%',
},
header: { header: {
flexDirection: 'row', flexDirection: 'row',
justifyContent: 'space-between', justifyContent: 'space-between',
@@ -75,6 +89,9 @@ const styles = StyleSheet.create({
color: colors.text, color: colors.text,
marginRight: spacing.sm, marginRight: spacing.sm,
}, },
nameTablet: {
fontSize: 18,
},
principioActivo: { principioActivo: {
fontSize: 14, fontSize: 14,
color: colors.textSecondary, color: colors.textSecondary,
@@ -95,6 +112,9 @@ const styles = StyleSheet.create({
color: colors.primary, color: colors.primary,
marginLeft: spacing.xs, marginLeft: spacing.xs,
}, },
priceTablet: {
fontSize: 16,
},
labContainer: { labContainer: {
flexDirection: 'row', flexDirection: 'row',
alignItems: 'center', alignItems: 'center',
@@ -107,4 +127,8 @@ const styles = StyleSheet.create({
marginLeft: spacing.xs, marginLeft: spacing.xs,
maxWidth: 120, maxWidth: 120,
}, },
laboratorioTablet: {
fontSize: 14,
maxWidth: 200,
},
}); });
+15 -3
View File
@@ -1,8 +1,10 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import { View, TextInput, StyleSheet, TouchableOpacity } from 'react-native'; import { View, TextInput, StyleSheet, TouchableOpacity, useWindowDimensions } from 'react-native';
import { Ionicons } from '@expo/vector-icons'; import { Ionicons } from '@expo/vector-icons';
import { colors, spacing, borderRadius } from '../constants/theme'; import { colors, spacing, borderRadius } from '../constants/theme';
const TABLET_MIN_WIDTH = 768;
interface SearchBarProps { interface SearchBarProps {
placeholder?: string; placeholder?: string;
onSearch: (query: string) => void; onSearch: (query: string) => void;
@@ -16,6 +18,8 @@ export function SearchBar({
value, value,
onChangeText onChangeText
}: SearchBarProps) { }: SearchBarProps) {
const { width } = useWindowDimensions();
const isTablet = width >= TABLET_MIN_WIDTH;
const [localValue, setLocalValue] = useState(value || ''); const [localValue, setLocalValue] = useState(value || '');
const handleChange = (text: string) => { const handleChange = (text: string) => {
@@ -34,10 +38,10 @@ export function SearchBar({
}; };
return ( return (
<View style={styles.container}> <View style={[styles.container, isTablet && styles.containerTablet]}>
<Ionicons name="search" size={20} color={colors.textSecondary} style={styles.icon} /> <Ionicons name="search" size={20} color={colors.textSecondary} style={styles.icon} />
<TextInput <TextInput
style={styles.input} style={[styles.input, isTablet && styles.inputTablet]}
placeholder={placeholder} placeholder={placeholder}
placeholderTextColor={colors.textSecondary} placeholderTextColor={colors.textSecondary}
value={localValue} value={localValue}
@@ -71,6 +75,10 @@ const styles = StyleSheet.create({
shadowRadius: 8, shadowRadius: 8,
elevation: 2, elevation: 2,
}, },
containerTablet: {
paddingHorizontal: spacing.lg,
paddingVertical: spacing.md,
},
icon: { icon: {
marginRight: spacing.sm, marginRight: spacing.sm,
}, },
@@ -80,6 +88,10 @@ const styles = StyleSheet.create({
color: colors.text, color: colors.text,
paddingVertical: spacing.xs, paddingVertical: spacing.xs,
}, },
inputTablet: {
fontSize: 18,
paddingVertical: spacing.sm,
},
clearButton: { clearButton: {
marginLeft: spacing.sm, marginLeft: spacing.sm,
}, },
@@ -0,0 +1,29 @@
import { useWindowDimensions } from 'react-native';
const TABLET_MIN_WIDTH = 768;
export function useResponsive() {
const { width, height } = useWindowDimensions();
const isTablet = width >= TABLET_MIN_WIDTH;
const isLandscape = width > height;
// Scale factor for tablet: 1.0 on phone, ~1.2 on tablet
const scale = isTablet ? 1.2 : 1.0;
// Max content width to prevent stretching on large screens
const maxContentWidth = isTablet ? Math.min(600, width * 0.6) : width;
// Horizontal padding: more on tablets to center content
const horizontalPadding = isTablet ? 48 : 24;
return {
width,
height,
isTablet,
isLandscape,
scale,
maxContentWidth,
horizontalPadding,
};
}
+13 -3
View File
@@ -9,6 +9,7 @@ import AdminView from './views/AdminView';
import LoginModal from './components/LoginModal'; import LoginModal from './components/LoginModal';
import SavedNotifications from './components/SavedNotifications'; import SavedNotifications from './components/SavedNotifications';
import BottomNav from './components/BottomNav'; import BottomNav from './components/BottomNav';
import { getFaro } from './utils/faro';
function App() { function App() {
const [screen, setScreen] = useState('home'); const [screen, setScreen] = useState('home');
@@ -40,7 +41,10 @@ function App() {
fetch('/api/auth/check') fetch('/api/auth/check')
.then(r => r.json()) .then(r => r.json())
.then(data => { if (data.authenticated) setCurrentUser(data.user); }) .then(data => { if (data.authenticated) setCurrentUser(data.user); })
.catch(() => {}) .catch((err) => {
console.warn('[auth/check]', err);
getFaro()?.pushError(err, { type: 'network', url: '/api/auth/check' });
})
.finally(() => setAuthChecked(true)); .finally(() => setAuthChecked(true));
window.addEventListener('resize', handleResize); window.addEventListener('resize', handleResize);
@@ -57,7 +61,10 @@ function App() {
const count = (data.global?.length || 0) + (data.pharmacy?.length || 0); const count = (data.global?.length || 0) + (data.pharmacy?.length || 0);
setBadgeCount(count); setBadgeCount(count);
}) })
.catch(() => {}); .catch((err) => {
console.warn('[notifications/mine]', err);
getFaro()?.pushError(err, { type: 'network', url: '/api/notifications/mine' });
});
return () => { cancelled = true; }; return () => { cancelled = true; };
}, [currentUser]); }, [currentUser]);
@@ -69,7 +76,10 @@ function App() {
if (!data) return; if (!data) return;
setBadgeCount((data.global?.length || 0) + (data.pharmacy?.length || 0)); setBadgeCount((data.global?.length || 0) + (data.pharmacy?.length || 0));
}) })
.catch(() => {}); .catch((err) => {
console.warn('[refreshBadge]', err);
getFaro()?.pushError(err, { type: 'network', url: '/api/notifications/mine' });
});
} }
function handleLogin(user) { function handleLogin(user) {
@@ -0,0 +1,57 @@
import React from 'react';
export default class ErrorBoundary extends React.Component {
constructor(props) {
super(props);
this.state = { hasError: false, error: null };
}
static getDerivedStateFromError(error) {
return { hasError: true, error };
}
componentDidCatch(error, info) {
// Report to Faro if available
try {
const faro = window.__faro;
if (faro?.api?.pushError) {
faro.api.pushError(error, { type: 'react-boundary', componentStack: info.componentStack });
}
} catch {
// Faro reporting must never break the app
}
console.error('[ErrorBoundary]', error, info);
}
render() {
if (this.state.hasError) {
return (
<div style={{
padding: '2rem',
textAlign: 'center',
fontFamily: 'system-ui, sans-serif',
color: '#333',
}}>
<h2>Algo salió mal</h2>
<p style={{ color: '#666' }}>Ha ocurrido un error inesperado. Por favor, recarga la página.</p>
<button
onClick={() => window.location.reload()}
style={{
marginTop: '1rem',
padding: '0.5rem 1.5rem',
backgroundColor: '#27633a',
color: '#fff',
border: 'none',
borderRadius: '6px',
cursor: 'pointer',
fontSize: '1rem',
}}
>
Recargar
</button>
</div>
);
}
return this.props.children;
}
}
+12 -1
View File
@@ -1,6 +1,7 @@
import React from 'react'; import React from 'react';
import ReactDOM from 'react-dom/client'; import ReactDOM from 'react-dom/client';
import App from './App'; import App from './App';
import ErrorBoundary from './components/ErrorBoundary';
import './index.css'; import './index.css';
import { initNativeShell } from './utils/native'; import { initNativeShell } from './utils/native';
import { initFaro } from './utils/faro'; import { initFaro } from './utils/faro';
@@ -9,9 +10,19 @@ import { initFaro } from './utils/faro';
// No-op if VITE_FARO_ENDPOINT is not configured. // No-op if VITE_FARO_ENDPOINT is not configured.
initFaro(); initFaro();
// Global unhandled promise rejection handler — report to Faro
window.addEventListener('unhandledrejection', (event) => {
console.warn('[unhandledrejection]', event.reason);
try {
window.__faro?.api?.pushError(event.reason, { type: 'unhandled-rejection' });
} catch { /* Faro must never break the app */ }
});
ReactDOM.createRoot(document.getElementById('root')).render( ReactDOM.createRoot(document.getElementById('root')).render(
<React.StrictMode> <React.StrictMode>
<App /> <ErrorBoundary>
<App />
</ErrorBoundary>
</React.StrictMode> </React.StrictMode>
); );
+9 -1
View File
@@ -17,6 +17,11 @@ import { TracingInstrumentation } from '@grafana/faro-web-tracing';
import { OtlpHttpTransport } from '@grafana/faro-transport-otlp-http'; import { OtlpHttpTransport } from '@grafana/faro-transport-otlp-http';
let initialized = false; let initialized = false;
let faroApi = null;
export function getFaro() {
return faroApi;
}
export function initFaro() { export function initFaro() {
if (initialized) return; if (initialized) return;
@@ -34,7 +39,7 @@ export function initFaro() {
const version = import.meta.env.VITE_FARO_APP_VERSION || '1.0.0'; const version = import.meta.env.VITE_FARO_APP_VERSION || '1.0.0';
try { try {
initializeFaro({ const faro = initializeFaro({
url: `${endpoint.replace(/\/$/, '')}/v1/traces`, url: `${endpoint.replace(/\/$/, '')}/v1/traces`,
app: { app: {
name: appName, name: appName,
@@ -61,6 +66,9 @@ export function initFaro() {
url: `${endpoint.replace(/\/$/, '')}/v1/traces`, url: `${endpoint.replace(/\/$/, '')}/v1/traces`,
}), }),
}); });
faroApi = faro.api;
// Expose for ErrorBoundary and manual reporting
window.__faro = faro;
} catch (err) { } catch (err) {
// Never let Faro init failure break the app. // Never let Faro init failure break the app.
// eslint-disable-next-line no-console // eslint-disable-next-line no-console