@@ -5,10 +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" ;
89import { GamevaultUser } from "../api" ;
910
1011export default function Community ( ) {
1112 const { serverUrl, authFetch, user : loggedIn } = useAuth ( ) ;
13+ const navigate = useNavigate ( ) ;
1214 const [ users , setUsers ] = useState < GamevaultUser [ ] > ( [ ] ) ;
1315 const [ currentUsername , setCurrentUsername ] = useState < string > ( "" ) ;
1416 const [ loading , setLoading ] = useState < boolean > ( false ) ;
@@ -279,12 +281,34 @@ export default function Community() {
279281 const coverId = game ? getGameCoverMediaId ( game ) : null ;
280282 const key = p . id ?? `${ ( game && game . id ) || "g" } -${ idx } ` ;
281283 const hours = minutes / 60 ;
284+ const openGame = ( ) => {
285+ if ( ! game ?. id ) return ;
286+ const base = ( serverUrl || "" ) . replace ( / \/ + $ / , "" ) ;
287+ if ( base ) {
288+ window . location . href = `${ base } /library/${ game . id } ` ;
289+ } else {
290+ navigate ( `/library/${ game . id } ` ) ;
291+ }
292+ } ;
293+ const onKey : React . KeyboardEventHandler < HTMLDivElement > = ( e ) => {
294+ if ( e . key === 'Enter' || e . key === ' ' ) {
295+ e . preventDefault ( ) ;
296+ openGame ( ) ;
297+ }
298+ } ;
282299 return (
283300 < div
284301 key = { String ( key ) }
285302 className = "flex items-center gap-4 p-3"
286303 >
287- < div className = "shrink-0" >
304+ < div
305+ className = "shrink-0 cursor-pointer focus:outline-none focus:ring-2 focus:ring-indigo-500 rounded-lg"
306+ role = "button"
307+ tabIndex = { 0 }
308+ onClick = { openGame }
309+ onKeyDown = { onKey }
310+ title = { title }
311+ >
288312 { coverId ? (
289313 < Media
290314 media = { { id : coverId } as any }
@@ -296,9 +320,11 @@ export default function Community() {
296320 />
297321 ) : (
298322 < div
299- className = "rounded-lg bg-zinc-200 dark:bg-zinc-800"
323+ className = "rounded-lg bg-zinc-200 dark:bg-zinc-800 flex items-center justify-center text-[10px] text-zinc-600 dark:text-zinc-400 "
300324 style = { { width : 48 , height : 64 } }
301- />
325+ >
326+ No Cover
327+ </ div >
302328 ) }
303329 </ div >
304330 < div className = "min-w-0 flex-1" >
0 commit comments