Add notifications
This commit is contained in:
55
Views/NotificationsView.js
Normal file
55
Views/NotificationsView.js
Normal file
@@ -0,0 +1,55 @@
|
||||
import { StatusBar } from 'expo-status-bar';
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { View, Text, StyleSheet, SafeAreaView, FlatList } from 'react-native';
|
||||
import { Card } from 'react-native-paper';
|
||||
import API from '../API.js';
|
||||
import Post from '../components/Post.js';
|
||||
import Moment from 'moment';
|
||||
|
||||
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 renderNotification = (({ item }) => {
|
||||
const gotToPost = () => {
|
||||
navigation.navigate('SinglePost', { postid: item.postid, viewer: Me });
|
||||
};
|
||||
return (
|
||||
<Card style={{ margin: 3 }} onPress={gotToPost}>
|
||||
<Card.Content>
|
||||
<Text>{item.body}</Text>
|
||||
<Text style={{ fontWeight: 'normal', fontSize: 12 }}>
|
||||
{" " + Moment(item.ts).fromNow()}
|
||||
</Text>
|
||||
</Card.Content>
|
||||
</Card>
|
||||
)
|
||||
});
|
||||
|
||||
|
||||
return (
|
||||
<SafeAreaView style={styles.container}>
|
||||
<View>
|
||||
<FlatList
|
||||
data={notifications.reverse().slice(0, 10)}
|
||||
renderItem={renderNotification}
|
||||
keyExtractor={item => item.ts}
|
||||
/>
|
||||
</View>
|
||||
<StatusBar style="auto" />
|
||||
</SafeAreaView>
|
||||
);
|
||||
}
|
||||
|
||||
export default NotificationsView;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: {
|
||||
flex: 1,
|
||||
backgroundColor: "#edf2f7",
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user