Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

๐Ÿ› ๏ธ ํ”ผ๋“œ ๋ฉ”์ธ ํŽ˜์ด์ง€ ํ”ผ๋“œ๋ฐฑ ๋ฐ˜์˜ #38

Merged
merged 7 commits into from
May 7, 2024
6 changes: 4 additions & 2 deletions src/app/mocks/handler/feed.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { http } from 'msw';
import { delay, http } from 'msw';

import { feeds } from '../consts/feed';
import { reports } from '../consts/report';
Expand Down Expand Up @@ -28,7 +28,7 @@ export const feedHandlers = [
/**
* @todo pageCount๋ฅผ ์ฟผ๋ฆฌ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ๋ฐ›๋„๋ก ์ˆ˜์ •
*/
http.get('/feeds', ({ request }) => {
http.get('/feeds', async ({ request }) => {
const url = new URL(request.url);
const page = url.searchParams.get('page') || 1;

Expand All @@ -47,6 +47,8 @@ export const feedHandlers = [
const endOfPageRange = formattedPage * pageCount;
const hasNextPage = endOfPageRange < totalFeeds;

await delay(Math.floor(Math.random() * (4000 - 2000 + 1)) + 2000);

return createHttpSuccessResponse({
feeds: feedsData,
currentPageNumber: pageCount,
Expand Down
1 change: 1 addition & 0 deletions src/app/providers/query-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const queryClientOptions: QueryClientConfig = {
staleTime: 10 * 60 * 1000, // 10 minutes
gcTime: 15 * 60 * 1000, // 15 minutes
refetchOnWindowFocus: false,
retry: false,
},
},
};
Expand Down
3 changes: 3 additions & 0 deletions src/pages/feed-main/ui/FeedMainPage.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.feed-main-page {
margin-bottom: 24px;
}
1 change: 1 addition & 0 deletions src/pages/feed-main/ui/FeedMainPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { FeedMainHeader, FeedMainList } from '@/widgets';
import './FeedMainPage.scss';

export const FeedMainPage = () => {
return (
Expand Down
2 changes: 1 addition & 1 deletion src/shared/axios/config/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { onError, onRequest, onResponse } from './interceptors';

export const axiosInstance = axios.create({
baseURL: '',
timeout: 5000,
timeout: 3000,
headers: {
'Content-Type': 'application/json; charset=utf-8',
},
Expand Down
82 changes: 21 additions & 61 deletions src/shared/ui/network-toast-error/NetworkToastError.scss
Original file line number Diff line number Diff line change
@@ -1,75 +1,35 @@
@keyframes bounceInUp {
from,
60%,
75%,
90%,
to {
animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
}
from {
opacity: 0;
transform: translate3d(0, 100%, 0);
}
60% {
opacity: 1;
transform: translate3d(0, -20px, 0);
}
75% {
transform: translate3d(0, 10px, 0);
}
90% {
transform: translate3d(0, -5px, 0);
}
to {
transform: translate3d(0, 0, 0);
}
}
.Toastify__toast-container {
width: 100%;
margin-bottom: 8px;

.Toastify {
position: fixed;
bottom: 8px;
left: 0;
right: 0;
.Toastify__toast {
font-family: unset;

width: 280px;
height: 40px;
margin: 0 auto;
margin: 0 auto;
width: 280px;
height: 40px;

.network-error-toast {
animation: bounceInUp 0.75s cubic-bezier(0.68, -0.55, 0.27, 1.55) both;
min-height: 40px;
max-height: 40px;

width: 100%;
height: 100%;
border-radius: 6px;

display: flex;
align-items: center;

color: #ffffff;
background: #98a3b4e5;
color: #ffffff;
padding: 0;

.Toastify__toast--default {
color: #ffffff;

width: 100%;

.Toastify__toast-body {
display: flex;
align-items: center;

gap: 6px;

.Toastify__toast-icon {
width: 20px;
height: 20px;
.Toastify__toast-body {
height: 40px;
padding: 0 0 0 12px;

margin-left: 12px;
}
.Toastify__toast-icon {
margin-inline-end: 6px;
}
}

.Toastify__close-button {
display: none;
}
.Toastify__close-button,
.Toastify__progress-bar--wrp {
display: none;
}
}
}
29 changes: 27 additions & 2 deletions src/shared/ui/network-toast-error/NetworkToastError.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,34 @@
import { ToastContainer } from 'react-toastify';
import { useEffect, useRef } from 'react';
import { ToastContainer, toast } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';

import './NetworkToastError.scss';
import { Icon } from '..';

export const NetworkToastError = () => {
interface NetworkToastErrorProps {
isVisible: boolean;
errorMessage: string;
}

export const NetworkToastError: React.FC<NetworkToastErrorProps> = ({
isVisible,
errorMessage,
}) => {
const toastId = useRef<number | string>(-1);

useEffect(() => {
if (isVisible && toastId.current === -1) {
toastId.current = toast(errorMessage);
return;
}

if (!isVisible && toastId.current !== -1) {
toast.dismiss(toastId.current);
toastId.current = -1;
return;
}
}, [isVisible, errorMessage]);

return (
<ToastContainer
className='network-error-toast b1semi'
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/feed-main-list/ui/FeedMainList.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.feed-list-section {
.feed-list {
padding: 16px 0 24px;
margin-top: 16px;
}

.feed-wrapper:not(:last-child)::after {
Expand Down
14 changes: 6 additions & 8 deletions src/widgets/feed-main-list/ui/FeedMainList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import InfiniteScroll from 'react-infinite-scroller';
import { toast } from 'react-toastify';

import { NetworkError, NetworkToastError } from '@/shared/ui';

Expand All @@ -21,19 +20,14 @@ export const FeedMainList = () => {
} = useInfinityFeeds();

if (isLoading) {
return <SkeletonFeedMainList />;
return <SkeletonFeedMainList count={10} />;
}

if (isError && !feeds) {
// ์ดˆ๊ธฐ ๋กœ๋”ฉ์—์„œ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•  ๊ฒฝ์šฐ
return <NetworkError refetch={refetchFeeds} />;
}

if (isError && feeds) {
// ๋ฌดํ•œ ์Šคํฌ๋กค ๋„์ค‘ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•  ๊ฒฝ์šฐ
toast('์ธํ„ฐ๋„ท ์—ฐ๊ฒฐ์ด ๋ถˆ์•ˆ์ •ํ•ด์š”');
}

return (
<section className='feed-list-section'>
<InfiniteScroll
Expand All @@ -48,8 +42,12 @@ export const FeedMainList = () => {
<Feed key={feed.id} feed={feed} />
));
})}
{isFetching && <SkeletonFeedMainList count={3} />}
</InfiniteScroll>
<NetworkToastError />
<NetworkToastError
isVisible={isError && !!feeds}
errorMessage='์ธํ„ฐ๋„ท ์—ฐ๊ฒฐ์ด ๋ถˆ์•ˆ์ •ํ•ด์š”'
/>
</section>
);
};
6 changes: 1 addition & 5 deletions src/widgets/feed-main-list/ui/SkeletonFeedMainList.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
.skeleton-feed-section {
width: 320px;
height: 508px;
margin: 16px 0 24px;

overflow: hidden;
margin-top: 16px;

.skeleton-feed-wrapper:not(:last-child)::after {
content: '';
Expand Down
6 changes: 4 additions & 2 deletions src/widgets/feed-main-list/ui/SkeletonFeedMainList.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { SkeletonFeed } from './SkeletonFeed';
import './SkeletonFeedMainList.scss';

export const SkeletonFeedMainList = () => {
export const SkeletonFeedMainList: React.FC<{ count: number }> = ({
count,
}) => {
return (
<section className='skeleton-feed-section'>
{new Array(5).fill(1).map((_, i) => (
{new Array(count).fill(1).map((_, i) => (
<SkeletonFeed key={i} />
))}
</section>
Expand Down
Loading