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

[# 309] 웹에서의 알림 기능 제거 #310

Merged
merged 1 commit into from
Oct 8, 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
8 changes: 5 additions & 3 deletions src/hooks/useNotification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import CTAButton from '@/components/common/CTAButton';
import { useDeleteDeviceToken } from '@/queries/useDeleteDeviceToken.ts';

const DEVICE_TOKEN_KEY = 'deviceToken';
const DEVICE_TOKEN_DENIED_VALUE = 'denied';
const DEVICE_TOKEN_DENIED = 'denied';
const DEVICE_TOKEN_REQUESTED = 'requested';

export const useNotification = () => {
const { mutate: createDeviceToken } = useCreateDeviceToken();
Expand Down Expand Up @@ -52,6 +53,7 @@ export const useNotification = () => {
const permission = await Notification.requestPermission();

if (permission === 'granted') {
localStorage.setItem(DEVICE_TOKEN_KEY, DEVICE_TOKEN_REQUESTED);
const token = await getToken(messaging, {
vapidKey: import.meta.env.VITE_VAPID_KEY,
});
Expand All @@ -62,11 +64,11 @@ export const useNotification = () => {
return;
}

localStorage.setItem(DEVICE_TOKEN_KEY, DEVICE_TOKEN_DENIED_VALUE);
localStorage.setItem(DEVICE_TOKEN_KEY, DEVICE_TOKEN_DENIED);
}, []);

const denyPermission = useCallback(() => {
localStorage.setItem(DEVICE_TOKEN_KEY, DEVICE_TOKEN_DENIED_VALUE);
localStorage.setItem(DEVICE_TOKEN_KEY, DEVICE_TOKEN_DENIED);
deleteDeviceToken(undefined);
}, []);

Expand Down
7 changes: 0 additions & 7 deletions src/pages/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ import { useToken } from '@/hooks/useToken.ts';
import { SECOND } from '@/constants/day.ts';
import { useQueryClient } from '@tanstack/react-query';
import { keyStore } from '@/queries/keyStore.ts';
import { useNotification } from '@/hooks/useNotification.tsx';

const Main = () => {
const { data: homeData } = useGetHomeData();
const { mutate: refreshAccessToken } = useRefreshAccessToken();
const { getRefreshToken, isValidToken, setRefreshToken, setAccessToken, getAccessToken } =
useToken();
const { RequestPermissionModal, isPermissionChecked, openPermissionModal } = useNotification();

const queryClient = useQueryClient();

Expand Down Expand Up @@ -48,10 +46,6 @@ const Main = () => {
useEffect(() => {
if (window.ReactNativeWebView) {
window?.ReactNativeWebView?.postMessage?.(getAccessToken());
} else {
if (!isPermissionChecked) {
openPermissionModal();
}
}
}, []);

Expand All @@ -71,7 +65,6 @@ const Main = () => {
<BloomingWeather register={register} />
<HeightBox height={100} />
<TabBar />
<RequestPermissionModal />
</Screen>
);
};
Expand Down
Loading