App.js
3.36 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
/* src/app.js */
import ReactDOM from 'react-dom';
import { Route, BrowserRouter, Switch, Link, useHistory} from 'react-router-dom';
import React, { Component } from 'react';
import Home from './home';
//import {navigate} from "@reach/router"
import TodayChannel from './TodayChannel';
import TodayEpic from './TodayEpic';
import WeekChannel from './WeekChannel';
import WeekEpic from './WeekEpic'
import Search from './Search'
import App2 from './App2'
import './App.css'
import axios from 'axios';
const TestPage = ({data}) => {
const history = useHistory();
React.useEffect(()=>{
console.log(data)
if(data.length > 0)
history.push('/searchList/result')
}, [data])
return (
<></>
)
}
class App extends Component {
constructor(props) {
super(props)
this.state = {
searchList: [], //검색 결과
screenWidth: 0, //보여지는 윈도우 가로길이
}
}
onKeyDownMethod = async(e)=>
{
if(e.keyCode===13)//엔터 입력시
{
const searchTag = document.querySelector("#searchInput").value;
const res = await axios.get(`/api/search_data/${searchTag}`);
console.log(res.data);
this.setState({searchList: [res.data]})
}
}
render() {
const sStyle={
margin: "0 auto",
}
const lStyle ={
color: "black",
top: "30px",
height: "100%",
fontSize: "50px",
fontWeight: "bold",
color: "black",
textDecoration: "none",
}
return (
<BrowserRouter>
<div>
<div style={{height: "50px"}}></div>
<div id = "menu">
<ul>
<li><Link to='/todayEpic'>오늘 가장 많이 나온 에픽</Link></li>
<li><Link to='/todayChannel'>오늘 가장 많이 나온 채널</Link></li>
<li><Link to='/WeekEpic'>지난 1주간 가장 많이 나온 에픽</Link></li>
<li><Link to='/WeekChannel'>지난 1주간 가장 많이 나온 채널</Link></li>
{/* <li><Link to='/searchList'>테스트</Link></li>*/}
</ul>
</div>
<TestPage data={this.state.searchList} />
<div style={{height: "50px"}}></div>
<div id ="HomeLogo">
<Link style={lStyle}to='/'>D&F Epic</Link>
</div>
<div style={{height: "50px"}}></div>
<div class="active-cyan-4">
<input id="searchInput" onKeyDown={this.onKeyDownMethod} class="form-control" type="text" placeholder="Search" aria-label="Search"/>
</div>
<div style={{height: "50px"}}></div>
<Switch>
<Route exact path='/'><Home></Home></Route>
<Route path='/todayChannel'><TodayChannel></TodayChannel></Route>
<Route path='/todayEpic'><TodayEpic></TodayEpic></Route>
<Route path='/WeekEpic'><WeekEpic></WeekEpic></Route>
<Route path='/WeekChannel'><WeekChannel></WeekChannel></Route>
{/*<Route exact path='/searchList'><App2 searchList={this.state.searchList}></App2></Route>*/}
<Route path='/searchList/result'><Search searchList={this.state.searchList}></Search></Route>
<Route path ='/'>Not Found</Route>
</Switch>
</div>
</BrowserRouter>
);
}
}
ReactDOM.render(<BrowserRouter><App/></BrowserRouter>,document.getElementById('root'));
export default App;