LeagueStats/client/src/components/Summoner/RecentActivity.vue

146 lines
4.2 KiB
Vue
Raw Normal View History

2019-08-19 22:08:13 +00:00
<template>
<div>
<div class="inline-block bg-gradient rounded-lg p-3">
<h4 class="font-bold text-base text-white text-left">Recent Activity</h4>
<div class="flex">
<span class="ml-12 text-blue-200 font-semibold text-xs">{{ gridDays[11].month }}</span>
<span class="ml-16 text-blue-200 font-semibold text-xs">{{ gridDays[42].month }}</span>
<span class="ml-16 text-blue-200 font-semibold text-xs">{{ gridDays[73].month }}</span>
<span class="ml-16 text-blue-200 font-semibold text-xs">{{ gridDays[104].month }}</span>
</div>
<div class="mt-1 flex">
<div class="flex flex-col">
<span class="text-blue-200 font-semibold text-xs leading-snug">Mo</span>
<span class="text-blue-200 font-semibold text-xs leading-snug mt-1">Tu</span>
<span class="text-blue-200 font-semibold text-xs leading-snug mt-1">We</span>
<span class="text-blue-200 font-semibold text-xs leading-snug mt-1">Th</span>
<span class="text-blue-200 font-semibold text-xs leading-snug mt-1">Fr</span>
<span class="text-blue-200 font-semibold text-xs leading-snug mt-1">Sa</span>
<span class="text-blue-200 font-semibold text-xs leading-snug mt-1">Su</span>
</div>
<div
class="ml-2 flex flex-col flex-wrap"
style="width: calc(20px * 15); height: calc(20px * 7)"
>
<Dropdown v-for="(day, index) in gridDays.slice(indexFirstMonday)" :key="day.timestamp">
<template v-slot:trigger>
<div
:class="[getCaseMargin(index), getCaseColor(day.matches)]"
class="ml-1 w-4 h-4 cursor-pointer"
/>
</template>
<template v-slot:default>
<div class="px-2 text-white text-center text-xs">
<div>{{ day.date }}</div>
<div>
<span class="font-bold text-teal-400">{{ day.matches }}</span> game(s)
</div>
</div>
</template>
</Dropdown>
</div>
</div>
</div>
2019-08-19 22:08:13 +00:00
</div>
</template>
<script>
import Dropdown from '@/components/Dropdown.vue'
2019-08-19 22:08:13 +00:00
export default {
components: {
Dropdown,
},
2019-08-19 22:08:13 +00:00
props: {
matches: {
type: Array,
2019-09-08 20:08:49 +00:00
default() {
return []
}
2019-08-19 22:08:13 +00:00
}
},
data() {
2019-08-19 22:08:13 +00:00
return {
gridDays: [],
indexFirstMonday: 0,
2019-09-08 20:08:49 +00:00
nbColumns: 15,
options: {
year: 'numeric',
month: '2-digit',
day: 'numeric'
}
}
},
watch: {
matches() {
this.fillGrid()
2019-08-23 14:48:16 +00:00
}
},
created() {
this.createGrid()
2019-08-19 22:08:13 +00:00
},
methods: {
createGrid() {
2019-08-23 14:48:16 +00:00
const nbDaysInGrid = this.nbColumns * 7
2019-08-19 22:08:13 +00:00
// Create array with all the days of the Grid
for (let i = 1; i <= nbDaysInGrid; i++) {
2019-08-23 14:48:16 +00:00
const day = new Date()
day.setDate(day.getDate() - nbDaysInGrid + i)
2019-09-08 20:08:49 +00:00
const formattedDay = day.toLocaleString('fr', this.options)
this.gridDays.push({
date: formattedDay,
matches: 0,
2019-08-23 14:48:16 +00:00
day: day.toLocaleString('en', { weekday: 'long' }).substring(0, 2),
month: day.toLocaleString('en', { month: 'long' }).substring(0, 3)
})
}
2019-09-08 20:08:49 +00:00
this.fillGrid()
},
fillGrid() {
// Add all the matches made by the summoner
for (const key in this.matches) {
2019-08-23 14:48:16 +00:00
const match = this.matches[key]
const matchTime = new Date(match.timestamp)
2019-09-08 20:08:49 +00:00
const formattedTime = matchTime.toLocaleString('fr', this.options)
const dayOfTheMatch = this.gridDays.filter(
e => e.date === formattedTime
2019-08-23 14:48:16 +00:00
)
if (dayOfTheMatch.length > 0) {
2019-08-23 14:48:16 +00:00
dayOfTheMatch[0].matches++
}
}
// Get the index of the first Monday
2019-08-23 14:48:16 +00:00
this.indexFirstMonday = this.gridDays.findIndex(d => d.day === 'Mo')
},
getCaseColor(nbMatches) {
/* TODO: change this */
if (nbMatches >= 6) {
2019-08-23 14:48:16 +00:00
return 'bg-teal-200'
} else if (nbMatches >= 4) {
2019-08-23 14:48:16 +00:00
return 'bg-teal-300'
} else if (nbMatches >= 2) {
2019-08-23 14:48:16 +00:00
return 'bg-teal-400'
} else if (nbMatches >= 1) {
2019-08-23 14:48:16 +00:00
return 'bg-teal-500'
}
2019-08-23 14:48:16 +00:00
return 'bg-teal-700'
},
getCaseMargin(index) {
if (index % 7 !== 0) {
2019-08-23 14:48:16 +00:00
return 'mt-1'
2019-08-19 22:08:13 +00:00
}
}
}
2019-08-23 14:48:16 +00:00
}
2019-09-08 20:08:49 +00:00
</script>