Skip to content
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
1 change: 1 addition & 0 deletions src/config/webview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
24 changes: 21 additions & 3 deletions src/layout/SearchHeader/SearchHeader.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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<string>('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(
<>
<ToastHeartSVG />
Expand All @@ -51,7 +68,7 @@ const SearchHeader = ({ stockInfo }: { stockInfo: StockDetailInfo }) => {
}
};

const onBellClick = () => {
const onBellClick = async () => {
if (!stockInfo) return;

if (!isLogin) {
Expand All @@ -67,6 +84,7 @@ const SearchHeader = ({ stockInfo }: { stockInfo: StockDetailInfo }) => {
</>,
);
} else {
await checkAndRequestNotificationPermission();
showToast(
<>
<ToastBellSVG />
Expand Down
Loading