1
- import React , { useEffect , useState } from 'react' ;
1
+ import React , { useEffect , useState , useContext } from 'react' ;
2
2
import { PropTypes } from 'prop-types' ;
3
3
import { useFocusable , init , FocusContext , setKeyMap } from 'spatial' ;
4
4
import { useNavigate , Link } from 'react-router-dom' ;
5
+ import { GlobalContext } from 'context/globalContext' ;
5
6
6
7
function System ( { data, onEnterPress, onFocus } ) {
7
8
const { ref, focused } = useFocusable ( {
8
9
onEnterPress,
9
10
onFocus,
10
11
} ) ;
12
+ const { state, setState } = useContext ( GlobalContext ) ;
11
13
14
+ const { themeName, currentSystem } = state ;
12
15
const item = data ;
16
+
17
+ const saveSystem = ( id ) => {
18
+ console . log ( { id } ) ;
19
+ setState ( { ...state , currentSystem : id } ) ;
20
+ } ;
21
+
22
+ const devnull = ( id ) => {
23
+ // setState({ ...state, currentSystem: id });
24
+ } ;
25
+
26
+ useEffect ( ( ) => {
27
+ if ( focused ) {
28
+ if ( item . id !== currentSystem ) {
29
+ saveSystem ( item . id ) ;
30
+ }
31
+ }
32
+ // Opcionalmente, incluir devnull o lógica similar si necesitas manejar la pérdida de foco.
33
+ } , [ focused , item . id , saveSystem ] ) ;
34
+
13
35
return (
14
36
< div ref = { ref } >
15
37
< Link
@@ -19,18 +41,31 @@ function System({ data, onEnterPress, onFocus }) {
19
41
focused ? 'systems__system--focused' : ''
20
42
} `}
21
43
>
22
- < img className = "systems__bg" src = { item . poster } alt = "" />
44
+ < img
45
+ className = "systems__bg"
46
+ src = { `file:///Users/rsedano/emudeck/launcher/themes/${ themeName } /posters/${ item . id } .jpg` }
47
+ alt = ""
48
+ />
23
49
< div className = "systems__excerpt" > { item . excerpt } </ div >
24
50
< div className = "systems__name" > { item . name } </ div >
25
51
< div className = "systems__count" > Games: { item . games } </ div >
26
52
< div className = "systems__description" > { item . description } </ div >
27
- < img
28
- loading = "lazy"
29
- className = "systems__controller"
30
- src = { item . controller }
31
- alt = ""
32
- />
33
- < img loading = "lazy" className = "systems__logo" src = { item . logo } alt = "" />
53
+ < div className = "systems__controller-holder" >
54
+ < img
55
+ loading = "lazy"
56
+ className = "systems__controller"
57
+ src = { item . controller }
58
+ alt = ""
59
+ />
60
+ </ div >
61
+ < div className = "systems__logo-holder" >
62
+ < img
63
+ loading = "lazy"
64
+ className = "systems__logo"
65
+ src = { `file:///Users/rsedano/emudeck/launcher/themes/${ themeName } /logos/${ item . id } .svg` }
66
+ alt = ""
67
+ />
68
+ </ div >
34
69
</ Link >
35
70
</ div >
36
71
) ;
0 commit comments