-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessageScreen.tsx
More file actions
108 lines (100 loc) · 2.4 KB
/
MessageScreen.tsx
File metadata and controls
108 lines (100 loc) · 2.4 KB
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
108
import React, { useState, useEffect, useCallback } from 'react';
import {
View,
Text,
FlatList,
StyleSheet,
TouchableOpacity,
ActivityIndicator
} from 'react-native';
import { useTranslation } from 'react-i18next';
import { useMessageContext } from './MessageContext';
const MessageScreen = ({ navigation }) => {
const { t } = useTranslation();
const { messages, total, loading, handleDeleteMessage } = useMessageContext();
if (loading) {
return (
<View>
<ActivityIndicator size="large" color="#007AFF" style={styles.loader} />
</View>
);
}
if (total === 0) {
return (
<View>
<Text style={styles.noMessagesText}>{t('message.no_items')}</Text>
</View>
);
}
const renderMessageItem = ({ item }) => {
const handlePress = () => {
navigation.navigate('MessageDetail', { id: item.id });
};
return (
<View style={styles.messageItem}>
<TouchableOpacity onPress={handlePress} style={styles.messageInfo}>
<Text style={styles.messageTitle}>{item.title}</Text>
<Text style={styles.messageCreatedAt}>
{new Date(item.created_at).toLocaleDateString()}
</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.deleteButton}
onPress={() => handleDeleteMessage(item.id)}
>
<Text style={styles.deleteButtonText}>{t('common.delete')}</Text>
</TouchableOpacity>
</View>
);
};
return (
<View style={{ flex: 1 }}>
<FlatList
data={messages}
renderItem={renderMessageItem}
keyExtractor={(item) => item.id.toString()}
contentContainerStyle={styles.messageList}
style={{ flexGrow: 1 }}
/>
</View>
);
};
const styles = StyleSheet.create({
noMessagesText: {
fontSize: 16,
color: '#666',
textAlign: 'center',
marginTop: 20,
},
messageList: {
padding: 8,
},
messageTitle: {
fontSize: 16,
fontWeight: 'bold',
},
messageItem: {
flexDirection: 'row',
padding: 12,
borderBottomWidth: 1,
borderBottomColor: '#ccc',
marginBottom: 8,
},
messageInfo: {
flex: 1,
},
messageCreatedAt: {
fontSize: 12,
color: '#666',
},
deleteButton: {
backgroundColor: '#ff4444',
padding: 8,
borderRadius: 4,
},
deleteButtonText: {
color: 'white',
fontSize: 14,
},
});
export default MessageScreen;