Valtio and new tab menu
This commit is contained in:
@@ -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}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user