summaryrefslogtreecommitdiff
path: root/frontend/app/screens/social/notifications.js
blob: c397d17ba7afd3cfcffc2d09582c9f848ad848dc (plain)
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
92
93
94
95
96
97
98
import React from 'react';
import {
  FlatList,
  View,
  Image,
} from 'react-native';
import { RkStyleSheet, RkText } from 'react-native-ui-kitten';
import { Avatar } from '../../components';
import { data } from '../../data';

const moment = require('moment');

export class Notifications extends React.Component {
  static navigationOptions = {
    title: 'Notifications',
  };

  state = {
    data: data.getNotifications(),
  };

  extractItemKey = (item) => `${item.id}`;

  renderAttachment = (item) => {
    const hasAttachment = item.attach !== undefined;
    return hasAttachment ? <View /> : <Image style={styles.attachment} source={item.attach} />;
  };

  renderItem = ({ item }) => (
    <View style={styles.container}>
      <Avatar
        img={item.user.photo}
        rkType='circle'
        style={styles.avatar}
        badge={item.type}
      />
      <View style={styles.content}>
        <View style={styles.mainContent}>
          <View style={styles.text}>
            <RkText>
              <RkText rkType='header6'>{`${item.user.firstName} ${item.user.lastName}`}</RkText>
              <RkText rkType='primary2'> {item.description}</RkText>
            </RkText>
          </View>
          <RkText
            rkType='secondary5 hintColor'>{moment().add(item.time, 'seconds').fromNow()}
          </RkText>
        </View>
        {this.renderAttachment(item)}
      </View>
    </View>
  );

  render = () => (
    <FlatList
      style={styles.root}
      data={this.state.data}
      renderItem={this.renderItem}
      keyExtractor={this.extractItemKey}
    />
  );
}

const styles = RkStyleSheet.create(theme => ({
  root: {
    backgroundColor: theme.colors.screen.base,
  },
  container: {
    padding: 16,
    flexDirection: 'row',
    borderBottomWidth: 1,
    borderColor: theme.colors.border.base,
    alignItems: 'flex-start',
  },
  avatar: {},
  text: {
    marginBottom: 5,
  },
  content: {
    flex: 1,
    marginLeft: 16,
    marginRight: 0,
  },
  mainContent: {
    marginRight: 60,
  },
  img: {
    height: 50,
    width: 50,
    margin: 0,
  },
  attachment: {
    position: 'absolute',
    right: 0,
    height: 50,
    width: 50,
  },
}));