diff --git a/src/config/webview.ts b/src/config/webview.ts index 389f709..0f9f680 100644 --- a/src/config/webview.ts +++ b/src/config/webview.ts @@ -5,6 +5,7 @@ export const MESSAGE_TYPES = { AUTH_ERROR: 'AUTH_ERROR', TOKEN: 'TOKEN', NEED_REGISTER: 'NEED_REGISTER', + REQUEST_NOTIFICATION_PERMISSION: 'REQUEST_NOTIFICATION_PERMISSION', } as const; export type MessageType = (typeof MESSAGE_TYPES)[keyof typeof MESSAGE_TYPES]; diff --git a/src/layout/SearchHeader/SearchHeader.tsx b/src/layout/SearchHeader/SearchHeader.tsx index 2fcae56..36de67c 100644 --- a/src/layout/SearchHeader/SearchHeader.tsx +++ b/src/layout/SearchHeader/SearchHeader.tsx @@ -1,5 +1,7 @@ +import { MESSAGE_TYPES } from '../../config/webview'; import { useNavigate } from 'react-router-dom'; import useAuthInfo from '@hooks/useAuthInfo'; +import useLocalStorageState from '@hooks/useLocalStorageState'; import useToast from '@hooks/useToast'; import ConfirmModal from '@components/Modal/Confirm/ConfirmModal'; import Toast from '@components/Toast/Toast'; @@ -29,16 +31,31 @@ const SearchHeader = ({ stockInfo }: { stockInfo: StockDetailInfo }) => { const { mutate: toggleNotification } = useToggleNotificationMutation(); const isBookmark = stockPreference?.isBookmarked ?? false; const isNotification = stockPreference?.isNotificationEnabled ?? false; + const [accessToken] = useLocalStorageState('access_token'); - const onHeartClick = () => { - if (!stockInfo) return; + const checkAndRequestNotificationPermission = async () => { + const isWebView = !!(window as any).ReactNativeWebView; + if (isWebView) { + (window as any).ReactNativeWebView.postMessage( + JSON.stringify({ + type: MESSAGE_TYPES.REQUEST_NOTIFICATION_PERMISSION, + token: accessToken, + }), + ); + } + }; + const onHeartClick = async () => { + if (!stockInfo) return; if (!isLogin) { openLoginModal(); return; } if (!isBookmark) { + // 관심 등록 시 알림 권한 체크 및 요청 + await checkAndRequestNotificationPermission(); + showToast( <> @@ -51,7 +68,7 @@ const SearchHeader = ({ stockInfo }: { stockInfo: StockDetailInfo }) => { } }; - const onBellClick = () => { + const onBellClick = async () => { if (!stockInfo) return; if (!isLogin) { @@ -67,6 +84,7 @@ const SearchHeader = ({ stockInfo }: { stockInfo: StockDetailInfo }) => { , ); } else { + await checkAndRequestNotificationPermission(); showToast( <>