Skip to content

Commit

Permalink
feat: 카카오 인앱프라우저로 접속시 다른 브라우저로 열기 안내 토스트 구현 (#120)
Browse files Browse the repository at this point in the history
방만들기와, 초대하기에서 토스트
  • Loading branch information
cheonjiyun authored Sep 7, 2024
1 parent f94e834 commit 0a37e5a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Game from './pages/Game';
import InputCode from './pages/InputCode';
import InputName from './pages/InputName';
import NotFound from './pages/NotFound';
import CheckInAppBrowser from './routers/CheckInAppBrowser';

interface RouteElement {
path: string;
Expand All @@ -22,11 +23,19 @@ const routes: RouteElement[] = [
},
{
path: 'create',
element: <CreateRoom />,
element: (
<CheckInAppBrowser>
<CreateRoom />
</CheckInAppBrowser>
),
},
{
path: '/participate',
element: <InputCode />,
element: (
<CheckInAppBrowser>
<InputCode />
</CheckInAppBrowser>
),
},
{
path: '/name',
Expand Down
18 changes: 17 additions & 1 deletion src/components/toast/NotifyToast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import toast from 'react-hot-toast';

import { VariablesCSS } from '../../styles/VariablesCSS';

export const notifyUseToast = (message: string, whereUse: 'LOBBY' | 'INVITE') => {
export const notifyUseToast = (message: string, whereUse: 'LOBBY' | 'INVITE' | 'WARNING') => {
if (whereUse === 'LOBBY') {
return toast(message, {
duration: 3000,
Expand All @@ -16,6 +16,22 @@ export const notifyUseToast = (message: string, whereUse: 'LOBBY' | 'INVITE') =>
},
});
}
if (whereUse === 'WARNING') {
return toast(message, {
duration: 8000,
position: 'bottom-center',
style: {
marginBottom: '50%',
textAlign: 'center',
color: VariablesCSS.night,
background: 'linear-gradient(118.95deg, #dfcfeb 0%, #c9abca 100%)',
border: '3px solid #ffffff',
borderRadius: '15px',
fontFamily: 'KCC-Hanbit',
},
});
}

return toast(message, {
duration: 3000,
position: 'bottom-center',
Expand Down
Empty file added src/hooks/useInAppBrowser
Empty file.
26 changes: 26 additions & 0 deletions src/routers/CheckInAppBrowser.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { useEffect } from 'react';
import { Toaster } from 'react-hot-toast';

import { notifyUseToast } from '../components/toast/NotifyToast';

interface propsType {
children: React.ReactNode;
}

export default function CheckInAppBrowser({ children }: propsType) {
useEffect(() => {
if (navigator.userAgent.indexOf('KAKAOTALK') >= 0) {
notifyUseToast(
'카카오톡안에서 튕기면 재접속할 수 없습니다.\n\n⋮ 을 눌러 다른 브라우저로 열어주세요.',
'WARNING',
);
}
}, []);

return (
<>
<Toaster />
{children}
</>
);
}

0 comments on commit 0a37e5a

Please sign in to comment.