MovieRankingTab.js
3.86 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
import React, { Component } from "react";
import {
View,
StyleSheet,
SafeAreaView,
ScrollView,
FlatList,
AsyncStorage
} from "react-native";
import { Icon } from "native-base";
import axios from "axios";
import RankUI from "./RankUI";
import * as API from "../../API_Key.js";
const API_KEY = API.getAPI_KEY1(); // 영하 순위 받아오기
const API_KEY2 = API.getAPI_KEY2(); // 줄거리 받아오기
export default class MovieRankingTab extends Component {
state = {
rankingList: []
};
static navigationOptions = {
tabBarIcon: ({ tintColor }) => (
<Icon name="ios-trophy" style={{ color: tintColor }} />
)
};
getMovieList = async date => {
axios
.get(
`http://www.kobis.or.kr/kobisopenapi/webservice/rest/boxoffice/searchDailyBoxOfficeList.json?key=${API_KEY}&targetDt=${date}`
)
.then(response => {
var ranking = response.data.boxOfficeResult.dailyBoxOfficeList;
var infos = []; // 전체 정보
var info = {
// 객체 생성
name: "",
url: "",
overview: ""
};
// 랭킹 순으로 이름 정보 가져오기
for (let i = 0; i < 10; i++) {
info.name = ranking[i].movieNm;
infos.push(info);
info = {
name: "",
url: "",
overview: ""
};
}
// 영화이름으로 포스터 url, 줄거리 가져오기
for (let i = 0; i < 10; i++) {
name = infos[i].name;
axios
.get(
`https://api.themoviedb.org/3/search/movie?api_key=${API_KEY2}&query=${name}&language=ko-KR&page=1`
)
.then(response => {
infos[i].url = response.data.results[0].poster_path;
infos[i].overview = response.data.results[0].overview;
if (i == 9) {
this.setState({
rankingList: infos
});
}
});
}
})
.catch(error => {
console.log(error);
});
};
printData = async key => {
value = await AsyncStorage.getItem(key);
console.log(value);
};
componentDidMount() {
var month = new Date().getMonth() + 1; //Current Month
if (month < 10) {
month = "0" + month;
}
var day = new Date().getDate() - 1; // 어제 일짜
if (day == 1) {
day = 30;
month = month - 1;
if (month == 0) {
month == 12;
}
} else if (day < 10) {
day = "0" + day;
}
var year = new Date().getFullYear(); //Current Year
var date = year + "" + month + day;
this.getMovieList(date);
}
//눌렀을 때 디테일 텝으로 이동
_onPressButton = async temp => {
axios
.get(
`https://api.themoviedb.org/3/search/movie?api_key=${API_KEY2}&query=${temp}&language=ko-KR&page=1`
)
.then(response => {
var data = response.data.results[0];
this.props.navigation.navigate("Detail", {
title: data.title,
overview: data.overview + "\n\n\n",
release_date: data.release_date,
url: data.poster_path,
back: data.backdrop_path
});
});
};
render() {
return (
<SafeAreaView style={style.container}>
<ScrollView>
<FlatList
data={this.state.rankingList}
renderItem={({ item }) => {
return (
<View>
<RankUI
name={item.name}
imgur={item.url}
overview={item.overview}
_onPress={this._onPressButton.bind(this, `${item.name}`)}
/>
</View>
);
}}
/>
</ScrollView>
</SafeAreaView>
);
}
}
const style = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "black"
}
});