-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNoticeDetailScreen.tsx
More file actions
175 lines (161 loc) · 4.02 KB
/
Copy pathNoticeDetailScreen.tsx
File metadata and controls
175 lines (161 loc) · 4.02 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import React, { useState, useEffect } from 'react';
import {
View,
Text,
ScrollView,
StyleSheet,
ActivityIndicator,
TouchableOpacity,
} from 'react-native';
import { useTranslation } from 'react-i18next';
import { useRoute, useNavigation } from '@react-navigation/native';
import { authFetch } from './src/utils/api';
const NoticeDetailScreen = ({ navigation }) => {
const { t } = useTranslation();
const route = useRoute();
const [notice, setNotice] = useState(null);
const [loading, setLoading] = useState(true);
/*const fetchNoticeRead = async () => {
try {
const response = await authFetch(`${BASE_URL}/notices/read/${route.params.id}`, {
method: 'POST',
});
if (response.ok) {
} else {
throw new Error('Failed to fetch message data');
}
} catch (error) {
console.error('Error fetching message:', error);
}
}; */
const fetchNotice= async () => {
try {
const response = await authFetch(`/notices/${route.params.id}`, {
headers: {
"Content-Type": "application/json",
},
});
if (response.ok) {
const data = await response.json();
// Always mark as read when viewing the message
// fetchNoticeRead();
setNotice(data);
} else {
throw new Error('Failed to fetch notice data');
}
} catch (error) {
console.error('Error fetching notice:', error);
} finally {
setLoading(false);
}
};
const goBackToList = () => {
navigation.setParams({ refresh: true });
};
useEffect(() => {
fetchNotice();
}, [navigation, route.params.id]);
if (loading) {
return (
<View style={styles.container}>
<ActivityIndicator size="large" color="#000" />
</View>
);
}
if (!notice) {
return (
<View style={styles.errorContainer}>
<Text style={styles.errorTitle}>{t('common.error')}</Text>
<Text style={styles.errorMessage}>{t('message.noMessage')}</Text>
<TouchableOpacity style={styles.backButton} onPress={() => navigation.goBack()}>
<Text style={styles.buttonText}>{t('common.backToList')}</Text>
</TouchableOpacity>
</View>
);
}
return (
<View style={styles.container}>
<ScrollView style={styles.scrollView}>
<View style={styles.content}>
<View style={styles.contentContainer}>
<Text style={styles.title}>{notice.title}</Text>
<Text style={styles.contentText}>{notice.content}</Text>
</View>
<TouchableOpacity style={styles.backButton} onPress={() => navigation.goBack()}>
<View style={styles.buttonContent}>
<Text style={styles.buttonText}>{t('common.backToList')}</Text>
</View>
</TouchableOpacity>
</View>
</ScrollView>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1
},
scrollView: {
flex: 1,
},
content: {
padding: 20,
},
contentContainer: {
backgroundColor: '#f8f9fa',
padding: 16,
borderRadius: 12,
marginBottom: 20,
shadowColor: '#000',
shadowOffset: {
width: 0,
height: 2,
},
shadowOpacity: 0.1,
shadowRadius: 3.84,
elevation: 5,
},
contentText: {
fontSize: 16,
lineHeight: 24,
color: '#333',
},
backButton: {
backgroundColor: '#ccc',
padding: 12,
borderRadius: 8,
width: '100%',
justifyContent: 'center',
alignItems: 'center',
},
buttonContent: {
width: '100%',
justifyContent: 'center',
alignItems: 'center',
},
buttonText: {
color: '#666',
fontSize: 16,
fontWeight: '500',
},
errorContainer: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#fff',
padding: 20,
},
errorTitle: {
fontSize: 20,
fontWeight: 'bold',
color: '#666',
marginBottom: 16,
},
errorMessage: {
fontSize: 16,
color: '#666',
textAlign: 'center',
marginBottom: 32,
}
});
export default NoticeDetailScreen;