Skip to content

Commit

Permalink
Merge pull request #277 from dnd-side-project/fix-276
Browse files Browse the repository at this point in the history
[# 276] pwa 기능 제거 및 expo로 푸시 알림 기능 수정
  • Loading branch information
gihwan-dev authored Oct 2, 2024
2 parents e972ec6 + 27eae06 commit f719870
Show file tree
Hide file tree
Showing 8 changed files with 263 additions and 321 deletions.
1 change: 0 additions & 1 deletion .storybook/preview-head.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<link as="style" crossorigin href="https://cdn.jsdelivr.net/gh/orioncactus/[email protected]/dist/web/static/pretendard.min.css" rel="stylesheet" />

<script>
console.log("font loaded");
</script>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"clsx": "^2.1.1",
"embla-carousel-react": "^8.1.8",
"es-toolkit": "^1.16.0",
"firebase": "^10.13.0",
"firebase": "^10.14.0",
"framer-motion": "^11.9.0",
"jotai": "^2.9.3",
"lucide-react": "^0.417.0",
Expand Down
469 changes: 238 additions & 231 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

37 changes: 0 additions & 37 deletions public/firebase-messaging-sw.js

This file was deleted.

24 changes: 0 additions & 24 deletions public/messaging_receive_message.js

This file was deleted.

26 changes: 8 additions & 18 deletions src/hooks/useNotification.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { useCallback, useState } from 'react';
import { getToken } from 'firebase/messaging';
import { messaging } from '@/libs/firebase.ts';
import { useCreateDeviceToken } from '@/queries/useCreateDeviceToken.ts';
import CenterBottomSheet from '@/components/common/CenterBottomSheet';
import CTAButton from '@/components/common/CTAButton';
import { useDeleteDeviceToken } from '@/queries/useDeleteDeviceToken.ts';
import { useToken } from '@/hooks/useToken.ts';

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

export const useNotification = () => {
const { mutate: createDeviceToken } = useCreateDeviceToken();
// const { mutate: createDeviceToken } = useCreateDeviceToken();
const { mutate: deleteDeviceToken } = useDeleteDeviceToken();
const { getAccessToken } = useToken();

const [isModalOpen, setIsModalOpen] = useState(false);

Expand Down Expand Up @@ -49,24 +48,15 @@ export const useNotification = () => {
);

const requestPermission = useCallback(async () => {
const permission = await Notification.requestPermission();

if (permission === 'granted') {
const token = await getToken(messaging, {
vapidKey: import.meta.env.VITE_VAPID_KEY,
});

createDeviceToken(token);

localStorage.setItem(DEVICE_TOKEN_KEY, token);
return;
if (window?.ReactNativeWebView) {
window.ReactNativeWebView.postMessage(getAccessToken());
}

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

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

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

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

const queryClient = useQueryClient();

Expand All @@ -44,12 +43,11 @@ const Main = () => {
}
}, []);

useEffect(() => {
if (!isPermissionChecked) {
console.log('isPermissionChecked', isPermissionChecked);
openPermissionModal();
}
}, []);
// useEffect(() => {
// if (!isPermissionChecked) {
// openPermissionModal();
// }
// }, []);

useEffect(() => {
void queryClient.prefetchQuery({
Expand All @@ -67,7 +65,7 @@ const Main = () => {
<BloomingWeather register={register} />
<HeightBox height={100} />
<TabBar />
<RequestPermissionModal />
{/*<RequestPermissionModal />*/}
</Screen>
);
};
Expand Down
9 changes: 9 additions & 0 deletions src/types/react-native.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export {};

declare global {
interface Window {
ReactNativeWebView: {
postMessage: (message: string) => void;
};
}
}

0 comments on commit f719870

Please sign in to comment.