-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuserDashboard.js
More file actions
155 lines (124 loc) · 3.47 KB
/
userDashboard.js
File metadata and controls
155 lines (124 loc) · 3.47 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
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
// tab switching
let btn_click=document.querySelectorAll('.btn_container');
let nav =document.querySelectorAll('.nav-tab');
const tabSwitch=(index,color)=>{
btn_click.forEach((node)=>{
node.style.backgroundColor="";
node.style.color="";
node.style.border='none';
});
btn_click[index].style.backgroundColor='white';
btn_click[index].style.border='1px solid '
// btn_click[index].style.borderRight='none'
btn_click[index].style.color=color;
nav.forEach((node)=>{
node.style.display='none';
});
nav[index].style.display="block";
}
tabSwitch(0,' #7b7b7b');
// tab switch end
// form function
let submit=document.getElementById('submit');
submit.disabled=true;
let file=document.getElementById('file');
file.onchange=()=>{
imageHandle();
}
let imgUrl;
const imageHandle=async()=>{
let img = document.getElementById('file');
let ac_img=img.files[0];
let form=new FormData();
form.append('image',ac_img);
let res=await fetch(`https://api.imgbb.com/1/upload?key=7653934e21bf1f5ec0f422196404d69f`,{
method:'POST',
body: form,
});
let data=await res.json()
submit.disabled=false
imgUrl=data.data.url;
console.log(data.data.url);
}
let form = document.querySelector('form')
const getData=async(e)=>{
e.preventDefault();
let obj={
id:Date.now(),
name:form.name.value,
exp:form.exp.value,
thumbnil:imgUrl,
status:false,
platform:form.platform.value,
website:form.shop.value,
}
form.name.value=null;
form.exp.value=null;
form.file.value=null;
let res= await fetch('https://my-nstagram.herokuapp.com/posts',{
method: 'POST',
body:JSON.stringify(obj),
headers:{
'Content-Type': 'application/json',
},
});
let data=await res.json();
//console.log(data);
}
// form function end
// products start
let body=document.getElementsByName('tbody');
const showData=async()=>{
let res=await fetch(' https://my-nstagram.herokuapp.com/posts')
let data= await res.json();
console.log(data);
append(data);
}
showData();
let tb=document.querySelector('tbody');
const append=(data)=>{
tb.innerHTML=null;
data.forEach((el)=>{
let tr=document.createElement('tr');
let name=document.createElement('td');
name.innerText=el.name;
let media=document.createElement('td');
let img=document.createElement('href');
img.innerText=el.thumbnil;
media.append(img);
let dsc=document.createElement('td');
dsc.innerText=el.exp;
let status=document.createElement('td');
status.innerText=el.status;
tr.append(name,media,dsc,status);
tb.append(tr);
});
}
// products end here
// statusbar items
const getStatus=async()=>{
let apr=document.getElementById('approved');
let faild=document.getElementById('faild');
let review=document.getElementById('reviewe');
let res = await fetch('https://my-nstagram.herokuapp.com/posts')
let data= await res.json();
let count=0;
let c=0;
data.forEach((el)=>{
if(el.status)
{
count++;
}
else c++;
});
faild.innerText=0+' '+'Could not Pass Review';
review.innerText=c+' '+'Under Review';
let tPost=count+"/"+data.length+" " + 'Approved';
apr.append(tPost);
}
getStatus();
let si_out = document.getElementById("sign_out");
si_out.onclick = () => {
window.location.href="index.html";
localStorage.clear();
}