최원석3 [goesnow]

add components, edit Update API

...@@ -13,17 +13,14 @@ import Footer from "./views/footer/Footer"; ...@@ -13,17 +13,14 @@ import Footer from "./views/footer/Footer";
13 const App = (pathname : string) : string => { 13 const App = (pathname : string) : string => {
14 history.pushState('','', pathname); 14 history.pushState('','', pathname);
15 15
16 - let contents : string = ` 16 + return `
17 <div> 17 <div>
18 ${Header()} 18 ${Header()}
19 - hello ${pathname} 19 + ${Body(pathname)}
20 - ${Body()}
21 ${Footer()} 20 ${Footer()}
22 <a href="/wonseog" id="nav-button" data-link>wonseok!!</a> 21 <a href="/wonseog" id="nav-button" data-link>wonseok!!</a>
23 </div> 22 </div>
24 `; 23 `;
25 -
26 - return contents;
27 } 24 }
28 25
29 export default App; 26 export default App;
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
6 6
7 const titleTemplate = (type : string, title : string) => ` 7 const titleTemplate = (type : string, title : string) => `
8 <div class="${type}-title"> 8 <div class="${type}-title">
9 - ${type} ${title} 9 + ${title}
10 </div> 10 </div>
11 ` 11 `
12 12
......
1 -export const BASE_URL = 'http://127.0.0.1:5000/'; 1 +export const BASE_URL = 'http://localhost:5000/';
......
...@@ -10,15 +10,32 @@ window.addEventListener('DOMContentLoaded', () => { ...@@ -10,15 +10,32 @@ window.addEventListener('DOMContentLoaded', () => {
10 const $App = document.querySelector('#App'); 10 const $App = document.querySelector('#App');
11 const pathname = window.location.pathname.split('/')[1]; 11 const pathname = window.location.pathname.split('/')[1];
12 12
13 - document.body.addEventListener('click', (e) => { 13 + document.body.addEventListener('click', async (e) => {
14 - const target = e.target as HTMLAnchorElement; 14 + e.stopPropagation();
15 - const href = target.href.split(BASE_URL)[1]; 15 + if((e.target as HTMLAnchorElement).matches("[data-link]")){
16 - 16 + const href = (e.target as HTMLAnchorElement).href.split(BASE_URL)[1];
17 - if(target.matches("[data-link]")){
18 e.preventDefault(); 17 e.preventDefault();
19 $App && ($App.innerHTML = App(href)); 18 $App && ($App.innerHTML = App(href));
19 + } else if((e.target as HTMLAnchorElement).id === 'update-button') {
20 + let result: any= null;
21 + const insta_id = (document.querySelector('#id-input') as HTMLInputElement).value;
22 +
23 + if(insta_id){
24 + try{
25 + result = await (await fetch(BASE_URL + 'update?insta_id=' + insta_id)).json();
26 + } catch (e){
27 + console.log(e);
28 + } finally {
29 + console.log(result)
30 + result && $App && ($App.innerHTML = App('main'))
31 + }
32 + }
20 } 33 }
21 }); 34 });
22 35
36 + window.addEventListener('popstate', ()=>{
37 + $App && ($App.innerHTML = App(pathname))
38 + });
39 +
23 $App && ($App.innerHTML = App(pathname)); 40 $App && ($App.innerHTML = App(pathname));
24 }) 41 })
...\ No newline at end of file ...\ No newline at end of file
......
1 +/**
2 + * @author wonseog
3 + * @date 2021-03-09
4 + * @description state 관리
5 + * 주로 instaId, followers, following 관리
6 + **/
7 +
8 +export interface StateType{
9 + insta_id? : string,
10 + followers? : Array<string>,
11 + following? : Array<string>
12 +}
13 +
14 +export const state: StateType ={
15 + insta_id : '',
16 + followers : [''],
17 + following : [''],
18 +};
19 +
20 +export const setState = (newState: StateType): StateType =>({
21 + ...state,
22 + ...newState
23 +});
...\ No newline at end of file ...\ No newline at end of file
...@@ -3,11 +3,24 @@ ...@@ -3,11 +3,24 @@
3 * @date : 2021/03/08 3 * @date : 2021/03/08
4 * @description : 페이지 내용 4 * @description : 페이지 내용
5 **/ 5 **/
6 +import Home from "./contents/Home";
6 7
7 -const Body = () : string => { 8 +const Body = (pathname: string) : string => {
9 + let contentsContainer = '';
10 +
11 + switch (pathname){
12 + case 'compare':
13 + break;
14 + case 'main':
15 + break;
16 + default:
17 + contentsContainer = Home();
18 + }
8 19
9 return ` 20 return `
10 - <div class="Body">Its my Body</div> 21 + <div class="Body">
22 + ${contentsContainer}
23 + </div>
11 `; 24 `;
12 } 25 }
13 26
......
1 +/**
2 + * @author wonseog
3 + * @date 2021-03-09
4 + * @description id 입력하는 메인 화면
5 + * 조회 / 업데이트
6 + **/
7 +import {state} from "../../../state/state";
8 +import Title from "../../../components/title";
9 +
10 +const Home = (): string =>{
11 + const onSubmit = (e : Event) => {
12 + e.preventDefault();
13 + alert('hi');
14 + }
15 +
16 + const literalTag = `<div class="home">
17 + <lable>
18 + ${Title('인스타 조회하기').Large}
19 + <input id="id-input" type="text" name="insta_id" />
20 + <button id="update-button">조회</button>
21 + </lable>
22 + </div>`
23 +
24 + return literalTag;
25 +}
26 +
27 +export default Home;
...\ No newline at end of file ...\ No newline at end of file
...@@ -3,13 +3,13 @@ ...@@ -3,13 +3,13 @@
3 * @date : 2021/03/08 3 * @date : 2021/03/08
4 * @description : 페이지 헤더 4 * @description : 페이지 헤더
5 **/ 5 **/
6 -import Title from "../../components/title";
7 6
8 -const Header = () : string => { 7 +import Title from "../../components/title";
9 8
10 - return ` 9 +const Header = () : string => `
11 - <div class="header">${Title('im title').Large}</div> 10 + <div class="header">
12 - `; 11 + ${Title('im title').Large}
13 -} 12 + </div>
13 +`;
14 14
15 export default Header; 15 export default Header;
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -49,10 +49,10 @@ def get_list(insta_id, driver): ...@@ -49,10 +49,10 @@ def get_list(insta_id, driver):
49 def crawler_instagram(insta_id): 49 def crawler_instagram(insta_id):
50 driver = webdriver.Chrome(executable_path=LOCAL_PROJECT_PATH + '/crawler/chromedriver') 50 driver = webdriver.Chrome(executable_path=LOCAL_PROJECT_PATH + '/crawler/chromedriver')
51 driver.get(url=INSTAGRAM_URL) 51 driver.get(url=INSTAGRAM_URL)
52 - time.sleep(4) 52 + time.sleep(2)
53 53
54 login(driver) 54 login(driver)
55 - time.sleep(5) 55 + time.sleep(2)
56 56
57 url="%s/%s"%(INSTAGRAM_URL, insta_id) 57 url="%s/%s"%(INSTAGRAM_URL, insta_id)
58 driver.get(url=url) 58 driver.get(url=url)
......
...@@ -29,11 +29,9 @@ def page_not_found(): ...@@ -29,11 +29,9 @@ def page_not_found():
29 def home(path): 29 def home(path):
30 if path == 'update': 30 if path == 'update':
31 insta_id = request.args.get('insta_id') 31 insta_id = request.args.get('insta_id')
32 - update(insta_id) 32 + return update(insta_id)
33 - # elif path == '': 33 +
34 - else: 34 + return send_from_directory(my_path, filename='index.html')
35 - print()
36 - return send_from_directory(my_path, filename='index.html')
37 35
38 36
39 if __name__ == "__main__": 37 if __name__ == "__main__":
......