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

⚡ 공용 컴포넌트 리팩토링 #64

Merged
merged 8 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
import { RouterProvider } from 'react-router-dom';

import { queryClient } from '@/shared/react-query';
import { NetworkErrorToast } from '@/shared/ui';
import { Toast } from '@/shared/toast';

import { router } from './routers/index';
import './styles/global.scss';
Expand All @@ -13,7 +13,7 @@ function App() {
<QueryClientProvider client={queryClient}>
<RouterProvider router={router} />

<NetworkErrorToast />
<Toast />
<ReactQueryDevtools />
</QueryClientProvider>
);
Expand Down
4 changes: 2 additions & 2 deletions src/app/layout/iPhone/hooks/useUtilityIPhone.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useRef } from 'react';

const IPHONE_MIN_SIZE = 60;
const IPHONE_INIT_SIZE = 80;
const IPHONE_MIN_SIZE = 75;
const IPHONE_INIT_SIZE = 75;
const IPHONE_MAX_SIZE = 100;

const IPHONE_PROTRAIT_MODE = 0; // 세로 모드
Expand Down
2 changes: 1 addition & 1 deletion src/app/layout/iPhone/ui/IPhoneLayout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
display: none;
}

@media (min-width: 1440px) {
@media (min-width: 1080px) {
.root-layout {
width: 100vw;
height: 100vh;
Expand Down
7 changes: 4 additions & 3 deletions src/shared/react-query/dir/handleQuery.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Query, QueryKey } from '@tanstack/react-query';

import { removeErrorHandler, showErrorHandler } from './toastHandlers';
import { removeToastHandler, showToastHandler } from '@/shared/toast';

/**
* 쿼리 성공 핸들러
*/
export function handleQuerySuccess() {
removeErrorHandler();
removeToastHandler();
}

/**
Expand All @@ -20,7 +20,8 @@ export function handleQueryError(
const { queryKey, state } = query;

// feeds 쿼리에서 2 페이지부터 에러가 발생하면 네트워크 에러 토스트를 띄웁니다.
if (queryKey[0] === 'feeds' && state.data) showErrorHandler();
if (queryKey[0] === 'feeds' && state.data)
showToastHandler('caution', '인터넷 연결이 불안정해요');
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/shared/react-query/dir/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './handleQuery';
export * from './toastHandlers';
27 changes: 0 additions & 27 deletions src/shared/react-query/dir/toastHandlers.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/shared/toast/dir/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './toastHandlers';
33 changes: 33 additions & 0 deletions src/shared/toast/dir/toastHandlers.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Bounce, toast } from 'react-toastify';

import { Icon } from '@/shared/ui';
import { IconName } from '@/shared/ui/icon';

const id = 'react-query-toast';

/**
* reference: https://fkhadra.github.io/react-toastify/api/toast
* 메시지를 토스트 메시지로 변환합니다.
* @param iconName 아이콘 이름
* @param message 메시지
*/
export function showToastHandler(iconName: IconName, message: string) {
BangDori marked this conversation as resolved.
Show resolved Hide resolved
if (!toast.isActive(id)) {
toast(message, {
toastId: id,
autoClose: 3000,
position: 'bottom-center',
transition: Bounce,
icon: <Icon name={iconName} width='20' height='20' />,
});
}
}

/**
* 화면에 표시되어 있는 토스트를 제거합니다.
*/
export function removeToastHandler() {
if (toast.isActive(id)) {
toast.dismiss(id);
}
}
2 changes: 2 additions & 0 deletions src/shared/toast/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { Toast } from './ui';
export * from './dir';
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { ToastContainer } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';

import './NetworkErrorToast.scss';
import { Icon } from '..';
import './Toast.scss';

export const NetworkErrorToast = () => {
export const Toast = () => {
return (
<ToastContainer
className='network-error-toast b1semi'
icon={<Icon name='caution' width='20' height='20' />}
limit={1}
pauseOnHover={false}
pauseOnFocusLoss={false}
Expand Down
1 change: 1 addition & 0 deletions src/shared/toast/ui/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Toast } from './Toast';
1 change: 1 addition & 0 deletions src/shared/ui/icon/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { Icon } from './ui';
export type { IconName } from './consts';
2 changes: 0 additions & 2 deletions src/shared/ui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@ export { ConfirmModal, BottomSheetModal } from './modal';
export { Profile, SkeletonProfile } from './profile';
export { Icon } from './icon';
export { NetworkError } from './network-error';
export { NetworkErrorToast } from './network-error-toast';
export { Observer } from './observer';
export { Carousel } from './carousel';
1 change: 0 additions & 1 deletion src/shared/ui/network-error-toast/index.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/widgets/feed-carousel/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Carousel } from './ui';
File renamed without changes.
3 changes: 2 additions & 1 deletion src/widgets/feed-main-list/ui/Feed.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { BookmarkButton } from '@/features/feed-bookmark';
import { LikeButton } from '@/features/feed-main-like';
import { Feed as FeedProps } from '@/shared/consts';
import { Carousel, Icon, Profile } from '@/shared/ui';
import { Icon, Profile } from '@/shared/ui';
import { calculateElapsedTime } from '@/shared/utils';
import { Carousel } from '@/widgets/feed-carousel';
import { FeedKebabButton } from '@/widgets/feed-kebab';

import './Feed.scss';
Expand Down
Loading