-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfriendRequests.js
More file actions
91 lines (83 loc) · 2.68 KB
/
Copy pathfriendRequests.js
File metadata and controls
91 lines (83 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import React, { Component } from 'react';
import {
Container,
Content,
Button,
Left,
Body,
Icon,
Text,
Right,
List,
ListItem,
Card,
CardItem,
SwipeRow,
View,
Badge,
Header,
Item,
Input,
Toast
} from 'native-base';
import styles from './styles';
import { default as FAIcon } from 'react-native-vector-icons/FontAwesome';
import { NativeModules, AsyncStorage } from 'react-native';
import axios from 'axios';
import Database from '../../../utils/database';
import Prompt from 'react-native-prompt';
import firebase from 'firebase';
const SpotifyModule = NativeModules.SpotifyModule;
export default class FriendRequests extends Component {
constructor(props) {
super(props);
this.state = {
requests: this.props.navigation.state.params
}
}
deleteRequest = (userId) => {
Database.rejectFriendFromPending(userId)
this.setState({requests: this.state.requests.filter(person => userId != person.userId)}, () => {
if(!this.state.requests.length) this.props.navigation.goBack()
})
Toast.show({text: 'Request deleted!', position: 'bottom', duration: 1500, type: 'danger'})
}
acceptRequest = (userId) => {
Database.addFriendFromPending(userId)
this.setState({requests: this.state.requests.filter(person => userId != person.userId)}, () => {
if(!this.state.requests.length) this.props.navigation.goBack()
})
Toast.show({text: 'Friend added!', position: 'bottom', duration: 1500, type: 'success'})
}
render() {
return (
<Container>
<Content>
<Card>
<CardItem header>
<Icon active name="md-people" style={styles.headerIcon} />
<Text style={styles.header}>Requests</Text>
</CardItem>
{this.state.requests.map(friend => {
return(
<CardItem bordered key={friend.userId}>
<Body>
<Text>{friend.fullname}</Text>
<Text note >@{friend.username}</Text>
</Body>
{/* OB/TL: consider moving styles to file (like in other places) */}
<Button small style={{backgroundColor: "#FC642D", margin: 5}} onPress={() => this.acceptRequest(friend.userId)}>
<Icon name="ios-add" />
</Button>
<Button small danger style={{margin: 5}} onPress={() => this.deleteRequest(friend.userId)}>
<Icon name="ios-close" />
</Button>
</CardItem>
)
})}
</Card>
</Content>
</Container>
);
}
}