@@ -5,13 +5,12 @@ import { Divider } from "@tw/divider";
55import { Heading } from "@tw/heading" ;
66import { Listbox , ListboxLabel , ListboxOption } from "@tw/listbox" ;
77import { useEffect , useMemo , useState } from "react" ;
8- import { useNavigate } from "react-router" ;
8+ import { Link } from "react-router" ;
99import { GamevaultUser } from "../api" ;
1010import { ROLE_LABELS } from "@/utils/roles" ;
1111
1212export default function Community ( ) {
1313 const { serverUrl, authFetch, user : loggedIn } = useAuth ( ) ;
14- const navigate = useNavigate ( ) ;
1514 const [ users , setUsers ] = useState < GamevaultUser [ ] > ( [ ] ) ;
1615 const [ currentUsername , setCurrentUsername ] = useState < string > ( "" ) ;
1716 const [ loading , setLoading ] = useState < boolean > ( false ) ;
@@ -282,52 +281,60 @@ export default function Community() {
282281 const coverId = game ? getGameCoverMediaId ( game ) : null ;
283282 const key = p . id ?? `${ ( game && game . id ) || "g" } -${ idx } ` ;
284283 const hours = minutes / 60 ;
285- const openGame = ( ) => {
286- if ( ! game ?. id ) return ;
287- const base = ( serverUrl || "" ) . replace ( / \/ + $ / , "" ) ;
288- if ( base ) {
289- window . location . href = `${ base } /library/${ game . id } ` ;
290- } else {
291- navigate ( `/library/${ game . id } ` ) ;
292- }
293- } ;
294- const onKey : React . KeyboardEventHandler < HTMLDivElement > = ( e ) => {
295- if ( e . key === 'Enter' || e . key === ' ' ) {
296- e . preventDefault ( ) ;
297- openGame ( ) ;
298- }
299- } ;
284+ const gameUrl = game ?. id ? `/library/${ game . id } ` : undefined ;
300285 return (
301286 < div
302287 key = { String ( key ) }
303288 className = "flex items-center gap-4 p-3"
304289 >
305- < div
306- className = "shrink-0 cursor-pointer focus:outline-none focus:ring-2 focus:ring-indigo-500 rounded-lg"
307- role = "button"
308- tabIndex = { 0 }
309- onClick = { openGame }
310- onKeyDown = { onKey }
311- title = { title }
312- >
313- { coverId ? (
314- < Media
315- media = { { id : coverId } as any }
316- width = { 48 }
317- height = { 64 }
318- className = "rounded-lg"
319- square
320- alt = { title }
321- />
322- ) : (
323- < div
324- className = "rounded-lg bg-zinc-200 dark:bg-zinc-800 flex items-center justify-center text-[10px] text-zinc-600 dark:text-zinc-400"
325- style = { { width : 48 , height : 64 } }
326- >
327- No Cover
328- </ div >
329- ) }
330- </ div >
290+ { gameUrl ? (
291+ < Link
292+ to = { gameUrl }
293+ className = "shrink-0 focus:outline-none focus:ring-2 focus:ring-indigo-500 rounded-lg"
294+ title = { title }
295+ >
296+ { coverId ? (
297+ < Media
298+ media = { { id : coverId } as any }
299+ width = { 48 }
300+ height = { 64 }
301+ className = "rounded-lg"
302+ square
303+ alt = { title }
304+ />
305+ ) : (
306+ < div
307+ className = "rounded-lg bg-zinc-200 dark:bg-zinc-800 flex items-center justify-center text-[10px] text-zinc-600 dark:text-zinc-400"
308+ style = { { width : 48 , height : 64 } }
309+ >
310+ No Cover
311+ </ div >
312+ ) }
313+ </ Link >
314+ ) : (
315+ < div
316+ className = "shrink-0 rounded-lg"
317+ title = { title }
318+ >
319+ { coverId ? (
320+ < Media
321+ media = { { id : coverId } as any }
322+ width = { 48 }
323+ height = { 64 }
324+ className = "rounded-lg"
325+ square
326+ alt = { title }
327+ />
328+ ) : (
329+ < div
330+ className = "rounded-lg bg-zinc-200 dark:bg-zinc-800 flex items-center justify-center text-[10px] text-zinc-600 dark:text-zinc-400"
331+ style = { { width : 48 , height : 64 } }
332+ >
333+ No Cover
334+ </ div >
335+ ) }
336+ </ div >
337+ ) }
331338 < div className = "min-w-0 flex-1" >
332339 < div className = "text-sm font-medium truncate" >
333340 { title }
0 commit comments