Skip to content

Commit 15908e9

Browse files
author
Alexandra Janin
committed
Change note total source
1 parent 2b2ecc5 commit 15908e9

File tree

12 files changed

+178
-40
lines changed

12 files changed

+178
-40
lines changed

src/actions/Talks.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export const loadTalks = () => dispatch => {
3030
.then(response => {
3131
const values = response.valueRanges[0].values;
3232
if (values.length > 0) {
33-
console.log(values);
3433
const talks = parseTalks(values);
3534
dispatch(fetchedTalks(talks));
3635
} else {

src/components/AppView.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ class AppView extends Component {
7373
count,
7474
selectedTalk,
7575
permission,
76-
filteredTalks
76+
filteredTalks,
77+
notes
7778
} = this.props;
7879

7980
if (loader) {
@@ -99,6 +100,7 @@ class AppView extends Component {
99100
style={{position: 'relative'}}>
100101
<TalkList
101102
selectedTalk={selectedTalk}
103+
notes={notes}
102104
count={count}
103105
talks={filteredTalks}
104106
selectTalk={id => this.props.selectTalk(id)}

src/components/NotesView.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class NotesView extends Component {
6464
}
6565

6666
getDetailsNote() {
67+
console.log(this.props);
6768
if (!this.state.voteOpen) {
6869
return null;
6970
}

src/components/TalkList.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,21 @@ class TalkList extends Component {
5959
}
6060

6161
getTalk(talk, i) {
62-
return (
63-
<ListItem
64-
key={i}
65-
value={i}
66-
onTouchTap={() => this.props.selectTalk(talk.id)}
67-
primaryText={talk.titre_de_ta_presentation}
68-
secondaryText={talk.prenom_et_nom}
69-
rightIcon={<span>{Math.round(talk.note)}</span>}
70-
leftAvatar={this.getFormat(talk.formats)}
71-
/>
72-
)
62+
if (this.props.notes !== null) {
63+
return (
64+
<ListItem
65+
key={i}
66+
value={i}
67+
onTouchTap={() => this.props.selectTalk(talk.id)}
68+
primaryText={talk.titre_de_ta_presentation}
69+
secondaryText={talk.prenom_et_nom}
70+
rightIcon={<span>{this.props.notes[i].total}</span>}
71+
leftAvatar={this.getFormat(talk.formats)}
72+
/>
73+
)
74+
}
75+
76+
return null;
7377
}
7478

7579
render() {

src/components/TalkList.test.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,24 @@ const talks = [
2323
}
2424
];
2525

26+
const notes = [
27+
{ values: { "A": 1, "B": 0 , "C": 0}, total: 1 },
28+
{ values: { "A": 1, "B": 0 , "C": 0}, total: 1 },
29+
{ values: {"A": 0, "B": 0, "C": 0}, total: 0 }
30+
];
31+
2632
describe('TalkList component', () => {
2733
it('should renders correctly', () => {
28-
const sortTalks = jest.fn(()=>Promise.resolve(0))
29-
const setFilter = jest.fn(()=>Promise.resolve(0))
30-
const selectTalk = jest.fn(()=>Promise.resolve(0))
34+
const sortTalks = jest.fn(()=>Promise.resolve(0));
35+
const setFilter = jest.fn(()=>Promise.resolve(0));
36+
const selectTalk = jest.fn(()=>Promise.resolve(0));
3137

3238
const component = shallow(
3339
<TalkList
3440
selectedTalk={0}
3541
count={{'all': 3, 'PK': 2, 'PK': 1}}
3642
talks={talks}
43+
notes={notes}
3744
selectTalk={id => selectTalk(id)}
3845
setFilter={format => setFilter(format)}
3946
// sortBy={this.props.sortBy}

src/components/__snapshots__/AppView.test.js.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ ShallowWrapper {
5555
"all": 3,
5656
}
5757
}
58+
notes={undefined}
5859
selectTalk={[Function]}
5960
selectedTalk={0}
6061
setFilter={[Function]}
@@ -122,6 +123,7 @@ ShallowWrapper {
122123
"all": 3,
123124
}
124125
}
126+
notes={undefined}
125127
selectTalk={[Function]}
126128
selectedTalk={0}
127129
setFilter={[Function]}
@@ -251,6 +253,7 @@ ShallowWrapper {
251253
"all": 3,
252254
}
253255
}
256+
notes={undefined}
254257
selectTalk={[Function]}
255258
selectedTalk={0}
256259
setFilter={[Function]}
@@ -318,6 +321,7 @@ ShallowWrapper {
318321
"all": 3,
319322
}
320323
}
324+
notes={undefined}
321325
selectTalk={[Function]}
322326
selectedTalk={0}
323327
setFilter={[Function]}

src/components/__snapshots__/TalkList.test.js.snap

Lines changed: 122 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ ShallowWrapper {
9393
open={null}
9494
primaryText="Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolores, esse."
9595
primaryTogglesNestedList={false}
96-
rightIcon={<span />}
96+
rightIcon={
97+
<span>
98+
1
99+
</span>
100+
}
97101
secondaryText="Alexandra Janin"
98102
secondaryTextLines={1}
99103
value={0} />
@@ -122,7 +126,11 @@ ShallowWrapper {
122126
open={null}
123127
primaryText="Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolores, esse."
124128
primaryTogglesNestedList={false}
125-
rightIcon={<span />}
129+
rightIcon={
130+
<span>
131+
1
132+
</span>
133+
}
126134
secondaryText="Alexandra Janin"
127135
secondaryTextLines={1}
128136
value={1} />
@@ -239,7 +247,11 @@ ShallowWrapper {
239247
open={null}
240248
primaryText="Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolores, esse."
241249
primaryTogglesNestedList={false}
242-
rightIcon={<span />}
250+
rightIcon={
251+
<span>
252+
1
253+
</span>
254+
}
243255
secondaryText="Alexandra Janin"
244256
secondaryTextLines={1}
245257
value={0} />
@@ -268,7 +280,11 @@ ShallowWrapper {
268280
open={null}
269281
primaryText="Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolores, esse."
270282
primaryTogglesNestedList={false}
271-
rightIcon={<span />}
283+
rightIcon={
284+
<span>
285+
1
286+
</span>
287+
}
272288
secondaryText="Alexandra Janin"
273289
secondaryTextLines={1}
274290
value={1} />
@@ -311,6 +327,34 @@ ShallowWrapper {
311327
"all": 3,
312328
}
313329
}
330+
notes={
331+
Array [
332+
Object {
333+
"total": 1,
334+
"values": Object {
335+
"A": 1,
336+
"B": 0,
337+
"C": 0,
338+
},
339+
},
340+
Object {
341+
"total": 1,
342+
"values": Object {
343+
"A": 1,
344+
"B": 0,
345+
"C": 0,
346+
},
347+
},
348+
Object {
349+
"total": 0,
350+
"values": Object {
351+
"A": 0,
352+
"B": 0,
353+
"C": 0,
354+
},
355+
},
356+
]
357+
}
314358
selectTalk={[Function]}
315359
selectedTalk={0}
316360
setFilter={[Function]}
@@ -344,6 +388,32 @@ ShallowWrapper {
344388
"PK": 1,
345389
"all": 3,
346390
},
391+
"notes": Array [
392+
Object {
393+
"total": 1,
394+
"values": Object {
395+
"A": 1,
396+
"B": 0,
397+
"C": 0,
398+
},
399+
},
400+
Object {
401+
"total": 1,
402+
"values": Object {
403+
"A": 1,
404+
"B": 0,
405+
"C": 0,
406+
},
407+
},
408+
Object {
409+
"total": 0,
410+
"values": Object {
411+
"A": 0,
412+
"B": 0,
413+
"C": 0,
414+
},
415+
},
416+
],
347417
"selectTalk": [Function],
348418
"selectedTalk": 0,
349419
"setFilter": [Function],
@@ -472,7 +542,11 @@ ShallowWrapper {
472542
open={null}
473543
primaryText="Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolores, esse."
474544
primaryTogglesNestedList={false}
475-
rightIcon={<span />}
545+
rightIcon={
546+
<span>
547+
1
548+
</span>
549+
}
476550
secondaryText="Alexandra Janin"
477551
secondaryTextLines={1}
478552
value={0} />
@@ -501,7 +575,11 @@ ShallowWrapper {
501575
open={null}
502576
primaryText="Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolores, esse."
503577
primaryTogglesNestedList={false}
504-
rightIcon={<span />}
578+
rightIcon={
579+
<span>
580+
1
581+
</span>
582+
}
505583
secondaryText="Alexandra Janin"
506584
secondaryTextLines={1}
507585
value={1} />
@@ -618,7 +696,11 @@ ShallowWrapper {
618696
open={null}
619697
primaryText="Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolores, esse."
620698
primaryTogglesNestedList={false}
621-
rightIcon={<span />}
699+
rightIcon={
700+
<span>
701+
1
702+
</span>
703+
}
622704
secondaryText="Alexandra Janin"
623705
secondaryTextLines={1}
624706
value={0} />
@@ -647,7 +729,11 @@ ShallowWrapper {
647729
open={null}
648730
primaryText="Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolores, esse."
649731
primaryTogglesNestedList={false}
650-
rightIcon={<span />}
732+
rightIcon={
733+
<span>
734+
1
735+
</span>
736+
}
651737
secondaryText="Alexandra Janin"
652738
secondaryTextLines={1}
653739
value={1} />
@@ -694,6 +780,34 @@ ShallowWrapper {
694780
"all": 3,
695781
}
696782
}
783+
notes={
784+
Array [
785+
Object {
786+
"total": 1,
787+
"values": Object {
788+
"A": 1,
789+
"B": 0,
790+
"C": 0,
791+
},
792+
},
793+
Object {
794+
"total": 1,
795+
"values": Object {
796+
"A": 1,
797+
"B": 0,
798+
"C": 0,
799+
},
800+
},
801+
Object {
802+
"total": 0,
803+
"values": Object {
804+
"A": 0,
805+
"B": 0,
806+
"C": 0,
807+
},
808+
},
809+
]
810+
}
697811
selectTalk={[Function]}
698812
selectedTalk={0}
699813
setFilter={[Function]}

src/containers/Notes.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import {
77
import { vote } from '../actions/Notes';
88

99
const mapStateToProps = state => {
10-
const notes = state.notes[state.selectedTalk];
10+
const notes = state.notes[state.selectedTalk].values;
11+
1112
return {
1213
ownName: state.ownName,
1314
ownNote: getOwnNote(notes, state.ownName),
1415
myProfileName: state.profile.name,
1516
othersNote: getOthersNote(notes, state.ownName),
16-
globalNote: state.talks[state.selectedTalk].note
17+
globalNote: state.notes[state.selectedTalk].total
1718
};
1819
}
1920

src/reducers/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export const rootReducer = (state = defaultState, action) => {
7373
};
7474

7575
case FETCHED_NOTES:
76-
const ownName = getOwnName(action.notes[0], state.profile.name);
76+
const ownName = getOwnName(action.notes[0].values, state.profile.name);
7777
return {
7878
...state,
7979
loader: false,

src/reducers/index.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ describe('rootReducer', () => {
7676

7777
it('should change state start if action.type is FETCHED_NOTES', () => {
7878
const baseState = {loader: false, notes: null, ownName: null, profile: {name: 'alex'}};
79-
const expectedState = {loader: false, notes: [{alex: 0}], ownName: 'alex', profile: {name: 'alex'}};
79+
const expectedState = {loader: false, notes: [{values: {alex: 0}, total: 0}], ownName: 'alex', profile: {name: 'alex'}};
8080

81-
const testAction = {type: FETCHED_NOTES, notes: [{alex: 0}]};
81+
const testAction = {type: FETCHED_NOTES, notes: [{values: {alex: 0}, total: 0}]};
8282
expect(rootReducer(baseState, testAction)).toEqual(expectedState);
8383
});
8484

0 commit comments

Comments
 (0)