Render user's time top, average and median score
There should be dropdown to allow the user to see top, average and median from a time range:
- Last 24 hours
- Last month
- All time
User sessions are stored in
|
async saveScore() { |
|
try { |
|
const { user } = this.props; |
|
if (!user.uid) return this.setState({ authError: true }); |
|
this.setState({ authError: false, error: '' }); |
|
|
|
const { score } = this.state; |
|
|
|
// a string in the format 2018-10-26 |
|
const sessionId = (new Date()).toISOString().slice(0,10); |
|
|
|
// store record in Firebase |
|
await firebase |
|
.database() |
|
.ref('user-score') |
|
.child(user.uid) |
|
.child(sessionId) |
|
.push({ |
|
score, |
|
timestamp: firebase.database.ServerValue.TIMESTAMP |
|
}); |
|
|
|
this.updateScoreboard(user, score) |
|
|
|
} catch (err) { |
|
console.error(err); |
|
this.setState({ |
|
error: |
|
'Something went wrong while saving score, please contact support!' |
|
}); |
|
} |
|
} |
Render user's time top, average and median score
There should be dropdown to allow the user to see top, average and median from a time range:
User sessions are stored in
typist/src/Main/index.js
Lines 187 to 218 in 1f8c297