forked from vishallovecode/JavaWithDsa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestpurpose
92 lines (84 loc) · 2.1 KB
/
testpurpose
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
import { useState } from "react";
import { fetchMovieAvailability, fetchMovieList } from "./api";
import "./styles.css";
export default function App() {
const [data, setData] = useState([]);
const [availability, setAvailibility] = useState([]);
const fetchAvailability = (movie) => {
fetchMovieAvailability(movie)
.then((res) => {
// aupdateObject(res);
aupdateObject(res);
})
.catch((error) => {
console.error(error);
});
};
const aupdateObject = (available) => {
let data = [];
for (let i = 1; i <= 24; i++) {
if (available.indexOf(i) == -1) {
data.push({
[i]: true
});
} else {
data.push({
[i]: false
});
}
}
console.log(data);
setAvailibility(data);
};
// const updateArray = (available)=>{
// let data = [];
// for (let i = 1; i <= 24; i++) {
// if (available.indexOf(i) == -1) {
// data.push(true , i)
// } else {
// data.push(false , i)
// }
// }
// }
fetchMovieList()
.then((res) => {
setData(res);
console.log(res);
})
.catch((error) => {
console.error(error);
});
return (
<div className="App">
<div className="main">
{data.map((item) => {
return (
<div className="container">
<img src={item.imgUrl} className="img" />
<a href="#" onClick={() => fetchAvailability(item.name)}>
{item.name}
</a>
</div>
);
})}
</div>
<div className="box">
{availability?.map((item, index) => {
return (
<div>
{/* {item[index + 1] ? (
<div style={{ backgroundColor: "red" }}>{index + 1}</div>
) : (
<div style={{ backgroundColor: "blue" }}>{index + 1}</div>
)} */}
<div className={item[index + 1] ? "blue" : "green"}>
{index + 1}
</div>
</div>
);
})}
</div>
</div>
);
}
// Movie list