Add categories to sidebar
This commit is contained in:
@@ -43,6 +43,8 @@ type GlobalCtxType = {
|
||||
viewingInfoFromDownloads: boolean
|
||||
version: string | null
|
||||
downloadVersions: (list: string[]) => Promise<void>
|
||||
category: number
|
||||
setCategory: Dispatch<SetStateAction<number>>
|
||||
}
|
||||
|
||||
const GlobalCtx = createContext<GlobalCtxType | null>(null)
|
||||
|
||||
@@ -8,16 +8,18 @@ import {
|
||||
faCog,
|
||||
faDownload,
|
||||
faGamepad,
|
||||
faHexagonNodes
|
||||
faHexagonNodes,
|
||||
faLayerGroup
|
||||
} from '@fortawesome/free-solid-svg-icons'
|
||||
import { faDiscord } from '@fortawesome/free-brands-svg-icons'
|
||||
import { platform } from '@tauri-apps/plugin-os'
|
||||
import { useGlobal } from '../GlobalProvider'
|
||||
import Image from 'next/image'
|
||||
import Link from 'next/link'
|
||||
import { usePathname, useSearchParams } from 'next/navigation'
|
||||
import { usePathname, useRouter, useSearchParams } from 'next/navigation'
|
||||
import { getCurrentWindow } from '@tauri-apps/api/window'
|
||||
import { Lexend } from 'next/font/google'
|
||||
import React from 'react'
|
||||
|
||||
const lexend = Lexend({
|
||||
subsets: ['latin']
|
||||
@@ -30,11 +32,16 @@ export default function Sidebar () {
|
||||
setShowPopup,
|
||||
setPopupMode,
|
||||
setFadeOut,
|
||||
downloadProgress
|
||||
downloadProgress,
|
||||
downloadedVersionsConfig,
|
||||
getVersionInfo,
|
||||
category,
|
||||
setCategory
|
||||
} = useGlobal()
|
||||
|
||||
const pathname = usePathname()
|
||||
const params = useSearchParams()
|
||||
const router = useRouter()
|
||||
|
||||
return (
|
||||
<aside className='sidebar'>
|
||||
@@ -92,27 +99,87 @@ export default function Sidebar () {
|
||||
return a.id - b.id
|
||||
})
|
||||
.map(i => (
|
||||
<Link
|
||||
key={i.id}
|
||||
draggable={false}
|
||||
href={'/game?id=' + i.id}
|
||||
className={`link ${
|
||||
pathname === '/game' && Number(params.get('id') || 0) == i.id
|
||||
? 'active'
|
||||
: ''
|
||||
} ml-auto w-50 ${
|
||||
normalConfig?.settings.alwaysShowGamesInSidebar ||
|
||||
pathname === '/' ||
|
||||
pathname === '/game'
|
||||
? ''
|
||||
: 'hidden'
|
||||
}`}
|
||||
>
|
||||
<div className='flex items-center'>
|
||||
<FontAwesomeIcon icon={faGamepad} className='mr-1' />
|
||||
<span className='truncate max-w-full'>{i.name}</span>
|
||||
<React.Fragment key={i.id}>
|
||||
<div
|
||||
draggable={false}
|
||||
className={`link ${
|
||||
pathname === '/game' && Number(params.get('id') || 0) == i.id
|
||||
? 'active'
|
||||
: ''
|
||||
} ml-auto w-50 ${
|
||||
normalConfig?.settings.alwaysShowGamesInSidebar ||
|
||||
pathname === '/' ||
|
||||
pathname === '/game'
|
||||
? ''
|
||||
: 'hidden'
|
||||
}`}
|
||||
onClick={() => {
|
||||
setCategory(-1)
|
||||
router.push('/game?id=' + i.id)
|
||||
}}
|
||||
>
|
||||
<div className='flex items-center'>
|
||||
<FontAwesomeIcon
|
||||
icon={
|
||||
Object.entries(i.categoryNames).length > 0
|
||||
? faLayerGroup
|
||||
: faGamepad
|
||||
}
|
||||
className='mr-1'
|
||||
/>
|
||||
<span className='truncate max-w-full'>{i.name}</span>
|
||||
</div>
|
||||
</div>
|
||||
</Link>
|
||||
{Object.entries(i.categoryNames)
|
||||
.sort(([a], [b]) => Number(b) - Number(a))
|
||||
.filter(([key]) => {
|
||||
const count = Object.keys(
|
||||
downloadedVersionsConfig?.list ?? {}
|
||||
).filter(v => {
|
||||
const info = getVersionInfo(v)
|
||||
if (!info) return false
|
||||
|
||||
if (
|
||||
platform() === 'linux' &&
|
||||
info.wine &&
|
||||
!normalConfig?.settings.useWineOnUnixWhenNeeded
|
||||
)
|
||||
return false
|
||||
|
||||
return info.game === i.id && info.category === Number(key)
|
||||
}).length
|
||||
|
||||
return count >= 1
|
||||
})
|
||||
.map(([key, value]) => (
|
||||
<div
|
||||
key={`${i.id}-${key}`}
|
||||
draggable={false}
|
||||
className={`link ${
|
||||
pathname === '/game' &&
|
||||
Number(params.get('id') || 0) == i.id &&
|
||||
category == Number(key)
|
||||
? 'active'
|
||||
: ''
|
||||
} ml-auto w-47.5 ${
|
||||
normalConfig?.settings.alwaysShowGamesInSidebar ||
|
||||
pathname === '/' ||
|
||||
pathname === '/game'
|
||||
? ''
|
||||
: 'hidden'
|
||||
}`}
|
||||
onClick={() => {
|
||||
setCategory(Number(key))
|
||||
router.push('/game?id=' + i.id)
|
||||
}}
|
||||
>
|
||||
<div className='flex items-center'>
|
||||
<FontAwesomeIcon icon={faGamepad} className='mr-1' />
|
||||
<span className='truncate max-w-full'>{value}</span>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</React.Fragment>
|
||||
))}
|
||||
<Link
|
||||
draggable={false}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use client'
|
||||
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useEffect } from 'react'
|
||||
import '../Installs.css'
|
||||
import { invoke } from '@tauri-apps/api/core'
|
||||
import { useGlobal } from '../GlobalProvider'
|
||||
@@ -22,7 +22,9 @@ export default function Installs () {
|
||||
getVersionInfo,
|
||||
getGameInfo,
|
||||
setSelectedGame,
|
||||
serverVersionList
|
||||
serverVersionList,
|
||||
category,
|
||||
setCategory
|
||||
} = useGlobal()
|
||||
|
||||
const params = useSearchParams()
|
||||
@@ -30,9 +32,6 @@ export default function Installs () {
|
||||
const id = Number(params.get('id') || 0)
|
||||
const game = serverVersionList?.games.find(g => g.id === id)
|
||||
|
||||
const [category, setCategory] = useState<number>(-1)
|
||||
const [lastId, setLastId] = useState(id)
|
||||
|
||||
useEffect(() => {
|
||||
if (!showPopup) return
|
||||
setSelectedVersionList([])
|
||||
@@ -40,11 +39,6 @@ export default function Installs () {
|
||||
|
||||
if (!id || !game) return <p>Invalid game</p>
|
||||
|
||||
if (lastId !== id) {
|
||||
setLastId(id)
|
||||
setCategory(-1)
|
||||
}
|
||||
|
||||
const needsRevisionUpdate = (
|
||||
lastRevision: number | undefined,
|
||||
version: string
|
||||
|
||||
@@ -82,6 +82,8 @@ export default function RootLayout ({
|
||||
useState<boolean>(false)
|
||||
const [selectedGame, setSelectedGame] = useState<number | null>(null)
|
||||
|
||||
const [category, setCategory] = useState<number>(-1)
|
||||
|
||||
const pathname = usePathname()
|
||||
const revisionCheck = useRef(false)
|
||||
|
||||
@@ -480,7 +482,9 @@ export default function RootLayout ({
|
||||
getVersionsAmountData,
|
||||
viewingInfoFromDownloads,
|
||||
version,
|
||||
downloadVersions
|
||||
downloadVersions,
|
||||
category,
|
||||
setCategory
|
||||
}}
|
||||
>
|
||||
<div
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
import { useEffect } from 'react'
|
||||
import './Installs.css'
|
||||
import { useGlobal } from './GlobalProvider'
|
||||
import Link from 'next/link'
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
||||
import {
|
||||
faCheck,
|
||||
@@ -24,7 +23,8 @@ export default function Installs () {
|
||||
normalConfig,
|
||||
setSelectedGame,
|
||||
getListOfGames,
|
||||
getVersionsAmountData
|
||||
getVersionsAmountData,
|
||||
setCategory
|
||||
} = useGlobal()
|
||||
|
||||
const router = useRouter()
|
||||
@@ -80,6 +80,7 @@ export default function Installs () {
|
||||
}
|
||||
onClick={() => {
|
||||
if (normalConfig?.settings.useLegacyInteractButtons) return
|
||||
setCategory(-1)
|
||||
router.push('/game?id=' + i.id)
|
||||
}}
|
||||
>
|
||||
@@ -128,14 +129,17 @@ export default function Installs () {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Link
|
||||
<div
|
||||
className='button absolute right-0 bottom-0'
|
||||
href={'/game?id=' + i.id}
|
||||
hidden={!normalConfig?.settings.useLegacyInteractButtons}
|
||||
title='Click to view game installs'
|
||||
onClick={() => {
|
||||
setCategory(-1)
|
||||
router.push('/game?id=' + i.id)
|
||||
}}
|
||||
>
|
||||
Installs
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))
|
||||
|
||||
Reference in New Issue
Block a user