File tree Expand file tree Collapse file tree 3 files changed +45
-19
lines changed Expand file tree Collapse file tree 3 files changed +45
-19
lines changed Original file line number Diff line number Diff line change @@ -6,11 +6,16 @@ import {getWeightClass} from "../mechSelectors";
6
6
const MechDetails = ( { mech= { } } ) => {
7
7
const {
8
8
id = "" ,
9
- name = "" ,
10
9
type = "" ,
11
- weight = "" ,
10
+ mechType = { } ,
12
11
} = mech ;
13
12
13
+ const {
14
+ name = "" ,
15
+ weight = "" ,
16
+ } = mechType ;
17
+
18
+
14
19
const weightClass = getWeightClass ( weight ) ;
15
20
16
21
return (
Original file line number Diff line number Diff line change 1
1
import React , { Component } from "react" ;
2
+ import { connect } from "react-redux" ;
2
3
3
4
import {
4
5
Grid ,
5
6
Segment ,
6
7
Header ,
7
8
} from "semantic-ui-react" ;
8
9
10
+ import schema from "app/schema" ;
11
+
9
12
import MechsList from "../MechsList" ;
10
13
import MechDetails from "../MechDetails" ;
11
14
12
- const mechs = [
13
- {
14
- id : 1 ,
15
- name : "Warhammer" ,
16
- type : "WHM-6R" ,
17
- weight : 70 ,
18
- }
19
- ] ;
20
15
21
- class Mechs extends Component {
22
- state = {
23
- mechs : mechs ,
24
- }
16
+ const mapState = ( state ) => {
17
+ const session = schema . from ( state . entities ) ;
18
+ const { Mech} = session ;
19
+
20
+ const mechs = Mech . all ( ) . withModels . map ( mechModel => {
21
+ const mech = {
22
+ // Copy the data from the plain JS object
23
+ ...mechModel . ref ,
24
+ // Provide a default empty object for the relation
25
+ mechType : { } ,
26
+ } ;
27
+
28
+ if ( mechModel . type ) {
29
+ // Replace the default object with a copy of the relation's data
30
+ mech . mechType = { ...mechModel . type . ref } ;
31
+ }
25
32
33
+ return mech ;
34
+ } ) ;
35
+
36
+ return { mechs}
37
+ }
38
+
39
+ class Mechs extends Component {
26
40
render ( ) {
27
- const { mechs} = this . state ;
41
+ const { mechs = [ ] } = this . props ;
28
42
29
43
const currentMech = mechs [ 0 ] || { } ;
30
44
@@ -46,4 +60,6 @@ class Mechs extends Component {
46
60
) ;
47
61
}
48
62
}
49
- export default Mechs ;
63
+
64
+
65
+ export default connect ( mapState ) ( Mechs ) ;
Original file line number Diff line number Diff line change @@ -7,10 +7,15 @@ import {getWeightClass} from "../mechSelectors";
7
7
const MechsListRow = ( { mech= { } } ) => {
8
8
const {
9
9
id = "" ,
10
- name = "" ,
11
10
type = "" ,
12
- weight = "" ,
11
+ mechType = { } ,
13
12
} = mech ;
13
+
14
+ const {
15
+ name = "" ,
16
+ weight = "" ,
17
+ } = mechType ;
18
+
14
19
const weightClass = getWeightClass ( weight ) ;
15
20
16
21
return (
@@ -35,4 +40,4 @@ const MechsListRow = ({mech={}}) => {
35
40
}
36
41
37
42
38
- export default MechsListRow ;
43
+ export default MechsListRow ;
You can’t perform that action at this time.
0 commit comments