1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
import { Link } from 'expo-router';
import {
ActivityIndicator,
FlatList,
Pressable,
StyleSheet,
Text,
View,
} from 'react-native';
import { useOffices } from '@/features/offices/hooks/useOffices';
export default function OfficesScreen() {
const { offices, loading, error, reload } = useOffices();
if (loading) {
return (
<View style={styles.center}>
<ActivityIndicator size="large" />
</View>
);
}
if (error) {
return (
<View style={styles.center}>
<Text style={styles.error}>{error}</Text>
<Pressable style={styles.button} onPress={reload}>
<Text style={styles.buttonText}>Reintentar</Text>
</Pressable>
</View>
);
}
return (
<View style={styles.container}>
<Text style={styles.title}>Espacios</Text>
<FlatList
data={offices}
keyExtractor={(item) => item.id}
contentContainerStyle={styles.list}
ListEmptyComponent={
<Text style={styles.empty}>No hay espacios disponibles</Text>
}
renderItem={({ item }) => (
<Link href={`/(protected)/offices/${item.id}`} asChild>
<Pressable style={styles.card}>
<Text style={styles.cardTitle}>{item.name}</Text>
<Text>{item.location}</Text>
<Text>Capacidad: {item.capacity}</Text>
{item.description ? <Text>{item.description}</Text> : null}
</Pressable>
</Link>
)}
/>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 16,
},
center: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
padding: 24,
},
title: {
fontSize: 28,
fontWeight: '700',
marginBottom: 16,
},
list: {
gap: 12,
},
card: {
borderWidth: 1,
borderColor: '#ddd',
borderRadius: 12,
padding: 16,
gap: 6,
},
cardTitle: {
fontSize: 18,
fontWeight: '600',
},
error: {
color: 'red',
marginBottom: 12,
},
button: {
backgroundColor: '#1f6feb',
paddingHorizontal: 16,
paddingVertical: 12,
borderRadius: 10,
},
buttonText: {
color: '#fff',
fontWeight: '600',
},
empty: {
color: '#666',
},
});
|