Skip to content

Commit

Permalink
Refactor: 로딩 화면 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
nightowlzz committed May 19, 2024
1 parent 73d070d commit 87bd07a
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 22 deletions.
27 changes: 7 additions & 20 deletions components/loading/Loading.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,17 @@
import { memo } from 'react';
import styled from './loading.module.css';
import Image from 'next/image';
import styled from 'styled-components';

const LoadingWrap = styled.div`
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
display: flex;
align-items: center;
justify-content: center;
background-color: rgba(0, 0, 0, 0.7);
z-index: 10;
img {
width: 150px;
}
`;

function Loading() {
return (
<LoadingWrap>
<div className={styled.loadingWrap}>
<Image
src='/assets/icon/icon_loading.svg'
alt='loading'
width={100}
height={100}
/>
</LoadingWrap>
</div>
);
}
export default Loading;
export default memo(Loading);
16 changes: 16 additions & 0 deletions components/loading/loading.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.loadingWrap {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
display: flex;
align-items: center;
justify-content: center;
background-color: rgba(0, 0, 0, 0.7);
z-index: 10;
}

.loadingWrap img {
width: 150px;
}
7 changes: 5 additions & 2 deletions pages/folder/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import FolderContentControll from '@/components/folder/FolderContentControll';
import PostCardList from '@/components/folder/PostCardList';
import Modal from '@/components/modal/Modal';
import Loading from '@/components/loading/Loading';
import { BodyInner, BookmarkBox, FolderContainHead } from '../../styles/folderStyle';
import { BodyInner, BookmarkBox, EmptyBox, FolderContainHead } from '../../styles/folderStyle';
import { IFolderContentApi, IFolderMenuButtonApi } from '../../components/folder/interface';
import { instance } from '@/lib/axios';

Expand Down Expand Up @@ -52,6 +52,7 @@ export default function Folder({ $menu, $content }: { $menu: IFolderMenuButtonAp
const [isModalShow, setIsModalShow] = useState(false);
const [modalType, setModalType] = useState<string>('');
const [searchContatn, setSearchContent] = useState<any>();
const [isStylesLoaded, setIsStylesLoaded] = useState(false);

// 폴더리스트버튼
const handleClick = (id: number) => {
Expand Down Expand Up @@ -115,9 +116,11 @@ export default function Folder({ $menu, $content }: { $menu: IFolderMenuButtonAp
alert('페이지가 없습니다.');
router.push(`/folder`);
}

setIsStylesLoaded(true);
}, [$menu, router]);

if (!$menu || !$content) return <Loading />;
if (!isStylesLoaded) return <Loading />;

return (
<Container>
Expand Down
10 changes: 10 additions & 0 deletions pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import { Container, TitleLs, TitleMs } from '@/styles/commonStyle';
import { Section } from '../styles/mainStyle';
import LinkButton from '@/components/common/atoms/LinkButton';
import { useEffect, useState } from 'react';
import Loading from '@/components/loading/Loading';

export default function Home() {
const [isStylesLoaded, setIsStylesLoaded] = useState(false);

useEffect(() => {
setIsStylesLoaded(true);
}, []);

if (!isStylesLoaded) return <Loading />;

return (
<Container className='body__main'>
<Section className='section__banner'>
Expand Down
1 change: 1 addition & 0 deletions pages/shared/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export default function Shared({ $title, $content }: { $title: IShareTitle; $con
const contentSearch = searchContatn ?? $content?.data;

if (!$title.data[0]) router.push('/notfound');

return (
<Container>
<ContainHead>
Expand Down
7 changes: 7 additions & 0 deletions pages/signin/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { GetServerSidePropsContext } from 'next';
import { useRouter } from 'next/router';
import { useForm } from 'react-hook-form';
import Image from 'next/image';
import Loading from '@/components/loading/Loading';

const BASE_PAGE_URL = '/';
const SIGNIN_PAGE_URL = '/signin';
Expand Down Expand Up @@ -61,6 +62,8 @@ export default function SignIn() {
const router = useRouter();
const { handleLogin } = useContext(AuthContext);
const [IsVisibility, setIsVisibility] = useState(false);
const [isStylesLoaded, setIsStylesLoaded] = useState(false);

const {
register,
handleSubmit,
Expand Down Expand Up @@ -93,7 +96,11 @@ export default function SignIn() {
alert('로그인한 상태입니다.');
router.push('/folder');
}
setIsStylesLoaded(true);
}, [router]);

if (!isStylesLoaded) return <Loading />;

return (
<JoinWrap className='no-header--container signin__wrap'>
<JoinBody>
Expand Down
6 changes: 6 additions & 0 deletions pages/signup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useRouter } from 'next/router';
import { IJoinForm } from '@/components/join/interfase';
import { GetServerSidePropsContext } from 'next';
import Image from 'next/image';
import Loading from '@/components/loading/Loading';

const BASE_PAGE_URL = '/';
const SIGNUP_PAGE_URL = '/signup';
Expand Down Expand Up @@ -65,6 +66,7 @@ export default function SignUp() {
setError,
setValue,
} = useForm<IJoinForm>({ mode: 'onBlur' });
const [isStylesLoaded, setIsStylesLoaded] = useState(false);

const handleEmailCheck = async (email: IJoinForm['email']) => {
try {
Expand Down Expand Up @@ -96,7 +98,11 @@ export default function SignUp() {
alert('로그인한 상태입니다.');
router.push('/folder');
}
setIsStylesLoaded(true);
}, [router]);

if (!isStylesLoaded) return <Loading />;

return (
<JoinWrap className='no-header--container signup__wrap'>
<JoinBody>
Expand Down

0 comments on commit 87bd07a

Please sign in to comment.