Skip to content

Commit

Permalink
feat: Add on/off switch for recent games bar in game list
Browse files Browse the repository at this point in the history
  • Loading branch information
ximu3 committed Nov 30, 2024
1 parent b0e914d commit aca50f1
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 13 deletions.
37 changes: 37 additions & 0 deletions src/renderer/src/components/Config/Appearances.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { cn } from '~/utils'
import { Card, CardContent, CardHeader, CardTitle } from '@ui/card'
import { Switch } from '@ui/switch'
import { useDBSyncedState } from '~/hooks'

export function Appearances(): JSX.Element {
const [showRecentGamesInGameList, setShowRecentGamesInGameList] = useDBSyncedState(
true,
'config.json',
['appearances', 'gameList', 'showRecentGamesInGameList']
)

return (
<div className={cn('flex flex-col w-full h-full')}>
<Card className={cn('group')}>
<CardHeader>
<CardTitle className={cn('relative')}>
<div className={cn('flex flex-row justify-between items-center')}>
<div className={cn('flex items-center')}>游戏列表</div>
</div>
</CardTitle>
</CardHeader>
<CardContent className={cn('')}>
<div className={cn('flex flex-col gap-5 justify-center')}>
<div className={cn('flex flex-row justify-between items-center')}>
<div>是否显示最近游戏栏目</div>
<Switch
checked={showRecentGamesInGameList}
onCheckedChange={(checked) => setShowRecentGamesInGameList(checked)}
/>
</div>
</div>
</CardContent>
</Card>
</div>
)
}
7 changes: 7 additions & 0 deletions src/renderer/src/components/Config/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Advanced } from './Advanced'
import { About } from './About'
import { Scraper } from './Scraper'
import { Theme } from './Theme'
import { Appearances } from './Appearances'

export function ConfigDialog({ children }: { children: React.ReactNode }): JSX.Element {
return (
Expand All @@ -22,6 +23,9 @@ export function ConfigDialog({ children }: { children: React.ReactNode }): JSX.E
<TabsTrigger className={cn('w-full')} value="general">
通用
</TabsTrigger>
<TabsTrigger className={cn('w-full')} value="appearances">
外观
</TabsTrigger>
<TabsTrigger className={cn('w-full')} value="advanced">
高级
</TabsTrigger>
Expand All @@ -44,6 +48,9 @@ export function ConfigDialog({ children }: { children: React.ReactNode }): JSX.E
<TabsContent value="general">
<General />
</TabsContent>
<TabsContent value="appearances">
<Appearances />
</TabsContent>
<TabsContent value="advanced">
<Advanced />
</TabsContent>
Expand Down
50 changes: 37 additions & 13 deletions src/renderer/src/components/Librarybar/GameList/RecentGames.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,47 @@
import { cn } from '~/utils'
import { AccordionContent, AccordionItem, AccordionTrigger } from '@ui/accordion'
import { useGameIndexManager } from '~/hooks'
import {
ContextMenuContent,
ContextMenuTrigger,
ContextMenu,
ContextMenuItem
} from '@ui/context-menu'
import { useGameIndexManager, useDBSyncedState } from '~/hooks'
import { GameNav } from '../GameNav'

export function RecentGames(): JSX.Element {
const [showRecentGamesInGameList, setShowRecentGamesInGameList] = useDBSyncedState(
true,
'config.json',
['appearances', 'gameList', 'showRecentGamesInGameList']
)
const { sort: sortGames } = useGameIndexManager()
const games = sortGames('lastRunDate', 'desc').slice(0, 5)
return (
<AccordionItem value="recentGames">
<AccordionTrigger className={cn('bg-accent/30 text-xs p-1 pl-2')}>
<div className={cn('flex flex-row items-center justify-start gap-1')}>
<div className={cn('text-xs')}>最近游戏</div>
</div>
</AccordionTrigger>
<AccordionContent className={cn('rounded-none pt-1 flex flex-col gap-1')}>
{games.map((gameId) => (
<GameNav key={gameId} gameId={gameId} groupId="all" />
))}
</AccordionContent>
</AccordionItem>
<>
{showRecentGamesInGameList && (
<AccordionItem value="recentGames">
<ContextMenu>
<ContextMenuTrigger>
<AccordionTrigger className={cn('bg-accent/30 text-xs p-1 pl-2')}>
<div className={cn('flex flex-row items-center justify-start gap-1')}>
<div className={cn('text-xs')}>最近游戏</div>
</div>
</AccordionTrigger>
</ContextMenuTrigger>
<ContextMenuContent>
<ContextMenuItem onClick={() => setShowRecentGamesInGameList(false)}>
隐藏
</ContextMenuItem>
</ContextMenuContent>
</ContextMenu>
<AccordionContent className={cn('rounded-none pt-1 flex flex-col gap-1')}>
{games.map((gameId) => (
<GameNav key={gameId} gameId={gameId} groupId="all" />
))}
</AccordionContent>
</AccordionItem>
)}
</>
)
}

0 comments on commit aca50f1

Please sign in to comment.