Skip to content
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
205 changes: 84 additions & 121 deletions CLIENT_SERVICE_HOOK_REFACTOR.md

Large diffs are not rendered by default.

10 changes: 1 addition & 9 deletions pwa-next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,23 @@
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "eslint",
"postinstall": "prisma generate"
"lint": "eslint"
},
"dependencies": {
"@clerk/nextjs": "^7.5.22",
"@prisma/adapter-pg": "^7.9.0",
"@prisma/client": "^7.9.0",
"@tanstack/react-query": "^5.101.4",
"epubjs": "^0.3.93",
"next": "16.2.11",
"opencc-js": "^1.4.1",
"pg": "^8.22.0",
"react": "19.2.4",
"react-dom": "19.2.4",
"zustand": "^5.0.14"
},
"devDependencies": {
"@tailwindcss/postcss": "^4",
"@types/node": "^20",
"@types/pg": "^8.20.0",
"@types/react": "^19",
"@types/react-dom": "^19",
"eslint": "^9",
"eslint-config-next": "16.2.11",
"prisma": "^7.9.0",
"tailwindcss": "^4",
"typescript": "^5"
}
Expand Down
14 changes: 0 additions & 14 deletions pwa-next/prisma.config.ts

This file was deleted.

92 changes: 0 additions & 92 deletions pwa-next/prisma/schema.prisma

This file was deleted.

28 changes: 1 addition & 27 deletions pwa-next/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,29 @@

import { useEffect, useRef, useState } from 'react'
import { useRouter, useSearchParams } from 'next/navigation'
import { useUser } from '@clerk/nextjs'
import Library from '@/page/Library'
import Reader from '@/page/Reader'
import MissingBookModal from '@/components/Library/MissingBookModal'
import { useLibrary } from '@/hooks/useLibrary'
import { setSyncEnabled } from '@/services/syncGate'
import { useCloudRestoreMutation } from '@/hooks/useCloudRestore'

type View = 'library' | 'reader'

// 一個瀏覽器分頁只自動還原一次,避免使用者掛著分頁時每次重新取得焦點/切換視圖
// 都重新打一輪全量還原(GET 書庫 + 逐本書 GET 進度/書籤/註記)。
const RESTORE_ONCE_KEY = 'tit-cloud-restore-done'

const App = () => {
const { records, addBook, getBookUrl, getCoverDataUrl, removeBook, touchBook, updateProgress, replaceRecords } = useLibrary()
const { records, addBook, getBookUrl, getCoverDataUrl, removeBook, touchBook, updateProgress } = useLibrary()
const [view, setView] = useState<View>('library')
const [activeBookUrl, setActiveBookUrl] = useState<string | null>(null)
const [activeBookId, setActiveBookId] = useState<string>('')
const [initialCfi, setInitialCfi] = useState<string | undefined>(undefined)
const [darkMode, setDarkMode] = useState(true)
const [missingBook, setMissingBook] = useState<{ id: string; title: string } | null>(null)
const recoverFileInputRef = useRef<HTMLInputElement>(null)
const { isSignedIn } = useUser()
const restoreMutation = useCloudRestoreMutation(replaceRecords)

// 每個 Service 層的 sync 函式都要先查這個開關才會真的發請求,未登入時完全不送出,
// 不是「送出去再被 401 擋掉」。這個 effect 要排在下面的還原 effect 之前
// (React 同一個元件裡的 effect 依宣告順序執行),不然還原當下開關還沒打開。
// 把 dark class 同步到 <html>,讓 body 的 background-color(globals.css 的
// var(--color-paper))能跟著切換,避免深色模式下 body 背景色停留在預設淺色。
useEffect(() => {
document.documentElement.classList.toggle('dark', darkMode)
}, [darkMode])

useEffect(() => {
setSyncEnabled(!!isSignedIn)
}, [isSignedIn])

// 登入時觸發一次讀取/還原:跟雲端資料合併書庫清單/進度/書籤/註記,取代舊版
// 只寫不讀的登入補推 effect(見 useCloudRestore.ts 的完整合併邏輯說明)。
useEffect(() => {
if (!isSignedIn) return
if (sessionStorage.getItem(RESTORE_ONCE_KEY) === '1') return
sessionStorage.setItem(RESTORE_ONCE_KEY, '1')
restoreMutation.mutate()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isSignedIn])

const handleOpenBook = async (id: string, cfi?: string) => {
const url = await getBookUrl(id)
if (!url) {
Expand Down
87 changes: 0 additions & 87 deletions pwa-next/src/app/api/books/[bookId]/annotations/route.ts

This file was deleted.

75 changes: 0 additions & 75 deletions pwa-next/src/app/api/books/[bookId]/bookmarks/route.ts

This file was deleted.

34 changes: 0 additions & 34 deletions pwa-next/src/app/api/books/[bookId]/progress/route.ts

This file was deleted.

Loading
Loading