1seok2

add Absolute Path, classify components

...@@ -10,7 +10,6 @@ import Header from "./views/header"; ...@@ -10,7 +10,6 @@ import Header from "./views/header";
10 import Body from "./views/body"; 10 import Body from "./views/body";
11 import Footer from "./views/footer"; 11 import Footer from "./views/footer";
12 import './assets/style/App.scss'; 12 import './assets/style/App.scss';
13 -import './assets/style/PageTransition.scss';
14 13
15 const App = (pathname : string) : string => { 14 const App = (pathname : string) : string => {
16 history.pushState('','', pathname); 15 history.pushState('','', pathname);
...@@ -19,8 +18,8 @@ const App = (pathname : string) : string => { ...@@ -19,8 +18,8 @@ const App = (pathname : string) : string => {
19 <div class="container"> 18 <div class="container">
20 ${Header()} 19 ${Header()}
21 ${Body(pathname)} 20 ${Body(pathname)}
22 - ${Footer()}
23 </div> 21 </div>
22 + ${Footer()}
24 `; 23 `;
25 } 24 }
26 25
......
...@@ -8,12 +8,7 @@ body { ...@@ -8,12 +8,7 @@ body {
8 justify-content: center; 8 justify-content: center;
9 align-items: center; 9 align-items: center;
10 flex-direction: column; 10 flex-direction: column;
11 - position: absolute;
12 - top: 50%;
13 - left: 50%;
14 - transform: translate(-50%, -50%);
15 min-width: 250px; 11 min-width: 250px;
16 - min-height: 500px; 12 + width: 100vw;
17 - width: 100%; 13 + height: 100vh;
18 - height: 100%;
19 } 14 }
...\ No newline at end of file ...\ No newline at end of file
......
1 .footer { 1 .footer {
2 - height: 50px; 2 + height: 120px;
3 background-color: #afafaf; 3 background-color: #afafaf;
4 display: flex; 4 display: flex;
5 justify-content: center; 5 justify-content: center;
......
1 +/**
2 + * @author : wonseog
3 + * @date : 2021/03/10
4 + * @description : 버튼 이벤트, Route 이벤트 등록 모음
5 +**/
6 +
7 +import {BASE_URL} from "@src/config/url";
8 +import {randomTransition} from "@src/components/pageTransition";
9 +import {setState} from "@src/store/state";
10 +
11 +export const addEvent = async (
12 + e : Event,
13 + $App : Element | null,
14 + App : (pathname : string) => string
15 +) => {
16 + e.stopPropagation();
17 +
18 + /* add navigation click event */
19 + if((e.target as HTMLAnchorElement).matches("[data-link]")){
20 + const href : string= (e.target as HTMLAnchorElement).href.split(BASE_URL)[1];
21 + e.preventDefault();
22 + setTimeout(()=>{
23 + $App && ($App.innerHTML = App(href));
24 + },1200);
25 + randomTransition();
26 + }
27 + /* add GET event for button */
28 + else if((e.target as HTMLButtonElement).id === 'search-button') {
29 + let result: any= null;
30 + const insta_id = (document.querySelector('#id-input') as HTMLInputElement).value;
31 +
32 + if(insta_id){
33 + try{
34 + result = await (await fetch(BASE_URL + 'update?insta_id=' + insta_id)).json();
35 + } catch (e){
36 + console.log(e);
37 + } finally {
38 + console.log(result);
39 + result && $App && (()=>{
40 + $App.innerHTML = App('main');
41 + setState({
42 + insta_id : insta_id,
43 + followers : result.followers,
44 + following : result.following
45 + });
46 + })();
47 + }
48 + } else {
49 + alert('아이디를 입력하세요');
50 + }
51 + }
52 + /* add POST event for button */
53 + else if((e.target as HTMLButtonElement).id === 'update-button') {
54 + let result: any= null;
55 + const insta_id = (document.querySelector('#id-input') as HTMLInputElement).value;
56 +
57 + if(insta_id){
58 + try{
59 + result = await (await fetch(BASE_URL + 'update?insta_id=' + insta_id)).json();
60 + } catch (e){
61 + console.log(e);
62 + } finally {
63 + console.log(result);
64 + result && $App && (()=>{
65 + $App.innerHTML = App('main');
66 + setState({insta_id : insta_id});
67 + })();
68 + }
69 + } else {
70 + alert('아이디를 입력하세요');
71 + }
72 + }
73 +}
...\ No newline at end of file ...\ No newline at end of file
...@@ -7,7 +7,9 @@ ...@@ -7,7 +7,9 @@
7 import App from './App'; 7 import App from './App';
8 import {BASE_URL} from './config/url'; 8 import {BASE_URL} from './config/url';
9 import {initialTrantition, randomTransition} from "./components/pageTransition"; 9 import {initialTrantition, randomTransition} from "./components/pageTransition";
10 -import {setState} from "./state/state"; 10 +import {setState} from "./store/state";
11 +import './assets/style/PageTransition.scss';
12 +import {addEvent} from "@src/components/addEvent";
11 13
12 window.addEventListener('DOMContentLoaded', () => { 14 window.addEventListener('DOMContentLoaded', () => {
13 /* add div for page transitions */ 15 /* add div for page transitions */
...@@ -31,37 +33,6 @@ window.addEventListener('DOMContentLoaded', () => { ...@@ -31,37 +33,6 @@ window.addEventListener('DOMContentLoaded', () => {
31 $App && ($App.innerHTML = App(pathname)); 33 $App && ($App.innerHTML = App(pathname));
32 34
33 document.body.addEventListener('click', async (e) => { 35 document.body.addEventListener('click', async (e) => {
34 - e.stopPropagation(); 36 + await addEvent(e, $App, App);
35 -
36 - /* add navigation click event */
37 - if((e.target as HTMLAnchorElement).matches("[data-link]")){
38 - const href : string= (e.target as HTMLAnchorElement).href.split(BASE_URL)[1];
39 - e.preventDefault();
40 - setTimeout(()=>{
41 - $App && ($App.innerHTML = App(href));
42 - },1200);
43 - randomTransition();
44 - }
45 - /* add POST event for button */
46 - else if((e.target as HTMLAnchorElement).id === 'update-button') {
47 - let result: any= null;
48 - const insta_id = (document.querySelector('#id-input') as HTMLInputElement).value;
49 -
50 - if(insta_id){
51 - try{
52 - result = await (await fetch(BASE_URL + 'update?insta_id=' + insta_id)).json();
53 - } catch (e){
54 - console.log(e);
55 - } finally {
56 - console.log(result);
57 - result && $App && (()=>{
58 - $App.innerHTML = App('main');
59 - setState({insta_id : insta_id});
60 - })();
61 - }
62 - } else {
63 - alert('아이디를 입력하세요');
64 - }
65 - }
66 }); 37 });
67 }) 38 })
...\ No newline at end of file ...\ No newline at end of file
......
1 /** 1 /**
2 * @author wonseog 2 * @author wonseog
3 * @date 2021-03-09 3 * @date 2021-03-09
4 - * @description state 관리 4 + * @description store 관리
5 * 주로 instaId, followers, following 관리 5 * 주로 instaId, followers, following 관리
6 **/ 6 **/
7 7
...@@ -11,12 +11,14 @@ export interface StateType{ ...@@ -11,12 +11,14 @@ export interface StateType{
11 following? : Array<string> 11 following? : Array<string>
12 } 12 }
13 13
14 -const state: StateType ={ 14 +const initialState = {
15 insta_id : '', 15 insta_id : '',
16 followers : [''], 16 followers : [''],
17 following : [''], 17 following : [''],
18 }; 18 };
19 19
20 +const state: StateType = initialState;
21 +
20 export const setState = (newState: StateType): StateType =>({ 22 export const setState = (newState: StateType): StateType =>({
21 ...state, 23 ...state,
22 ...newState 24 ...newState
......
...@@ -3,8 +3,11 @@ ...@@ -3,8 +3,11 @@
3 * @date : 2021/03/08 3 * @date : 2021/03/08
4 * @description : 페이지 내용 4 * @description : 페이지 내용
5 **/ 5 **/
6 -import Home from "./contents/Home"; 6 +
7 -import '../../assets/style/Body.scss'; 7 +import Intro from "./contents/intro";
8 +import Main from "./contents/main";
9 +import Compare from "./contents/compare";
10 +import '@src/assets/style/Body.scss';
8 11
9 const Body = (pathname: string) : string => { 12 const Body = (pathname: string) : string => {
10 let contentsContainer = ''; 13 let contentsContainer = '';
...@@ -12,12 +15,14 @@ const Body = (pathname: string) : string => { ...@@ -12,12 +15,14 @@ const Body = (pathname: string) : string => {
12 switch (pathname){ 15 switch (pathname){
13 case 'compare': 16 case 'compare':
14 /* 팔로워, 팔로잉 비교*/ 17 /* 팔로워, 팔로잉 비교*/
18 + contentsContainer = Compare();
15 break; 19 break;
16 case 'main': 20 case 'main':
17 /* 아이디 조회 후 */ 21 /* 아이디 조회 후 */
22 + contentsContainer = Main();
18 break; 23 break;
19 default: 24 default:
20 - contentsContainer = Home(); 25 + contentsContainer = Intro();
21 } 26 }
22 27
23 return ` 28 return `
......
1 +/**
2 + * @author : wonseog
3 + * @date : 2021/03/10
4 + * @description : followers vs followings
5 +**/
6 +
7 +const Compare = () => {
8 + return `
9 + <div class="compare">
10 + its compare
11 + </div>
12 + `
13 +}
14 +
15 +export default Compare
...\ No newline at end of file ...\ No newline at end of file
1 +export {default} from './Compare'
...\ No newline at end of file ...\ No newline at end of file
...@@ -4,24 +4,17 @@ ...@@ -4,24 +4,17 @@
4 * @description id 입력하는 메인 화면 4 * @description id 입력하는 메인 화면
5 * 조회 / 업데이트 5 * 조회 / 업데이트
6 **/ 6 **/
7 -import state from "../../../state";
8 -import Title from "../../../components/title";
9 7
10 -const Home = (): string =>{ 8 +import Title from "@src/components/title";
11 - const onSubmit = (e : Event) => {
12 - e.preventDefault();
13 - alert('hi');
14 - }
15 9
16 - const literalTag = `<div class="home"> 10 +const Intro = (): string =>{
11 + return `<div class="home">
17 <lable> 12 <lable>
18 ${Title('인스타 조회하기').Large} 13 ${Title('인스타 조회하기').Large}
19 <input id="id-input" type="text" name="insta_id" /> 14 <input id="id-input" type="text" name="insta_id" />
20 - <button id="update-button">조회</button> 15 + <button id="search-button">조회</button>
21 </lable> 16 </lable>
22 </div>` 17 </div>`
23 -
24 - return literalTag;
25 } 18 }
26 19
27 -export default Home;
...\ No newline at end of file ...\ No newline at end of file
20 +export default Intro;
...\ No newline at end of file ...\ No newline at end of file
......
1 +export {default} from './Intro'
...\ No newline at end of file ...\ No newline at end of file
1 +/**
2 + * @author : wonseog
3 + * @date : 2021/03/10
4 + * @description : 로그인 이후 첫 화면
5 + * 업데이트하기
6 + * 다른 메뉴 보기
7 +**/
8 +
9 +const Main = () => {
10 + return `
11 + <div class="main">
12 + its main
13 + </div>
14 + `
15 +}
16 +
17 +export default Main
...\ No newline at end of file ...\ No newline at end of file
1 +export {default} from './Main'
...\ No newline at end of file ...\ No newline at end of file
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
4 * @description : 페이지 푸터 4 * @description : 페이지 푸터
5 **/ 5 **/
6 6
7 -import '../../assets/style/Footer.scss' 7 +import '@src/assets/style/Footer.scss'
8 8
9 const Footer = () : string => { 9 const Footer = () : string => {
10 10
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
4 * @description : 페이지 헤더 4 * @description : 페이지 헤더
5 **/ 5 **/
6 6
7 -import Title from "../../components/title"; 7 +import Title from "@src/components/title";
8 -import '../../assets/style/Header.scss' 8 +import '@src/assets/style/Header.scss'
9 9
10 const Header = () : string => ` 10 const Header = () : string => `
11 <div class="header"> 11 <div class="header">
......
...@@ -8,9 +8,16 @@ ...@@ -8,9 +8,16 @@
8 "module": "commonjs", 8 "module": "commonjs",
9 "strict": true, 9 "strict": true,
10 "removeComments": true, 10 "removeComments": true,
11 - "esModuleInterop": true 11 + "esModuleInterop": true,
12 + "baseUrl": ".",
13 + "paths": {
14 + "@src/*": [
15 + "src/*"
16 + ]
17 + }
12 }, 18 },
13 "include": [ 19 "include": [
14 "src/**/*.ts" 20 "src/**/*.ts"
15 ], 21 ],
22 + "exclude": ["node_modules"]
16 } 23 }
......
...@@ -30,6 +30,9 @@ module.exports = { ...@@ -30,6 +30,9 @@ module.exports = {
30 }, 30 },
31 resolve : { 31 resolve : {
32 extensions: [".tsx", ".ts", ".js"], 32 extensions: [".tsx", ".ts", ".js"],
33 + alias: {
34 + '@src': path.resolve(__dirname, 'src'),
35 + },
33 }, 36 },
34 output : { 37 output : {
35 publicPath: '/public/', 38 publicPath: '/public/',
......
...@@ -31,7 +31,20 @@ def update_data(user_insta_id, data): ...@@ -31,7 +31,20 @@ def update_data(user_insta_id, data):
31 def get_data_by_id(user_insta_id): 31 def get_data_by_id(user_insta_id):
32 insta_id = id_encrypt(user_insta_id) 32 insta_id = id_encrypt(user_insta_id)
33 33
34 - data = db.child("insta").child(insta_id).get() 34 + data = {};
35 - 35 + try:
36 - return data.val() 36 + data = db.child("insta").child(insta_id).get()
37 + except Exception as e:
38 + print(e)
39 + return {
40 + 'result' : 'no'
41 + }
42 + finally:
43 + if data:
44 + return data.val()
45 + else:
46 + return {
47 + 'followers': [],
48 + 'following': []
49 + }
37 50
......