Add notification viewed sync and header badge dot

This commit is contained in:
Adolfo Reyna
2026-02-20 22:15:07 -05:00
parent cc9ca1d075
commit 0ba5d7bd0d
3 changed files with 55 additions and 2 deletions

View File

@@ -6,10 +6,32 @@ import SinglePost from '../components/SinglePostComponent';
import Moment from 'moment';
import { useSnapshot } from 'valtio';
import GlobalState from '../contexts/GlobalState.js';
import API from '../API.js';
import { useFocusEffect } from '@react-navigation/native';
let NotificationsView = ({ navigation, route }) => {
const gState = useSnapshot(GlobalState);
const viewer = gState.me;
useFocusEffect(
React.useCallback(() => {
let active = true;
const markViewed = async () => {
const notifications = Array.isArray(viewer?.notifications) ? viewer.notifications : [];
const hasUnviewed = notifications.some((n) => n && n.viewed !== true);
if (!hasUnviewed) return;
const result = await API.markNotificationsViewed();
if (!active || result?.status !== "ok") return;
if (!GlobalState.me.notifications) GlobalState.me.notifications = [];
GlobalState.me.notifications = GlobalState.me.notifications.map((n) => ({ ...n, viewed: true }));
};
markViewed();
return () => {
active = false;
};
}, [viewer?.notifications?.length])
);
const renderNotification = (({ item }) => {
const gotToPost = () => {
navigation.navigate('SinglePost', { postid: item.postid });
@@ -17,7 +39,7 @@ let NotificationsView = ({ navigation, route }) => {
return (
<Card style={{ margin: 3 }} onPress={gotToPost}>
<Card.Content>
<Text>{item.body}</Text>
<Text style={{ fontWeight: item.viewed ? 'normal' : '700' }}>{item.body}</Text>
<Text style={{ fontWeight: 'normal', fontSize: 12 }}>
{" " + Moment(item.ts).fromNow()}
</Text>