Skip to content

Commit 4ec5bd3

Browse files
committed
Fixed bug with responses. Reading responses from firebase as dictionary now instead of array
1 parent 361f31b commit 4ec5bd3

File tree

3 files changed

+26
-16
lines changed

3 files changed

+26
-16
lines changed

src/components/responses/allResponsePreviews.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default class AllResponsePreviews extends React.Component {
77
super(props)
88
this.DBREF_STRING = "/joseSite/responses/"
99

10-
this.waitTime = 10000
10+
this.waitTime = 10 * 1000
1111
this.intervalID = ""
1212

1313
this.state = {
@@ -32,9 +32,13 @@ export default class AllResponsePreviews extends React.Component {
3232
.ref(this.DBREF_STRING)
3333
.once("value")
3434
.then(snapshot => {
35-
let dbValues = snapshot.val()
36-
dbValues = dbValues.filter(function (el) {
37-
return el !== undefined
35+
let dbObjects = snapshot.val()
36+
let dbValues = []
37+
Object.keys(dbObjects).forEach(dbKey => {
38+
let dbObject = dbObjects[dbKey]
39+
if (dbObject != undefined) {
40+
dbValues.push(dbObject)
41+
}
3842
})
3943
dbValues.forEach(response => {
4044
response["randomLeftPos"] = Math.random() * 90

src/pages/responses.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,20 @@ export default class Responses extends React.Component {
1818
.ref(this.DBREF_STRING)
1919
.once("value")
2020
.then(snapshot => {
21-
let dbValues = snapshot.val()
22-
dbValues = dbValues.filter(function (el) {
23-
return el !== undefined
21+
let dbObjects = snapshot.val()
22+
let dbValues = []
23+
Object.keys(dbObjects).forEach(dbKey => {
24+
let dbObject = dbObjects[dbKey]
25+
if (dbObject != undefined) {
26+
dbValues.push(dbObject)
27+
}
2428
})
2529
this.setState({ firebaseDataList: dbValues })
2630
})
2731
}
2832
renderResponses = () => {
29-
return this.state.firebaseDataList.map(response => (
30-
<div className={`${ResponseStyles.responseDetail} half`}>
33+
return this.state.firebaseDataList.map((response, index) => (
34+
<div className={`${ResponseStyles.responseDetail} half`} key={index}>
3135
<div className={ResponseStyles.author}> {response.author}</div>
3236
<div className={ResponseStyles.response}> {response.response}</div>
3337
</div>

src/styles/response.module.css

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,30 +41,32 @@
4141
position: fixed;
4242
bottom: 0px;
4343
font-size: 14px;
44-
padding-bottom: 32px;
44+
padding-bottom: 16px;
45+
padding-top: 16px;
4546
z-index: 2;
47+
background: var(--yellow);
48+
box-shadow: 0px 0px 12px 10px var(--yellow);
4649
}
4750

48-
.button,
4951
.responsePreview {
5052
background: var(--yellow);
5153
box-shadow: 0px 0px 12px 10px var(--yellow);
5254
cursor: pointer;
5355
padding: 4px;
5456
}
5557

58+
.button {
59+
cursor: pointer;
60+
font-size: 18px;
61+
}
62+
5663
.button:hover,
5764
.responsePreview:hover,
5865
.expandedResponsePreview {
5966
background: var(--lightYellow);
6067
box-shadow: 0px 0px 12px 10px var(--lightYellow);
6168
}
6269

63-
.button {
64-
padding-top: 12px;
65-
padding-bottom: 12px;
66-
}
67-
6870
.add {
6971
float: left;
7072
}

0 commit comments

Comments
 (0)