1seok2

add scss loader & SPA animation

...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
26 "file-loader": "^6.2.0", 26 "file-loader": "^6.2.0",
27 "gts": "^3.1.0", 27 "gts": "^3.1.0",
28 "html-webpack-plugin": "^5.3.0", 28 "html-webpack-plugin": "^5.3.0",
29 + "node-sass": "^5.0.0",
30 + "sass-loader": "^11.0.1",
29 "style-loader": "^2.0.0", 31 "style-loader": "^2.0.0",
30 "ts-loader": "^8.0.17", 32 "ts-loader": "^8.0.17",
31 "typescript": "^4.0.3", 33 "typescript": "^4.0.3",
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
9 import Header from "./views/header/Header"; 9 import Header from "./views/header/Header";
10 import Body from "./views/body/Body"; 10 import Body from "./views/body/Body";
11 import Footer from "./views/footer/Footer"; 11 import Footer from "./views/footer/Footer";
12 +import './assets/style/App.scss';
13 +import './assets/style/PageTransition.scss';
12 14
13 const App = (pathname : string) : string => { 15 const App = (pathname : string) : string => {
14 history.pushState('','', pathname); 16 history.pushState('','', pathname);
......
1 body{ 1 body{
2 - background-color: beige; 2 + margin: 0;
3 + padding: 0;
3 } 4 }
...\ No newline at end of file ...\ No newline at end of file
......
1 +@keyframes page-initial-bottom {
2 + 0%{
3 + opacity: 1;
4 + background-color: white;
5 + }
6 + 100%{
7 + opacity: 0;
8 + background-color: white;
9 + }
10 +}
11 +
12 +@keyframes page-blink-bottom {
13 + 0%{
14 + opacity: 0;
15 + top: 50%;
16 + left: 50%
17 + }
18 + 40%{
19 + opacity: 1;
20 + left: 50%;
21 + }
22 + 50%{
23 + left: 50%;
24 + }
25 + 100%{
26 + opacity: 1;
27 + left: -70%;
28 + }
29 +}
30 +
31 +@keyframes page-top-left {
32 + 0%{
33 + left: 50%;
34 + top: 170%;
35 + }
36 + 50%{
37 + top: 50%;
38 + left: 50%;
39 + }
40 + 100%{
41 + top: 50%;
42 + left: -70%;
43 + }
44 +}
45 +
46 +.page-transition {
47 + width : 120%;
48 + height: 120%;
49 + position: fixed;
50 + left: 50%;
51 + top: 50%;
52 + transform: translate(-50%,-50%);
53 + background-color: #353535;
54 + z-index: 1;
55 + display: none;
56 +
57 + &.transition-0 {
58 + animation: ease-in-out 1.2s page-initial-bottom;
59 + }
60 +
61 + &.transition-1 {
62 + animation: ease-in-out 2.4s page-blink-bottom;
63 + }
64 +
65 + &.transition-2 {
66 + animation: ease-in-out 2.4s page-top-left;
67 + }
68 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/**
2 + * @author : wonseog
3 + * @date : 2021/03/09
4 + * @description : 페이지 이동 효과 주는 함수
5 +**/
6 +
7 +let $div : HTMLDivElement | null;
8 +
9 +const pageTransitionClassList = [
10 + "transition-0",
11 + "transition-1",
12 + "transition-2"
13 +]
14 +
15 +const getDivs = () : HTMLDivElement | null => document.querySelector('.page-transition');
16 +
17 +const turnOnAndOff = (idx : number)=>{
18 + $div && (()=>{
19 + $div.classList.toggle(pageTransitionClassList[idx]);
20 + $div.style.display = 'block';
21 +
22 + setTimeout(()=>{
23 + $div && (()=>{
24 + $div.style.display = 'none';
25 + $div.classList.toggle(pageTransitionClassList[idx]);
26 + })()
27 + },idx === 0 ? 1000 : 2400);
28 + })()
29 +}
30 +
31 +export const initialTrantition = () => {
32 + $div = $div || getDivs();
33 + $div && turnOnAndOff(0);
34 +}
35 +
36 +export const randomTransition = () => {
37 + $div = $div || getDivs();
38 + const randomIndex = Math.floor(Math.random()*(pageTransitionClassList.length - 1) + 1);
39 +
40 + $div && turnOnAndOff(randomIndex);
41 +}
...\ No newline at end of file ...\ No newline at end of file
1 -export const BASE_URL = 'http://localhost:5000/'; 1 +export const BASE_URL = 'http://localhost:8080/';
......
...@@ -3,20 +3,46 @@ ...@@ -3,20 +3,46 @@
3 * @date : 2021/03/08 3 * @date : 2021/03/08
4 * @description : 현재 pathname을 파악 후 App으로 전달 4 * @description : 현재 pathname을 파악 후 App으로 전달
5 **/ 5 **/
6 +
6 import App from './App'; 7 import App from './App';
7 import {BASE_URL} from './config/url'; 8 import {BASE_URL} from './config/url';
9 +import {initialTrantition, randomTransition} from "./components/pageTransition";
8 10
9 window.addEventListener('DOMContentLoaded', () => { 11 window.addEventListener('DOMContentLoaded', () => {
12 + /* add div for page transitions */
13 + (()=> {
14 + const $div = document.createElement('div');
15 + $div.className = "page-transition";
16 + document.body.appendChild($div);
17 +
18 + initialTrantition();
19 + })();
20 +
10 const $App = document.querySelector('#App'); 21 const $App = document.querySelector('#App');
11 const pathname = window.location.pathname.split('/')[1]; 22 const pathname = window.location.pathname.split('/')[1];
12 23
24 + /* change url */
25 + window.addEventListener('popstate', ()=>{
26 + $App && ($App.innerHTML = App(pathname))
27 + });
28 +
29 + /* initial render */
30 + $App && ($App.innerHTML = App(pathname));
31 +
13 document.body.addEventListener('click', async (e) => { 32 document.body.addEventListener('click', async (e) => {
14 e.stopPropagation(); 33 e.stopPropagation();
34 +
35 + /* add navigation click event */
15 if((e.target as HTMLAnchorElement).matches("[data-link]")){ 36 if((e.target as HTMLAnchorElement).matches("[data-link]")){
16 - const href = (e.target as HTMLAnchorElement).href.split(BASE_URL)[1]; 37 + const href : string= (e.target as HTMLAnchorElement).href.split(BASE_URL)[1];
17 e.preventDefault(); 38 e.preventDefault();
18 - $App && ($App.innerHTML = App(href)); 39 + setTimeout(()=>{
19 - } else if((e.target as HTMLAnchorElement).id === 'update-button') { 40 + $App && ($App.innerHTML = App(href));
41 + },1200);
42 + randomTransition();
43 + }
44 + /* add POST event for button */
45 + else if((e.target as HTMLAnchorElement).id === 'update-button') {
20 let result: any= null; 46 let result: any= null;
21 const insta_id = (document.querySelector('#id-input') as HTMLInputElement).value; 47 const insta_id = (document.querySelector('#id-input') as HTMLInputElement).value;
22 48
...@@ -32,10 +58,4 @@ window.addEventListener('DOMContentLoaded', () => { ...@@ -32,10 +58,4 @@ window.addEventListener('DOMContentLoaded', () => {
32 } 58 }
33 } 59 }
34 }); 60 });
35 -
36 - window.addEventListener('popstate', ()=>{
37 - $App && ($App.innerHTML = App(pathname))
38 - });
39 -
40 - $App && ($App.innerHTML = App(pathname));
41 }) 61 })
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -15,8 +15,8 @@ module.exports = { ...@@ -15,8 +15,8 @@ module.exports = {
15 exclude: /node_modules/, 15 exclude: /node_modules/,
16 }, 16 },
17 { 17 {
18 - test : /\.css$/, 18 + test : /\.scss$/,
19 - use: ['style-loader', 'css-loader'], 19 + use: ['style-loader', 'css-loader', 'sass-loader'],
20 }, 20 },
21 { 21 {
22 test: /\.(png|jpe?g|gif|jp2|webp)$/, 22 test: /\.(png|jpe?g|gif|jp2|webp)$/,
......
...@@ -2,9 +2,6 @@ import os ...@@ -2,9 +2,6 @@ import os
2 from flask import Flask, render_template, request, jsonify, send_from_directory 2 from flask import Flask, render_template, request, jsonify, send_from_directory
3 from crawler.crawler_instagram import crawler_instagram 3 from crawler.crawler_instagram import crawler_instagram
4 4
5 -# my_path = '/Users/choewonseog/Documents/check-your-instagram/app/public'
6 -# my_path = 'C:/Users/goesnow/Documents/study/check-your-instagram/app/public'
7 -
8 root_dir = os.path.dirname(os.getcwd()) 5 root_dir = os.path.dirname(os.getcwd())
9 my_path = os.path.join(root_dir, 'check-your-instagram', 'app', 'public') 6 my_path = os.path.join(root_dir, 'check-your-instagram', 'app', 'public')
10 app = Flask(__name__, static_folder=os.path.abspath(my_path)) 7 app = Flask(__name__, static_folder=os.path.abspath(my_path))
...@@ -39,4 +36,4 @@ if __name__ == "__main__": ...@@ -39,4 +36,4 @@ if __name__ == "__main__":
39 print(" server is start") 36 print(" server is start")
40 print("-" * 60) 37 print("-" * 60)
41 38
42 - app.run(debug=True) 39 + app.run(host="localhost", port=8080, debug=True)
......