2023-12-23 22:29:34 +01:00
|
|
|
<template>
|
2023-12-23 23:39:56 +01:00
|
|
|
<div class="bg-bg rounded-md shadow-lg border border-white border-opacity-5 p-1 sm:p-4 mb-4">
|
2023-12-23 22:29:34 +01:00
|
|
|
<!-- hack to get icon fonts loaded on init -->
|
|
|
|
<div class="h-0 w-0 overflow-hidden opacity-0">
|
2024-08-16 23:57:17 +02:00
|
|
|
<span class="material-symbols">close</span>
|
2023-12-23 22:29:34 +01:00
|
|
|
<span class="abs-icons icon-audiobookshelf" />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="flex items-center">
|
2024-12-16 23:44:06 +01:00
|
|
|
<h1 class="hidden md:block text-xl font-semibold">{{ $getString('HeaderYearReview', [yearInReviewYear]) }}</h1>
|
2023-12-23 22:29:34 +01:00
|
|
|
<div class="hidden md:block flex-grow" />
|
2024-07-08 18:36:37 +02:00
|
|
|
<ui-btn class="w-full md:w-auto" @click.stop="clickShowYearInReview">{{ showYearInReview ? $strings.LabelYearReviewHide : $strings.LabelYearReviewShow }}</ui-btn>
|
2023-12-23 22:29:34 +01:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- your year in review -->
|
|
|
|
<div v-if="showYearInReview">
|
|
|
|
<div class="w-full h-px bg-slate-200/10 my-4" />
|
|
|
|
|
2024-12-16 23:44:06 +01:00
|
|
|
<div v-if="availableYears.length > 1" class="mb-2 py-2 max-w-[800px] mx-auto">
|
|
|
|
<!-- year selector -->
|
|
|
|
<ui-dropdown v-model="yearInReviewYear" small :items="availableYears" :disabled="processingYearInReview" class="max-w-24" @input="yearInReviewYearChanged" />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div role="toolbar" class="flex items-center justify-center mb-2 max-w-[800px] mx-auto">
|
2023-12-23 22:29:34 +01:00
|
|
|
<!-- previous button -->
|
2024-12-16 23:44:06 +01:00
|
|
|
<ui-btn small :disabled="!yearInReviewVariant || processingYearInReview" :aria-label="$strings.ButtonPrevious" class="inline-flex items-center font-semibold" @click="yearInReviewVariant--">
|
2024-07-08 18:36:37 +02:00
|
|
|
<span class="material-symbols text-lg sm:pr-1 py-px sm:py-0">chevron_left</span>
|
2024-02-22 00:36:43 +01:00
|
|
|
<span class="hidden sm:inline-block pr-2">{{ $strings.ButtonPrevious }}</span>
|
2023-12-23 22:29:34 +01:00
|
|
|
</ui-btn>
|
|
|
|
<!-- share button -->
|
2024-12-16 23:44:06 +01:00
|
|
|
<ui-btn v-if="showShareButton" small :disabled="processingYearInReview" class="inline-flex items-center font-semibold ml-1 sm:ml-2" @click="shareYearInReview">{{ $strings.ButtonShare }} </ui-btn>
|
2023-12-23 22:29:34 +01:00
|
|
|
|
|
|
|
<div class="flex-grow" />
|
2024-12-16 23:44:06 +01:00
|
|
|
<h2 class="hidden sm:block text-lg font-semibold">{{ $getString('LabelPersonalYearReview', [yearInReviewVariant + 1]) }}</h2>
|
2023-12-23 23:39:56 +01:00
|
|
|
<p class="block sm:hidden text-lg font-semibold">{{ yearInReviewVariant + 1 }}</p>
|
2023-12-23 22:29:34 +01:00
|
|
|
<div class="flex-grow" />
|
|
|
|
|
|
|
|
<!-- refresh button -->
|
|
|
|
<ui-btn small :disabled="processingYearInReview" class="inline-flex items-center font-semibold mr-1 sm:mr-2" @click="refreshYearInReview">
|
2024-02-22 00:36:43 +01:00
|
|
|
<span class="hidden sm:inline-block">{{ $strings.ButtonRefresh }}</span>
|
2024-07-08 18:36:37 +02:00
|
|
|
<span class="material-symbols sm:!hidden text-lg py-px">refresh</span>
|
2023-12-23 22:29:34 +01:00
|
|
|
</ui-btn>
|
|
|
|
<!-- next button -->
|
2024-12-16 23:44:06 +01:00
|
|
|
<ui-btn small :disabled="yearInReviewVariant >= 2 || processingYearInReview" :aria-label="$strings.ButtonNext" class="inline-flex items-center font-semibold" @click="yearInReviewVariant++">
|
2024-02-22 00:36:43 +01:00
|
|
|
<span class="hidden sm:inline-block pl-2">{{ $strings.ButtonNext }}</span>
|
2024-08-16 23:57:17 +02:00
|
|
|
<span class="material-symbols text-lg sm:pl-1 py-px sm:py-0">chevron_right</span>
|
2023-12-23 22:29:34 +01:00
|
|
|
</ui-btn>
|
|
|
|
</div>
|
|
|
|
<stats-year-in-review ref="yearInReview" :variant="yearInReviewVariant" :year="yearInReviewYear" :processing.sync="processingYearInReview" />
|
|
|
|
|
|
|
|
<!-- your year in review short -->
|
|
|
|
<div class="w-full max-w-[800px] mx-auto my-4">
|
2023-12-23 23:39:56 +01:00
|
|
|
<!-- share button -->
|
2024-12-16 23:44:06 +01:00
|
|
|
<ui-btn v-if="showShareButton" small :disabled="processingYearInReviewShort" class="inline-flex items-center font-semibold mb-1" @click="shareYearInReviewShort">{{ $strings.ButtonShare }}</ui-btn>
|
2023-12-23 22:29:34 +01:00
|
|
|
<stats-year-in-review-short ref="yearInReviewShort" :year="yearInReviewYear" :processing.sync="processingYearInReviewShort" />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- your server in review -->
|
2024-12-16 23:44:06 +01:00
|
|
|
<div v-if="isAdminOrUp" role="toolbar" class="w-full max-w-[800px] mx-auto mb-2 mt-4 border-t pt-4 border-white/10">
|
2023-12-23 22:29:34 +01:00
|
|
|
<div class="flex items-center justify-center mb-2">
|
|
|
|
<!-- previous button -->
|
2024-12-16 23:44:06 +01:00
|
|
|
<ui-btn small :disabled="!yearInReviewServerVariant || processingYearInReviewServer" :aria-label="$strings.ButtonPrevious" class="inline-flex items-center font-semibold" @click="yearInReviewServerVariant--">
|
2024-07-08 18:36:37 +02:00
|
|
|
<span class="material-symbols text-lg sm:pr-1 py-px sm:py-0">chevron_left</span>
|
2024-02-22 00:36:43 +01:00
|
|
|
<span class="hidden sm:inline-block pr-2">{{ $strings.ButtonPrevious }}</span>
|
2023-12-23 22:29:34 +01:00
|
|
|
</ui-btn>
|
|
|
|
<!-- share button -->
|
2024-12-16 23:44:06 +01:00
|
|
|
<ui-btn v-if="showShareButton" small :disabled="processingYearInReviewServer" class="inline-flex items-center font-semibold ml-1 sm:ml-2" @click="shareYearInReviewServer">{{ $strings.ButtonShare }} </ui-btn>
|
2023-12-23 22:29:34 +01:00
|
|
|
|
|
|
|
<div class="flex-grow" />
|
2024-12-16 23:44:06 +01:00
|
|
|
<h2 class="hidden sm:block text-lg font-semibold">{{ $getString('LabelServerYearReview', [yearInReviewServerVariant + 1]) }}</h2>
|
2023-12-23 23:39:56 +01:00
|
|
|
<p class="block sm:hidden text-lg font-semibold">{{ yearInReviewServerVariant + 1 }}</p>
|
2023-12-23 22:29:34 +01:00
|
|
|
<div class="flex-grow" />
|
|
|
|
|
|
|
|
<!-- refresh button -->
|
|
|
|
<ui-btn small :disabled="processingYearInReviewServer" class="inline-flex items-center font-semibold mr-1 sm:mr-2" @click="refreshYearInReviewServer">
|
2024-02-22 00:36:43 +01:00
|
|
|
<span class="hidden sm:inline-block">{{ $strings.ButtonRefresh }}</span>
|
2024-07-08 18:36:37 +02:00
|
|
|
<span class="material-symbols sm:!hidden text-lg py-px">refresh</span>
|
2023-12-23 22:29:34 +01:00
|
|
|
</ui-btn>
|
|
|
|
<!-- next button -->
|
2024-12-16 23:44:06 +01:00
|
|
|
<ui-btn small :disabled="yearInReviewServerVariant >= 2 || processingYearInReviewServer" :aria-label="$strings.ButtonNext" class="inline-flex items-center font-semibold" @click="yearInReviewServerVariant++">
|
2024-02-22 00:36:43 +01:00
|
|
|
<span class="hidden sm:inline-block pl-2">{{ $strings.ButtonNext }}</span>
|
2024-08-16 23:57:17 +02:00
|
|
|
<span class="material-symbols text-lg sm:pl-1 py-px sm:py-0">chevron_right</span>
|
2023-12-23 22:29:34 +01:00
|
|
|
</ui-btn>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<stats-year-in-review-server v-if="isAdminOrUp" ref="yearInReviewServer" :year="yearInReviewYear" :variant="yearInReviewServerVariant" :processing.sync="processingYearInReviewServer" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
showYearInReview: false,
|
2024-12-16 23:44:06 +01:00
|
|
|
availableYears: [],
|
2023-12-23 22:29:34 +01:00
|
|
|
yearInReviewYear: 0,
|
|
|
|
yearInReviewVariant: 0,
|
|
|
|
yearInReviewServerVariant: 0,
|
|
|
|
processingYearInReview: false,
|
|
|
|
processingYearInReviewShort: false,
|
|
|
|
processingYearInReviewServer: false,
|
|
|
|
showShareButton: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
isAdminOrUp() {
|
|
|
|
return this.$store.getters['user/getIsAdminOrUp']
|
2024-12-16 23:44:06 +01:00
|
|
|
},
|
|
|
|
user() {
|
|
|
|
return this.$store.state.user.user
|
2023-12-23 22:29:34 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
shareYearInReviewServer() {
|
|
|
|
this.$refs.yearInReviewServer.share()
|
|
|
|
},
|
|
|
|
shareYearInReview() {
|
|
|
|
this.$refs.yearInReview.share()
|
|
|
|
},
|
2023-12-23 23:39:56 +01:00
|
|
|
shareYearInReviewShort() {
|
|
|
|
this.$refs.yearInReviewShort.share()
|
|
|
|
},
|
2024-12-16 23:44:06 +01:00
|
|
|
yearInReviewYearChanged() {
|
|
|
|
this.$nextTick(() => {
|
|
|
|
this.refreshYearInReview()
|
|
|
|
this.refreshYearInReviewServer()
|
|
|
|
})
|
|
|
|
},
|
2023-12-23 22:29:34 +01:00
|
|
|
refreshYearInReviewServer() {
|
2024-12-16 23:44:06 +01:00
|
|
|
if (this.$refs.yearInReviewServer != null) {
|
|
|
|
this.$refs.yearInReviewServer.refresh()
|
|
|
|
}
|
2023-12-23 22:29:34 +01:00
|
|
|
},
|
|
|
|
refreshYearInReview() {
|
2024-12-16 23:44:06 +01:00
|
|
|
if (this.$refs.yearInReview != null && this.$refs.yearInReviewShort != null) {
|
|
|
|
this.$refs.yearInReview.refresh()
|
|
|
|
this.$refs.yearInReviewShort.refresh()
|
|
|
|
}
|
2023-12-23 22:29:34 +01:00
|
|
|
},
|
|
|
|
clickShowYearInReview() {
|
|
|
|
this.showYearInReview = !this.showYearInReview
|
2024-12-16 23:44:06 +01:00
|
|
|
},
|
|
|
|
getAvailableYears() {
|
|
|
|
if (this.user) {
|
|
|
|
const oldestDate = this.user.createdAt
|
|
|
|
if (oldestDate) {
|
|
|
|
const date = new Date(oldestDate)
|
|
|
|
const oldestYear = date.getFullYear()
|
|
|
|
const currentYear = new Date().getFullYear()
|
|
|
|
|
|
|
|
const years = []
|
|
|
|
for (let year = currentYear; year >= oldestYear; year--) {
|
|
|
|
years.push({ value: year, text: year.toString() })
|
|
|
|
}
|
|
|
|
|
|
|
|
return years
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Fallback on error
|
|
|
|
return [{ value: this.yearInReviewYear, text: this.yearInReviewYear.toString() }]
|
2023-12-23 22:29:34 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
beforeMount() {
|
|
|
|
this.yearInReviewYear = new Date().getFullYear()
|
2024-12-16 23:44:06 +01:00
|
|
|
|
2023-12-23 22:29:34 +01:00
|
|
|
// When not December show previous year
|
|
|
|
if (new Date().getMonth() < 11) {
|
|
|
|
this.yearInReviewYear--
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
2024-12-16 23:44:06 +01:00
|
|
|
this.availableYears = this.getAvailableYears()
|
|
|
|
|
2023-12-23 22:29:34 +01:00
|
|
|
if (typeof navigator.share !== 'undefined' && navigator.share) {
|
|
|
|
this.showShareButton = true
|
|
|
|
} else {
|
|
|
|
console.warn('Navigator.share not supported')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-08-16 23:57:17 +02:00
|
|
|
</script>
|