-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImageShow.js
210 lines (192 loc) · 6.43 KB
/
ImageShow.js
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import React, { Component } from 'react';
import { Image, View, Dimensions, AsyncStorage, StatusBar, StyleSheet, TouchableOpacity } from 'react-native';
import { Container, Content, Card,Header, Title, Footer, Icon, Spinner, FooterTab, CardItem, Thumbnail, Text, Button, Left, Body, Right, Item } from 'native-base';
import * as Font from 'expo-font';
import { Ionicons } from '@expo/vector-icons';
import api from './DbConfig';
StatusBar.setBackgroundColor('#0099ff',true);
const {width, height} = Dimensions.get("window");
export default class ImageShow extends Component {
state = {
loading: true
}
constructor(props) {
super(props);
this.state={
showImg:[],
imglink:'',
imgid:0,
loadImg:0,
userid:0,
};
}
_retrieveData = async () => {
try{
const useruid = await AsyncStorage.getItem('mail').then((value) => {
this.decision();
});
}
catch(err){
console.log('Profile Page store error: '+err);
}
};
decision=async ()=>{
try{
const useruid = await AsyncStorage.getItem('userid');
if (useruid!==null) {
this.setState({userid:useruid});
}
else{
this.setState({userid:0});
}
}
catch(err){
console.log('Profile Page store error: '+err);
}
}
setImgid = ()=>{
this.setState({imgid:this.props.route.params.id});
this.showImage();
}
delete(postid){
var InsertAPI = api+'deletepost.php';
var Data={postid:postid};
var headers={
'Accept':'application/json',
'Content-Type':'application.json'
}
fetch(InsertAPI,{
method:'POST',
headers:headers,
body:JSON.stringify(Data),
}).then((response)=>response.json()).then((response)=>{
if(response==='True'){
this.props.navigation.replace("Home");
}
else{
console.log(response);
this.props.navigation.replace("Home");
}
})
.catch(err=>{
console.log(err);
this.props.navigation.replace("Home");
})
}
showImage=()=>{
var InsertAPI = api+'showimg.php';
var Data={imgid:this.state.imgid};
var headers={
'Accept':'application/json',
'Content-Type':'application.json'
}
fetch(InsertAPI,{
method:'POST',
headers:headers,
body:JSON.stringify(Data),
}).then((response)=>response.json()).then((response)=>{
if(response===null){
this.setState({loadImg:1});
this.props.navigation.goBack();
}
else{
this.setState({showImg:response});
this.setState({imglink:this.state.showImg[0].image});
this.setState({loadImg:1});
}
})
.catch(err=>{
alert('Something went wrong');
this.setState({loadImg:1});
this.props.navigation.goBack();
})
}
async componentDidMount() {
this._retrieveData();
await Font.loadAsync({
'Roboto': require('native-base/Fonts/Roboto.ttf'),
'Roboto_medium': require('native-base/Fonts/Roboto_medium.ttf'),
...Ionicons.font,
})
this.setState({ loading: false });
this.setImgid();
}
render() {
if (this.state.loading) {
return (
<View></View>
);
}
return (
<Container>
<Header style={{backgroundColor:'#000'}} androidStatusBarColor='#0099ff'>
<Left>
<Button transparent onPress={()=>{this.props.navigation.goBack()}}>
<Icon name='arrow-back' />
</Button>
</Left>
<Body>
</Body>
<Right />
</Header>
<Content style={{backgroundColor:'black'}}>
{this.state.loadImg==0?
<View style={{marginTop:height/3}}>
<Spinner color='#0099ff' />
</View>:<View>
<View style={{marginTop:10, flexDirection:'row'}}>
<Left><Text style={{color:'white', margin:10, fontSize:22, marginTop:50}}>{this.state.showImg[0].title}</Text></Left>
{this.state.userid==this.state.showImg[0].uid?
<Right>
<TouchableOpacity onPress={()=>{this.delete(this.state.showImg[0].id)}}>
<Icon name="trash" style={{margin:10,color:'red'}}/>
</TouchableOpacity>
</Right>:<View/>}
</View>
<View style={{marginTop:25, alignItems:'center', padding:10}}>
<Thumbnail large
source={{uri:this.state.imglink}} style={{height:height/2, width:width-20, borderRadius:0}}/>
</View>
<View>
<Text style={{color:'white', margin:20, fontSize:15, marginTop:50}}>{this.state.showImg[0].details}</Text>
</View>
</View>}
</Content>
<Footer>
<FooterTab style={{backgroundColor:'#fff'}}>
<Button onPress={()=>{this.props.navigation.replace("Home")}}>
<Icon name="home" />
</Button>
<Button onPress={()=>{this.props.navigation.replace("Feed")}}>
<Icon name="grid" />
</Button>
<Button onPress={()=>{this.props.navigation.replace("Search")}}>
<Icon name="search" />
</Button>
<Button onPress={()=>{this.props.navigation.replace("Upload")}}>
<Icon active name="paper-plane" />
</Button>
<Button active style={{backgroundColor:'#0099ff'}} onPress={()=>{this.props.navigation.replace("Profile")}}>
<Icon name="person" />
</Button>
</FooterTab>
</Footer>
</Container>
);
}
}
const styles = StyleSheet.create({
myHeader:{
height:60,
backgroundColor:'#0099FF',
justifyContent:'center',
padding:15,
elevation:7,
marginTop:25,
},
headerText:{
fontSize:25,
fontWeight:'bold',
color:'#fff',
},
})