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
|
import React from 'react';
import {
FlatList,
Image,
View,
TouchableOpacity,
} from 'react-native';
import {
RkText,
RkCard, RkStyleSheet,
} from 'react-native-ui-kitten';
import axios from 'axios';
import { SocialBar } from '../../components';
import NavigationType from '../../config/navigation/propTypes';
export class Articles2 extends React.Component {
static propTypes = {
navigation: NavigationType.isRequired,
};
static navigationOptions = {
title: 'Problems List'.toUpperCase(),
};
state = {
articles: [],
};
componentDidMount() {
axios.get('http://192.168.1.43:8000/api/articles')
.then(res => {
this.setState({
articles: res.data,
});
});
}
extractItemKey = (item) => `${item.id}`;
onItemPressed = (item) => {
this.props.navigation.navigate('Article', { id: item.id });
};
renderItem = ({ item }) => (
<TouchableOpacity
delayPressIn={70}
activeOpacity={0.8}
onPress={() => this.onItemPressed(item)}>
<RkCard rkType='imgBlock' style={styles.card}>
<Image rkCardImg source={{ uri: `${item.image.toString().replace('http://127.0.0.1:8000/', '')}` }} />
<View rkCardImgOverlay rkCardContent style={styles.overlay}>
<RkText rkType='header4 inverseColor'>{item.title}</RkText>
</View>
<View rkCardFooter>
<SocialBar rkType='space' showLabel likes={item.rating} comments={item.n_comments} is_solved={item.is_solved ? 'Solved' : "Doesn't solved"} />
</View>
</RkCard>
</TouchableOpacity>
);
render = () => (
<FlatList
data={this.state.articles}
renderItem={this.renderItem}
keyExtractor={this.extractItemKey}
style={styles.container}
/>
);
}
const styles = RkStyleSheet.create(theme => ({
container: {
backgroundColor: theme.colors.screen.scroll,
paddingVertical: 8,
paddingHorizontal: 14,
},
card: {
marginVertical: 8,
},
time: {
marginTop: 5,
},
}));
|