37 lines
1.9 KiB
TypeScript
37 lines
1.9 KiB
TypeScript
import { keepPreviousData, MutationCache, QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
import { myLevelQueryKey } from '@nalssigak/shared/api/client/@tanstack/react-query.gen'
|
|
import { StrictMode } from 'react'
|
|
import { createRoot } from 'react-dom/client'
|
|
import './index.css'
|
|
import './api/setup'
|
|
import App from './App.tsx'
|
|
import './b/install'
|
|
import { track } from './lib/analytics'
|
|
|
|
// index.html 의 첫 화면이 멈췄을 때 앱 파일까지는 실행됐는지 가르는 표시
|
|
;(window as Window & { __appStarted?: boolean }).__appStarted = true
|
|
|
|
// iOS는 user-scalable=no를 무시해서 두 손가락 확대를 직접 막는다
|
|
for (const type of ['gesturestart', 'gesturechange']) document.addEventListener(type, (e) => e.preventDefault(), { passive: false })
|
|
|
|
// 칩·지역·검색어를 바꿔 다시 받는 동안 이전 결과를 그대로 두어 화면이 비거나 접히지 않게 한다
|
|
const queryClient: QueryClient = new QueryClient({
|
|
defaultOptions: { queries: { staleTime: 5 * 60 * 1000, retry: 1, refetchOnWindowFocus: false, placeholderData: keepPreviousData } },
|
|
// 각을 주는 일(타로·좋아요·댓글·글·체크인·공유)은 모두 mutation 이라, 끝나면 내 레벨을 다시 받는다
|
|
mutationCache: new MutationCache({ onSuccess: () => queryClient.invalidateQueries({ queryKey: myLevelQueryKey() }) }),
|
|
})
|
|
|
|
// 홈 화면 설치 조건(서비스 워커)과, 홈 화면 아이콘으로 연 횟수
|
|
if (import.meta.env.PROD && 'serviceWorker' in navigator) {
|
|
navigator.serviceWorker.register('/sw.js').catch((e: unknown) => console.error('[sw] register', e))
|
|
}
|
|
if (window.matchMedia('(display-mode: standalone)').matches || (navigator as Navigator & { standalone?: boolean }).standalone) track('app_launch', { mode: 'standalone' })
|
|
|
|
createRoot(document.getElementById('root')!).render(
|
|
<StrictMode>
|
|
<QueryClientProvider client={queryClient}>
|
|
<App />
|
|
</QueryClientProvider>
|
|
</StrictMode>,
|
|
)
|