korkeep

Initial DB

1 -import React, { Component } from 'react'; 1 +import React, {Component} from 'react';
2 -import { 2 +import {Platform, StyleSheet, Text,
3 - StyleSheet, 3 + View,TouchableOpacity, AsyncStorage,
4 - Text, 4 +} from 'react-native';
5 - View, 5 +import { Icon } from "native-base";
6 - ScrollView,
7 - TouchableOpacity,
8 - Image,
9 - Alert,
10 - AsyncStorage
11 - } from 'react-native';
12 -import { Icon } from 'native-base';
13 -import axios from "axios";
14 -const API_KEY = "2bf00f660b1a6a3ffeb6e06ac270cce3";
15 -const NAVER_CLIENT_ID = "KqPsntd1hcPJ8FUPBGqN";
16 -const NAVER_CLIENT_SECRET = "0GRb3uya1U";
17 -import uuidv1 from "uuid/v1"; //ID 만들기위해 import
18 6
19 7
20 -export default class WantToWatchTab extends Component { 8 +export default class App extends Component {
21 //네비게이션 바 9 //네비게이션 바
22 static navigationOptions = { 10 static navigationOptions = {
23 tabBarIcon: ({ tintColor }) => ( 11 tabBarIcon: ({ tintColor }) => (
24 <Icon name='ios-star' style={{ color: tintColor }} /> 12 <Icon name='ios-star' style={{ color: tintColor }} />
25 ) 13 )
26 } 14 }
27 - 15 + saveData(){
28 - state = { 16 + let name = "앙기모띠";
29 - isLoading: true, 17 + AsyncStorage.setItem('user',name);
30 - info: [],
31 - date: "",
32 - imgur1: []
33 - };
34 -
35 - getMovieList = async date => {
36 - axios
37 - .get(
38 - `http://www.kobis.or.kr/kobisopenapi/webservice/rest/boxoffice/searchDailyBoxOfficeList.json?key=${API_KEY}&targetDt=${date}`
39 - )
40 - .then(
41 - response => {
42 - this.setState({
43 - //영화 제목
44 - name0: response.data.boxOfficeResult.dailyBoxOfficeList[0].movieNm,
45 - info: response.data.boxOfficeResult.dailyBoxOfficeList
46 - });
47 -
48 - name = response.data.boxOfficeResult.dailyBoxOfficeList[0].movieNm;
49 - fetch(
50 - `https://openapi.naver.com/v1/search/movie.json?query='${name}'`,
51 - {
52 - headers: {
53 - "X-Naver-Client-Id": NAVER_CLIENT_ID,
54 - "X-Naver-Client-Secret": NAVER_CLIENT_SECRET
55 - }
56 } 18 }
57 - ) 19 + displayData = async ()=>{
58 - .then(response => response.json()) 20 + try{
59 - .then(json => { 21 + let user = await AsyncStorage.getItem('user');
60 - this.setState({ 22 + alert(user);
61 - imgurl0: json.items[0].image
62 - });
63 - });
64 } 23 }
65 - ) 24 + catch(error){
66 - .catch(error => { 25 + alert(error)
67 - console.log(error);
68 - });
69 - };
70 -
71 - //날짜 정하기
72 - componentDidMount() {
73 - var day = new Date().getDate() - 1; // 어제 날짜
74 - if (day == 1) {
75 - day = 30;
76 - } else if (day < 10) {
77 - day = "0" + day;
78 } 26 }
79 - var month = new Date().getMonth() + 1; //Current Month
80 - var year = new Date().getFullYear(); //Current Year
81 - var date = year + "" + month + day;
82 - this.getMovieList(date);
83 } 27 }
84 -
85 - //눌렀을 때 동작
86 - _onPressButton = () => {
87 - Alert.alert("Image Pressed");
88 -
89 - };
90 -
91 -
92 -
93 render() { 28 render() {
94 return ( 29 return (
95 - <ScrollView style={style.scrollView}> 30 + <View style={styles.container}>
96 - <Text style={style.title}>MovieRanking</Text> 31 + <TouchableOpacity onPress ={this.saveData}>
97 - <View style={style.lowContainer}> 32 + <Text>User정보 저장</Text>
98 - <TouchableOpacity 33 + </TouchableOpacity>
99 - style={style.button} 34 + <TouchableOpacity onPress ={this.displayData}>
100 - onPress={this._onPressButton}//누르는 동작 35 + <Text>User정보 출력</Text>
101 - >
102 - <Image
103 - style={style.poster}
104 - source={{ uri: `${this.state.imgurl0}` }}
105 - />
106 - <Text>{this.state.name0}</Text>
107 </TouchableOpacity> 36 </TouchableOpacity>
108 </View> 37 </View>
109 - </ScrollView>
110 ); 38 );
111 } 39 }
112 } 40 }
113 41
114 - 42 +const styles = StyleSheet.create({
115 -const style = StyleSheet.create({
116 container: { 43 container: {
117 - flex: 1
118 - },
119 - scrollView: {
120 - // backgroundColor: "black",
121 - // justifyContent: "center",
122 - // alignItems: "center"
123 - },
124 - title: {
125 - fontSize: 20,
126 - justifyContent: "center",
127 - alignItems: "center"
128 - },
129 - lowContainer: {
130 flex: 1, 44 flex: 1,
131 - flexDirection: "row", 45 + justifyContent: 'center',
132 - justifyContent: "center", 46 + alignItems: 'center',
133 - alignItems: "center" 47 + backgroundColor: '#F5FCFF',
134 - },
135 - poster: {
136 - // resizeMode: "cover",
137 - flex: 10,
138 - width: "90%",
139 - height: 200,
140 - paddingHorizontal: 50
141 - // alignItems: "stretch"
142 }, 48 },
143 - });
...\ No newline at end of file ...\ No newline at end of file
49 +});
...\ No newline at end of file ...\ No newline at end of file
......