Skip to content

Commit

Permalink
[#619] PWA 구현 (#621)
Browse files Browse the repository at this point in the history
* feat: manifest 작성

* feat: PWAServiceWorker 작성

* chore: gitignore 추가

* chore: icon 이미지 추가

* chore: appleSplashScreen 이미지 추가

* feat: appleSplashScreen 적용

* feat: 메타데이터 추가 및 수정

* chore: manifest 불필요한 옵션 제거

* chore: 중복되는 meta태그 제거

* fix: 최상단 상태바 버그 수정

* feat: pwa환경 수직 패딩값 추가

* feat: pwa에서 bottomNavigation pb값 추가 및 statusBarStyle 속성 제거

* fix: BottomNavigation 고정 height값 제거

* feat: pb-safe 속성 추가

* fix: apple-touch-icon 아이콘 버그 수정

* fix: BottomNavigation 비정상적으로 보이던 문제 해결

* fix: 컴포넌트들의 position이 동적으로 바뀌도록 수정

* chore: import문 절대경로로 수정

* chore: 불필요한 className 제거
  • Loading branch information
hanyugeon authored and gxxrxn committed Jun 17, 2024
1 parent 70af27a commit 587f990
Show file tree
Hide file tree
Showing 55 changed files with 345 additions and 20 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,12 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts

# auto generated pwa files
# Auto Generated PWA files
**/public/sw.js
**/public/workbox-*.js
**/public/worker-*.js
**/public/sw.js.map
**/public/workbox-*.js.map
**/public/worker-*.js.map
Binary file added public/images/icon-128x128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/icon-192x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/icon-256x256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/icon-384x384.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/icon-512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions public/pwaServiceWorker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
self.addEventListener('install', () => {
console.log('Service worker installed');
});

self.addEventListener('activate', () => {
console.log('Service worker activated');
});
2 changes: 1 addition & 1 deletion src/app/group/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const GroupPage = () => {
};

const FLOATING_BUTTON_POSITION =
'bottom-[8.3rem] right-[1.7rem] desktop:right-1/2 desktop:translate-x-[19.8rem]';
'bottom-[calc(env(safe-area-inset-bottom)+8.3rem)] right-[1.7rem] desktop:right-1/2 desktop:translate-x-[19.8rem]';

return (
<>
Expand Down
23 changes: 14 additions & 9 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Metadata } from 'next';
import type { Metadata } from 'next';

import { appleSplashScreens } from '@/constants/metadata';

import ContextProvider from '@/components/ContextProvider';
import AuthFailedErrorBoundary from '@/components/AuthFailedErrorBoundary';
Expand All @@ -14,6 +16,7 @@ export const metadata: Metadata = {
default: '다독다독',
},
description: '책에 대한 인사이트를 공유하고 소통하는 독서 소셜 플랫폼',
themeColor: '#FFFFFF',
keywords: [
'다독다독',
'dadok',
Expand All @@ -25,25 +28,27 @@ export const metadata: Metadata = {
'책',
'독서',
],
viewport:
'minimum-scale=1, initial-scale=1, width=device-width, shrink-to-fit=no, viewport-fit=cover',
verification: {
google: '72kN3MWyQHuvSb8V67dVkfPUPMrw102Tm6BsvTvfKmg',
other: {
'naver-site-verification': '9046af5eda448309a92e2e923a45cb874df986a0',
},
},
icons: [
{ rel: 'apple-touch-icon', url: 'images/icon-192x192.png' },
{ rel: 'icon', url: 'favicon.ico' },
],
appleWebApp: {
title: '다독다독',
startupImage: appleSplashScreens,
},
};

const RootLayout = ({ children }: { children: React.ReactNode }) => {
return (
<html lang="ko">
<head>
<meta
content="width=device-width, initial-scale=1, maximum-scale=1"
name="viewport"
/>
<meta charSet="UTF-8" />
<link rel="icon" href="/favicon.ico" />
</head>
{/* @todo Chakra 제거시 app-layout 프로퍼티 제거. */}
<body className={`${LineSeedKR.variable} app-layout font-lineseed`}>
<Layout>
Expand Down
36 changes: 36 additions & 0 deletions src/app/manifest.webmanifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "다독다독",
"short_name": "다독다독",
"description": "책에 대한 인사이트를 공유하고 소통하는 독서 소셜 플랫폼",
"theme_color": "#FFA436",
"background_color": "#FFFFFF",
"display": "standalone",
"scope": "./",
"start_url": "./",
"icons": [
{
"src": "images/icon-192x192.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "maskable any"
},
{
"src": "images/icon-256x256.png",
"sizes": "256x256",
"type": "image/png",
"purpose": "maskable any"
},
{
"src": "images/icon-384x384.png",
"sizes": "384x384",
"type": "image/png",
"purpose": "maskable any"
},
{
"src": "images/icon-512x512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "maskable any"
}
]
}
18 changes: 11 additions & 7 deletions src/components/ContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@
import { ReactNode } from 'react';
import { RecoilRoot } from 'recoil';

import PWAServiceWorkerProvider from '@/components/PWAServiceWorkerProvider';
import ChakraThemeProvider from '@/components/ChakraThemeProvider';
import ReactQueryProvider from '@/components/ReactQueryProvider';

import ToastProvider from '@/v1/base/Toast/ToastProvider';

const ContextProvider = ({ children }: { children: ReactNode }) => {
return (
<RecoilRoot>
<ReactQueryProvider>
<ChakraThemeProvider>
<ToastProvider>{children}</ToastProvider>
</ChakraThemeProvider>
</ReactQueryProvider>
</RecoilRoot>
<PWAServiceWorkerProvider>
<RecoilRoot>
<ReactQueryProvider>
<ChakraThemeProvider>
<ToastProvider>{children}</ToastProvider>
</ChakraThemeProvider>
</ReactQueryProvider>
</RecoilRoot>
</PWAServiceWorkerProvider>
);
};

Expand Down
31 changes: 31 additions & 0 deletions src/components/PWAServiceWorkerProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use client';

import { useEffect } from 'react';

const PWAServiceWorkerProvider = ({
children,
}: {
children: React.ReactNode;
}) => {
useEffect(() => {
if ('serviceWorker' in navigator) {
const registerWorker = async () => {
const registration = await navigator.serviceWorker.register(
'/pwaServiceWorker.js'
);
registration.waiting?.postMessage('SKIP_WAITING');
};

try {
registerWorker();
console.log('register success!');
} catch (error) {
console.error('register failed: ', error);
}
}
}, []);

return <>{children}</>;
};

export default PWAServiceWorkerProvider;
Loading

0 comments on commit 587f990

Please sign in to comment.