complated
This commit is contained in:
@@ -38,6 +38,15 @@ export function NotificationTab() {
|
||||
initialPageParam: 1,
|
||||
});
|
||||
const notifications = data?.pages.flatMap((p) => p.results) ?? [];
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const { mutate: markAllAsRead, isPending: isMarkingAllRead } = useMutation({
|
||||
mutationFn: () => user_api.mark_all_as_read(),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['notifications-list'] });
|
||||
queryClient.invalidateQueries({ queryKey: ['notification-list'] });
|
||||
},
|
||||
});
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
@@ -82,6 +91,25 @@ export function NotificationTab() {
|
||||
<Text style={[styles.headerTitle, { color: isDark ? '#f1f5f9' : '#0f172a' }]}>
|
||||
{t('Bildirishnomalar')}
|
||||
</Text>
|
||||
|
||||
{notifications.some((n) => !n.is_read) && (
|
||||
<TouchableOpacity
|
||||
style={[
|
||||
styles.markAllButton,
|
||||
{ backgroundColor: isDark ? '#1e293b' : '#e0f2fe', borderColor: '#3b82f6' },
|
||||
]}
|
||||
onPress={() => markAllAsRead()}
|
||||
disabled={isMarkingAllRead}
|
||||
>
|
||||
{isMarkingAllRead ? (
|
||||
<ActivityIndicator size="small" color="#3b82f6" />
|
||||
) : (
|
||||
<Text style={[styles.markAllText, { color: '#3b82f6' }]}>
|
||||
{t("Barchasi o'qildi")}
|
||||
</Text>
|
||||
)}
|
||||
</TouchableOpacity>
|
||||
)}
|
||||
</View>
|
||||
<FlatList
|
||||
data={notifications}
|
||||
@@ -372,5 +400,19 @@ const styles = StyleSheet.create({
|
||||
fontSize: 18,
|
||||
fontWeight: '700',
|
||||
lineHeight: 24,
|
||||
flex: 1,
|
||||
},
|
||||
markAllButton: {
|
||||
paddingHorizontal: 12,
|
||||
paddingVertical: 8,
|
||||
borderRadius: 8,
|
||||
borderWidth: 1,
|
||||
minWidth: 80,
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
},
|
||||
markAllText: {
|
||||
fontSize: 13,
|
||||
fontWeight: '600',
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user