Skip to content

Commit

Permalink
adds leaderboard
Browse files Browse the repository at this point in the history
  • Loading branch information
sdellis committed Jul 29, 2018
1 parent eec9c5f commit 0ec8d96
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/pages/IsTree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
<p>Help us validate other users' images.</p>
<p>Current score: {{ profile.points }}</p>
<q-carousel ref="carousel">
<q-carousel-slide v-for="isTree in isTreeList" :key="isTree.datetime" >
<q-carousel-slide v-for="isTree in isTreeList" :key="isTree['.key']" >
<img class="slideImg" :src="isTree.s3url"/>
<p style="color:white">{{ isTree['.key'] }}</p>
</q-carousel-slide>
</q-carousel>
<p>Viewing {{ currentSlideIndex + 1 }} out of {{ isTreeList.length }}</p>
Expand Down Expand Up @@ -56,7 +57,7 @@ export default {
},
computed: {
isTreeList () {
return this.trees.filter(tree => tree.user_id !== this.userId)
return this.trees.filter(tree => tree.user_id !== this.userId).reverse()
},
profile: {
get () {
Expand Down
41 changes: 41 additions & 0 deletions src/pages/Leaderboard.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<template>
<q-page padding>
<div class="panel-body">
<h1>Top Scores</h1>
<div>
<div v-for="topUser in topUsers">
{{topUser.user_name}} : {{topUser.points}}
</div>
</div>
</div>
</q-page>
</template>
<script>
import { db } from '../plugins/firebase'
export default {
name: 'leaderboard',
firebase: {
leaders: db.ref('user_profiles').orderByChild('points').limitToLast(10)
},
computed: {
topUsers() {
// let topUsers = this.profiles.orderByChild('points').limitToLast(10)
// let topUsers = db.ref('user_profiles').sort(function (a, b) { return (a.points > b.points) ? 1 : ((b.points > a.points) ? -1 : 0) })
//topUsers = topUsers.slice(-3)
//return topUsers.reverse()
console.log(this.leaders)
return this.leaders.reverse()
}
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style>

h1 {
font-size: 30px;
padding-top:20px;
padding-bottom: 0px;
}

</style>
2 changes: 1 addition & 1 deletion src/pages/Profile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default {
let newProfile = Object.assign({}, this.profile)
newProfile.points = newProfile.points - this.spamToll
this.$store.dispatch('setProfile', newProfile)
this.profilesRef.child(this.userId).update({points: newProfile.points})
this.$profilesRef.child(this.userId).update({points: newProfile.points})
.then(this.removeFlagged())
},
photosFlaggedAlert () {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/tag.vue
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
save (formData) {
// upload data to the server
let key
let imageUrl
let s3url
this.currentStatus = STATUS_SAVING
this.$treesRef.push(this.tree)
Expand Down Expand Up @@ -209,7 +209,7 @@
})
.then(downloadURL => {
console.log(`Successfully uploaded file and got download link - ${downloadURL}`);
return this.$treesRef.child(key).update({imageUrl: downloadURL})
return this.$treesRef.child(key).update({s3url: downloadURL})
})
.then(() => {
//this.updateProfilePoints
Expand Down
2 changes: 2 additions & 0 deletions src/router/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export default [
requiresAuth: true }},
{ path: '/istree', component: () => import('pages/IsTree'), meta: {
requiresAuth: true }},
{ path: '/leaderboard', component: () => import('pages/Leaderboard'), meta: {
requiresAuth: true }},
{ path: '/profile', component: () => import('pages/Profile'), meta: {
requiresAuth: true }},
{ path: '/success', component: () => import('pages/Success'), meta: {
Expand Down

0 comments on commit 0ec8d96

Please sign in to comment.