LeagueStats/client/src/views/Summoner.vue

133 lines
3.3 KiB
Vue
Raw Normal View History

2019-03-30 22:55:48 +00:00
<template>
<div v-if="overviewLoaded" key="overview" class="mt-3 relative flex items-start text-center">
<div ref="sidebar" :class="{'fixed fixed-sidebar': fixedSidebar}" class="sidebar">
<SummonerChampions />
<SummonerStats />
<SummonerMates />
</div>
<div :class="{'pushed-container': fixedSidebar}" class="w-9/12">
<div v-if="current && current.participants" class="mb-4">
<LiveMatch />
</div>
<div v-if="overview.matches.length">
<ul>
<Match
v-for="(match, index) in overview.matches"
:key="index"
:data="overview.matches[index]"
:index-match="index"
/>
</ul>
<LoadingButton
v-if="moreMatchesToFetch"
@clicked="moreMatches"
:loading="matchesLoading"
btn-class="mt-4 block mx-auto bg-blue-800 px-4 py-2 rounded-md font-semibold hover:bg-blue-1000 shadow-lg"
>More matches</LoadingButton>
</div>
</div>
2019-03-30 22:55:48 +00:00
</div>
2020-01-01 16:04:55 +00:00
<div v-else>
<OverviewLoader />
2019-12-27 21:09:24 +00:00
</div>
2019-03-30 22:55:48 +00:00
</template>
2019-03-30 22:55:48 +00:00
<script>
2019-09-11 20:02:05 +00:00
import { mapState, mapActions, mapGetters } from 'vuex'
import LiveMatch from '@/components/Match/LiveMatch.vue'
import LoadingButton from '@/components/Form/LoadingButton.vue'
import Match from '@/components/Match/Match.vue'
2020-01-01 16:04:55 +00:00
import OverviewLoader from '@/components/Summoner/Overview/OverviewLoader.vue'
import SummonerChampions from '@/components/Summoner/Overview/SummonerChampions.vue'
import SummonerMates from '@/components/Summoner/Overview/SummonerMates.vue'
import SummonerStats from '@/components/Summoner/Overview/SummonerStats.vue'
2019-03-30 22:55:48 +00:00
export default {
components: {
LiveMatch,
LoadingButton,
2019-04-08 20:06:22 +00:00
Match,
2020-01-01 16:04:55 +00:00
OverviewLoader,
SummonerChampions,
SummonerMates,
SummonerStats,
2019-03-30 22:55:48 +00:00
},
2019-08-23 14:48:16 +00:00
data() {
return {
fixedSidebar: false,
sidebarRectangle: {
y: 354,
height: null,
},
}
},
2019-04-07 17:44:01 +00:00
computed: {
2019-09-08 20:08:49 +00:00
...mapState({
current: state => state.summoner.live.match,
overview: state => state.summoner.overview
2019-09-11 20:02:05 +00:00
}),
2019-12-27 21:09:24 +00:00
...mapGetters('summoner', ['matchesLoading', 'moreMatchesToFetch', 'overviewLoaded', 'summonerFound'])
},
watch: {
2020-02-01 19:17:14 +00:00
overviewLoaded() {
this.fetchData()
this.getSidebarHeight()
2020-02-01 19:17:14 +00:00
},
summonerFound() {
this.fetchData()
}
},
created() {
this.fetchData()
window.addEventListener('scroll', this.isSidebarFixed)
},
mounted() {
this.getSidebarHeight()
},
destroyed() {
window.removeEventListener('scroll', this.isSidebarFixed)
2019-08-23 14:48:16 +00:00
},
2019-03-30 22:55:48 +00:00
methods: {
fetchData() {
if (!this.overviewLoaded && this.summonerFound) {
this.overviewRequest()
}
},
getSidebarHeight() {
this.$nextTick(() => {
this.sidebarRectangle.height = this.$refs.sidebar ? this.$refs.sidebar.getBoundingClientRect().height : null
this.isSidebarFixed()
})
},
isSidebarFixed() {
if (!this.sidebarRectangle.height) return
this.fixedSidebar = window.innerHeight + document.documentElement.scrollTop > this.sidebarRectangle.y + this.sidebarRectangle.height + 112
},
...mapActions('summoner', ['moreMatches', 'overviewRequest']),
},
2019-08-23 14:48:16 +00:00
}
2019-03-30 22:55:48 +00:00
</script>
<style scoped>
.sidebar {
width: 300px;
}
.fixed-sidebar {
bottom: 112px;
}
.pushed-container {
margin-left: 300px;
}
</style>