Skip to content

Commit

Permalink
fix: Fix the problem that some states can't be updated properly
Browse files Browse the repository at this point in the history
  • Loading branch information
ximu3 committed Nov 28, 2024
1 parent 2bb4657 commit a271562
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
5 changes: 4 additions & 1 deletion src/renderer/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useUpdaterStore } from './pages/Updater/store'
import { useEffect } from 'react'
import { ipcOnUnique } from './utils'
import { ThemeProvider } from './components/ThemeProvider'
import { HashRouter } from 'react-router-dom'

function App(): JSX.Element {
const { setIsOpen: setIsUpdateDialogOpen } = useUpdaterStore()
Expand All @@ -22,7 +23,9 @@ function App(): JSX.Element {
return (
<ThemeProvider>
<Titlebar />
<Main />
<HashRouter>
<Main />
</HashRouter>
<GameAdder />
<GameBatchAdder />
<Toaster />
Expand Down
7 changes: 7 additions & 0 deletions src/renderer/src/components/Game/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ export function Header({ gameId, className }: { gameId: string; className?: stri
const [preScore, setPreScore] = useState(score.toString())
const [isScoreDialogOpen, setIsScoreDialogOpen] = useState(false)

const [_saveList] = useDBSyncedState(
{ ['']: { id: '', date: '', note: '' } },
`games/${gameId}/save.json`,
['#all']
)
const [_timer] = useDBSyncedState([], `games/${gameId}/record.json`, ['timer'])

function confirmScore(): void {
const scoreNum = parseFloat(preScore)

Expand Down
3 changes: 2 additions & 1 deletion src/renderer/src/components/Game/Record/RecordCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ export function RecordCard({
const playDays = getGamePlayDays(gameId)
const [playingTime] = useDBSyncedState(0, `games/${gameId}/record.json`, ['playingTime'])
const [lastRunDate] = useDBSyncedState('', `games/${gameId}/record.json`, ['lastRunDate'])
const [timer] = useDBSyncedState([], `games/${gameId}/record.json`, ['timer'])
const equalPlayingTime = playingTime / playDays
const maxPlayTimeDay = getGameMaxPlayTimeDay(gameId)
return (
<Card className={cn(className, 'p-3 w-auto')}>
{lastRunDate ? (
{lastRunDate && timer.length !== 0 ? (
<>
<div className={cn('flex flex-row')}>
<div>
Expand Down
22 changes: 11 additions & 11 deletions src/renderer/src/pages/Main.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HashRouter, Routes, Route, Navigate } from 'react-router-dom'
import { Routes, Route, Navigate, useNavigate } from 'react-router-dom'
import { Sidebar } from '~/components/Sidebar'
import { cn, ipcOnUnique, ipcSend } from '~/utils'
import { Library } from './Library'
Expand All @@ -11,6 +11,7 @@ import { useCloudSyncStore, SyncStatus } from '~/components/Config/CloudSync/sto
export function Main(): JSX.Element {
const { runningGames, setRunningGames } = useRunningGames()
const { setStatus } = useCloudSyncStore()
const navigate = useNavigate()
useEffect(() => {
const handleStartGameFromUrl = (
_event: any,
Expand Down Expand Up @@ -47,6 +48,7 @@ export function Main(): JSX.Element {
mode: string,
config: any
): Promise<void> {
navigate(`/library/games/${gameId}/all`)
if (gamePath === '') {
toast.warning('请先设置游戏路径')
return
Expand Down Expand Up @@ -77,15 +79,13 @@ export function Main(): JSX.Element {
}
}
return (
<HashRouter>
<div className={cn('flex flex-row w-screen h-screen')}>
<Sidebar />
<Routes>
<Route index element={<Navigate to="/library" />} />
<Route path="/library/*" element={<Library />} />
<Route path="/record/*" element={<Record />} />
</Routes>
</div>
</HashRouter>
<div className={cn('flex flex-row w-screen h-screen')}>
<Sidebar />
<Routes>
<Route index element={<Navigate to="/library" />} />
<Route path="/library/*" element={<Library />} />
<Route path="/record/*" element={<Record />} />
</Routes>
</div>
)
}

0 comments on commit a271562

Please sign in to comment.