1seok2

add Page loader

...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
9 import Header from "./views/header"; 9 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';
13 import {getState} from "@src/store/state"; 12 import {getState} from "@src/store/state";
13 +import './assets/style/App.scss';
14 14
15 const App = (pathname : string) : string => { 15 const App = (pathname : string) : string => {
16 /* id 없을 시 id 입력으로 redirect */ 16 /* id 없을 시 id 입력으로 redirect */
......
1 +.page-loader {
2 + position: fixed;
3 + left: 46%;
4 + top: 47%;
5 + display: none;
6 + width: 80px;
7 + height: 80px;
8 + z-index: -1;
9 +}
10 +.page-loader:after {
11 + content: " ";
12 + display: block;
13 + width: 64px;
14 + height: 64px;
15 + margin: 8px;
16 + border-radius: 50%;
17 + border: 12px solid #aaa;
18 + border-color: #a29bfe transparent #a29bfe transparent;
19 + transform: translate(-50%, -50%);
20 + animation: spin 1.2s both infinite;
21 +}
22 +
23 +/* Safari */
24 +@-webkit-keyframes spin {
25 + 0% { -webkit-transform: rotate(0deg); }
26 + 100% { -webkit-transform: rotate(360deg); }
27 +}
28 +
29 +@keyframes spin {
30 + 0% {
31 + transform: rotate(0deg);
32 + }
33 + 100% {
34 + transform: rotate(360deg);
35 + }
36 +}
...\ No newline at end of file ...\ No newline at end of file
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
51 top: 50%; 51 top: 50%;
52 transform: translate(-50%,-50%); 52 transform: translate(-50%,-50%);
53 background-color: #353535; 53 background-color: #353535;
54 - z-index: 1; 54 + z-index: 2;
55 display: none; 55 display: none;
56 56
57 &.transition-0 { 57 &.transition-0 {
......
...@@ -5,8 +5,9 @@ ...@@ -5,8 +5,9 @@
5 **/ 5 **/
6 6
7 import {BASE_URL} from "@src/config/url"; 7 import {BASE_URL} from "@src/config/url";
8 -import {randomTransition} from "@src/components/page.transition";
9 import {setState} from "@src/store/state"; 8 import {setState} from "@src/store/state";
9 +import {togglePageLoader} from "@src/components/page.loader";
10 +import {randomTransition} from "@src/components/page.transition";
10 11
11 export const addEvent = async ( 12 export const addEvent = async (
12 e : Event, 13 e : Event,
...@@ -28,6 +29,7 @@ export const addEvent = async ( ...@@ -28,6 +29,7 @@ export const addEvent = async (
28 else if((e.target as HTMLButtonElement).id === 'search-button') { 29 else if((e.target as HTMLButtonElement).id === 'search-button') {
29 let result: any= null; 30 let result: any= null;
30 const insta_id = (document.querySelector('#id-input') as HTMLInputElement).value; 31 const insta_id = (document.querySelector('#id-input') as HTMLInputElement).value;
32 + togglePageLoader(true);
31 33
32 if(insta_id){ 34 if(insta_id){
33 try{ 35 try{
...@@ -36,16 +38,23 @@ export const addEvent = async ( ...@@ -36,16 +38,23 @@ export const addEvent = async (
36 console.log(e); 38 console.log(e);
37 } finally { 39 } finally {
38 console.log('res!',result); 40 console.log('res!',result);
39 - result && $App && (()=>{ 41 + if(result){
40 - randomTransition(); 42 + $App && (()=>{
41 - setState(result); 43 + randomTransition();
42 - setTimeout(()=>{ 44 + setState(result);
43 - $App.innerHTML = App('main'); 45 + setTimeout(()=>{
44 - },1200) 46 + $App.innerHTML = App('main');
45 - })(); 47 + togglePageLoader(false);
48 + },1200)
49 + })();
50 + } else {
51 + togglePageLoader(false);
52 + alert('fail to search');
53 + }
46 } 54 }
47 } else { 55 } else {
48 alert('아이디를 입력하세요'); 56 alert('아이디를 입력하세요');
57 + togglePageLoader(false);
49 } 58 }
50 } 59 }
51 /* add POST event for button */ 60 /* add POST event for button */
......
1 +export const togglePageLoader = (type : boolean) : void => {
2 + const $loader : HTMLDivElement | null = document.querySelector('.page-loader');
3 + if($loader) {
4 + if(type) {
5 + $loader.style.display = 'block';
6 + $loader.style.zIndex = '1';
7 + } else {
8 + $loader.style.display = 'none';
9 + $loader.style.zIndex = '-1';
10 + }
11 + }
12 +}
...\ No newline at end of file ...\ No newline at end of file
...@@ -6,8 +6,9 @@ ...@@ -6,8 +6,9 @@
6 6
7 import App from './App'; 7 import App from './App';
8 import {initialTrantition} from "./components/page.transition"; 8 import {initialTrantition} from "./components/page.transition";
9 -import './assets/style/PageTransition.scss';
10 import {addEvent} from "@src/components/add.event"; 9 import {addEvent} from "@src/components/add.event";
10 +import './assets/style/PageTransition.scss';
11 +import './assets/style/PageLoader.scss';
11 12
12 window.addEventListener('DOMContentLoaded', () => { 13 window.addEventListener('DOMContentLoaded', () => {
13 /* add div for page transitions */ 14 /* add div for page transitions */
...@@ -19,6 +20,12 @@ window.addEventListener('DOMContentLoaded', () => { ...@@ -19,6 +20,12 @@ window.addEventListener('DOMContentLoaded', () => {
19 initialTrantition(); 20 initialTrantition();
20 })(); 21 })();
21 22
23 + (()=> {
24 + const $div = document.createElement('div');
25 + $div.className = "page-loader";
26 + document.body.appendChild($div);
27 + })();
28 +
22 const $App = document.querySelector('#App'); 29 const $App = document.querySelector('#App');
23 const pathname = window.location.pathname.split('/')[1]; 30 const pathname = window.location.pathname.split('/')[1];
24 31
......