diff --git a/.gitignore b/.gitignore index 7140179..b0234c4 100644 --- a/.gitignore +++ b/.gitignore @@ -41,8 +41,17 @@ yarn-error.log* # Prevent commiting lock file. package-lock.json -secret.json - # sub module +api-docs/ -api-docs/ \ No newline at end of file +# next-pwa +public/precache.*.*.js +public/sw.js +public/workbox-*.js +public/worker-*.js +public/fallback-*.js +public/precache.*.*.js.map +public/sw.js.map +public/workbox-*.js.map +public/worker-*.js.map +public/fallback-*.js \ No newline at end of file diff --git a/components/Navbar.tsx b/components/Navbar.tsx index 1b14901..65fb104 100644 --- a/components/Navbar.tsx +++ b/components/Navbar.tsx @@ -11,7 +11,7 @@ import { User, UserCache } from '@types' import DiscordAvatar from '@components/DiscordAvatar' import Fetch from '@utils/Fetch' -const Navbar = ({ token }:{ token: string }): JSX.Element => { +const Navbar = ({ token, pwa }:{ token: string, pwa: boolean }): JSX.Element => { const [userCache, setUserCache] = useState() const [navbarOpen, setNavbarOpen] = useState(false) const [dropdownOpen, setDropdownOpen] = useState(false) @@ -124,18 +124,11 @@ const Navbar = ({ token }:{ token: string }): JSX.Element => { : - { - if(!(logged)) { - localStorage.redirectTo = window.location.href - setNavbarOpen(false) - redirectTo(router, 'login') - } - }} onClick={()=> { - if(!(logged)) { - localStorage.redirectTo = window.location.href - setNavbarOpen(false) - redirectTo(router, 'login') - } + { + localStorage.redirectTo = window.location.href + setNavbarOpen(false) + if(pwa) window.open('/api/auth/discord') + else redirectTo(router, 'login') }} className='lg:hover:text-gray-300 flex items-center px-3 py-4 w-full hover:text-gray-500 text-gray-700 text-sm font-semibold sm:w-auto lg:py-2 lg:text-gray-100 cursor-pointer outline-none'> 로그인 @@ -204,15 +197,15 @@ const Navbar = ({ token }:{ token: string }): JSX.Element => { 로그아웃 - : - { - localStorage.redirectTo = window.location.href - setNavbarOpen(false) - }} className='flex items-center px-8 py-2 text-gray-100 hover:text-gray-300'> - - 로그인 - - + : { + localStorage.redirectTo = window.location.href + setNavbarOpen(false) + if(pwa) window.open('/api/auth/discord') + else redirectTo(router, 'login') + }} className='flex items-center px-8 py-2 text-gray-100 hover:text-gray-300'> + + 로그인 + } diff --git a/next.config.js b/next.config.js index 7583649..b76e73e 100644 --- a/next.config.js +++ b/next.config.js @@ -1,8 +1,12 @@ /* eslint-disable @typescript-eslint/no-var-requires */ const { withSentryConfig } = require('@sentry/nextjs') +const withPWA = require('next-pwa') const VERSION = require('./package.json').version -module.exports = withSentryConfig({ +module.exports = withSentryConfig(withPWA({ + pwa: { + dest: 'public' + }, env: { NEXT_PUBLIC_RELEASE_VERSION: VERSION, SENTRY_SKIP_AUTO_RELEASE: true @@ -13,4 +17,4 @@ module.exports = withSentryConfig({ experimental: { scrollRestoration: true } -}, {}) \ No newline at end of file +}), {}) \ No newline at end of file diff --git a/package.json b/package.json index 4f46f8f..fee810c 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "mysql": "2.18.1", "next": "10.2.0", "next-connect": "0.10.1", + "next-pwa": "5.2.21", "next-session": "3.4.0", "node-emoji": "1.10.0", "nprogress": "0.2.0", diff --git a/pages/_app.tsx b/pages/_app.tsx index caae990..87ef62c 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -7,7 +7,7 @@ import { GlobalHotKeys } from 'react-hotkeys' import NProgress from 'nprogress' import Logger from '@utils/Logger' -import { parseCookie, systemTheme } from '@utils/Tools' +import { handlePWA, parseCookie, systemTheme } from '@utils/Tools' import { shortcutKeyMap } from '@utils/Constants' import { Theme } from '@types' @@ -34,6 +34,7 @@ Router.events.on('routeChangeError', NProgress.done) const KoreanbotsApp = ({ Component, pageProps, err, cookie }: KoreanbotsProps): JSX.Element => { const [ shortcutModal, setShortcutModal ] = useState(false) const [ theme, setTheme ] = useState('system') + const [ standalone, setStandalone ] = useState(false) const router = useRouter() useEffect(() => { @@ -50,24 +51,17 @@ const KoreanbotsApp = ({ Component, pageProps, err, cookie }: KoreanbotsProps): setTheme(systemTheme()) } else setTheme(localStorage.theme) + setStandalone(handlePWA()) }, []) return
- + 한국 디스코드봇 리스트 - - - - - - - - - +
- +
{ !(router.pathname.startsWith('/developers')) &&