Valtio and new tab menu

This commit is contained in:
aeroreyna
2022-03-24 22:00:00 -07:00
parent 0bee9204f2
commit 296c153b47
13 changed files with 93 additions and 66 deletions

View File

@@ -5,18 +5,15 @@ import { Card } from 'react-native-paper';
import API from '../API.js';
import Post from '../components/Post.js';
import Moment from 'moment';
import { useSnapshot } from 'valtio';
import GlobalState from '../contexts/GlobalState.js';
let NotificationsView = ({ navigation, route }) => {
let [Me, setMeProfile] = useState({});
let [notifications, setNotifications] = useState([]);
useEffect(async () => {
let r = await API.getMe();
setMeProfile(r);
setNotifications(r.notifications)
}, [route.params]);
const gState = useSnapshot(GlobalState);
const viewer = gState.me;
const renderNotification = (({ item }) => {
const gotToPost = () => {
navigation.navigate('SinglePost', { postid: item.postid, viewer: Me });
navigation.navigate('SinglePost', { postid: item.postid });
};
return (
<Card style={{ margin: 3 }} onPress={gotToPost}>
@@ -35,7 +32,7 @@ let NotificationsView = ({ navigation, route }) => {
<SafeAreaView style={styles.container}>
<View>
<FlatList
data={notifications.reverse().slice(0, 10)}
data={[...viewer.notifications].reverse().slice(0, 10)}
renderItem={renderNotification}
keyExtractor={item => item.ts}
/>