2023-03-19 19:51:55 -04:00
|
|
|
<script lang="ts">
|
2023-06-19 23:18:10 -04:00
|
|
|
import { ref } from 'vue'
|
|
|
|
|
2023-03-31 07:50:46 -04:00
|
|
|
import StreamPreviewVue from '@/components/StreamPreview.vue'
|
2023-04-10 00:12:52 -04:00
|
|
|
import ErrorMessage from '@/components/ErrorMessage.vue'
|
|
|
|
import LoadingScreen from '@/components/LoadingScreen.vue'
|
2023-03-19 19:51:55 -04:00
|
|
|
|
2023-06-19 23:18:10 -04:00
|
|
|
import type { CategoryData } from '@/types'
|
|
|
|
import { getEndpoint, abbreviate } from '@/mixins'
|
|
|
|
|
2023-03-24 18:48:45 -04:00
|
|
|
export default {
|
2023-05-12 10:21:31 -04:00
|
|
|
inject: ['protocol'],
|
2023-03-19 19:51:55 -04:00
|
|
|
async setup() {
|
2023-06-19 23:18:10 -04:00
|
|
|
let data = ref<CategoryData>()
|
2023-07-20 13:57:01 -04:00
|
|
|
let status = ref<'ok' | 'error'>()
|
2023-04-08 20:04:28 -04:00
|
|
|
|
2023-03-19 19:51:55 -04:00
|
|
|
return {
|
2023-03-24 18:48:45 -04:00
|
|
|
data,
|
2023-06-19 23:18:10 -04:00
|
|
|
status
|
2023-03-19 19:51:55 -04:00
|
|
|
}
|
|
|
|
},
|
2023-04-10 00:12:52 -04:00
|
|
|
async mounted() {
|
2023-09-16 11:33:25 -04:00
|
|
|
await getEndpoint('api/discover/' + encodeURIComponent(this.$route.params.game.toString()))
|
2023-07-20 13:57:01 -04:00
|
|
|
.catch(() => {
|
|
|
|
this.status = 'error'
|
|
|
|
})
|
|
|
|
.then((data: CategoryData) => {
|
|
|
|
this.data = data
|
|
|
|
})
|
2023-04-11 14:27:43 -04:00
|
|
|
|
2023-08-18 13:28:43 -04:00
|
|
|
window.onscroll = this.getMoreStreams
|
|
|
|
},
|
|
|
|
beforeUnmount() {
|
|
|
|
window.onscroll = null
|
2023-04-10 00:12:52 -04:00
|
|
|
},
|
2023-03-19 19:51:55 -04:00
|
|
|
methods: {
|
2023-08-18 13:28:43 -04:00
|
|
|
async getMoreStreams() {
|
2023-08-18 13:39:26 -04:00
|
|
|
let bottomOfWindow =
|
|
|
|
document.documentElement.scrollTop + window.innerHeight ===
|
|
|
|
document.documentElement.offsetHeight
|
|
|
|
const streams = this.data!.streams
|
2023-06-19 23:18:10 -04:00
|
|
|
|
2023-08-18 13:39:26 -04:00
|
|
|
if (bottomOfWindow && streams) {
|
|
|
|
// get cursor of the last stream rendered
|
|
|
|
const cursor = streams[streams.length - 1].cursor
|
|
|
|
if (!cursor) return
|
2023-04-11 14:27:43 -04:00
|
|
|
|
2023-08-18 13:39:26 -04:00
|
|
|
// get rest of streams from api
|
|
|
|
const resData: CategoryData = await getEndpoint(
|
|
|
|
`api/discover/${this.$route.params.game}?cursor=${cursor}`
|
|
|
|
).catch((err) => {
|
|
|
|
throw err
|
|
|
|
})
|
2023-06-19 23:18:10 -04:00
|
|
|
|
2023-08-18 13:39:26 -04:00
|
|
|
let lastStreamCursor = this.data!.streams[this.data!.streams.length - 1].cursor
|
|
|
|
let newLastStreamCursor = resData.streams[resData.streams.length - 1].cursor
|
|
|
|
if (lastStreamCursor === newLastStreamCursor) {
|
|
|
|
// Add "no more streams!" screen later
|
|
|
|
console.log('no more streams!')
|
|
|
|
} else {
|
|
|
|
for (let stream of resData.streams) {
|
|
|
|
this.data!.streams.push(stream)
|
2023-04-11 14:27:43 -04:00
|
|
|
}
|
|
|
|
}
|
2023-08-18 13:39:26 -04:00
|
|
|
}
|
2023-04-11 14:27:43 -04:00
|
|
|
},
|
2023-07-20 13:57:01 -04:00
|
|
|
abbreviate
|
2023-03-31 07:50:46 -04:00
|
|
|
},
|
|
|
|
components: {
|
2023-04-10 00:12:52 -04:00
|
|
|
StreamPreviewVue,
|
|
|
|
ErrorMessage,
|
|
|
|
LoadingScreen
|
2023-03-19 19:51:55 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2023-06-19 23:18:10 -04:00
|
|
|
<loading-screen v-if="!data && status != 'error'"></loading-screen>
|
|
|
|
<error-message v-else-if="status == 'error'"></error-message>
|
2023-04-10 00:12:52 -04:00
|
|
|
|
2023-06-19 23:18:10 -04:00
|
|
|
<div v-else-if="data" class="flex flex-col max-w-5xl mx-auto">
|
2023-04-11 13:52:19 -04:00
|
|
|
<div class="flex p-3 flex-col">
|
|
|
|
<div class="inline-flex space-x-4">
|
|
|
|
<img :src="data.cover" class="self-start rounded-md" />
|
2023-03-19 19:51:55 -04:00
|
|
|
|
2023-04-11 13:52:19 -04:00
|
|
|
<div>
|
|
|
|
<h1 class="font-bold text-5xl text-white">{{ data.name }}</h1>
|
|
|
|
<div class="hidden md:block">
|
|
|
|
<div>
|
|
|
|
<div class="inline-flex my-1 space-x-3">
|
2023-07-20 13:57:01 -04:00
|
|
|
<p class="font-bold text-white text-lg">
|
|
|
|
{{ $t('main.followers') }}: {{ abbreviate(data.followers) }}
|
|
|
|
</p>
|
|
|
|
<p class="font-bold text-white text-lg">
|
|
|
|
{{ $t('main.viewers') }}: {{ abbreviate(data.viewers) }}
|
|
|
|
</p>
|
2023-04-11 13:52:19 -04:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<ul class="mb-5">
|
|
|
|
<li v-for="tag in data.tags" :key="tag" class="inline-flex">
|
2023-07-20 13:57:01 -04:00
|
|
|
<span
|
2023-09-24 11:47:48 -04:00
|
|
|
class="text-white p-1 py-0.5 mr-1 text-sm font-bold bg-overlay1 rounded-sm"
|
2023-07-20 13:57:01 -04:00
|
|
|
>{{ tag }}</span
|
|
|
|
>
|
2023-04-11 13:52:19 -04:00
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-07-20 13:57:01 -04:00
|
|
|
<p class="text-md text-gray-400 overflow-y-auto hidden md:block">
|
|
|
|
{{ data.description }}
|
|
|
|
</p>
|
2023-03-19 19:51:55 -04:00
|
|
|
</div>
|
2023-04-11 13:52:19 -04:00
|
|
|
</div>
|
2023-03-19 19:51:55 -04:00
|
|
|
|
2023-04-11 13:52:19 -04:00
|
|
|
<div class="md:hidden">
|
|
|
|
<div>
|
|
|
|
<div class="inline-flex my-1 space-x-3">
|
2023-07-20 13:57:01 -04:00
|
|
|
<p class="font-bold text-white text-lg">
|
|
|
|
{{ $t('main.followers') }}: {{ abbreviate(data.followers) }}
|
|
|
|
</p>
|
|
|
|
<p class="font-bold text-white text-lg">
|
|
|
|
{{ $t('main.viewers') }}: {{ abbreviate(data.viewers) }}
|
|
|
|
</p>
|
2023-04-11 13:52:19 -04:00
|
|
|
</div>
|
2023-03-24 18:48:45 -04:00
|
|
|
|
2023-04-11 13:52:19 -04:00
|
|
|
<ul class="mb-5">
|
|
|
|
<li v-for="tag in data.tags" :key="tag" class="inline-flex">
|
2023-07-20 13:57:01 -04:00
|
|
|
<span
|
2023-09-24 11:47:48 -04:00
|
|
|
class="text-white p-1 py-0.5 mr-1 text-sm font-bold bg-overlay1 rounded-sm"
|
2023-07-20 13:57:01 -04:00
|
|
|
>{{ tag }}</span
|
|
|
|
>
|
2023-04-11 13:52:19 -04:00
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
2023-03-24 18:48:45 -04:00
|
|
|
</div>
|
2023-04-11 13:52:19 -04:00
|
|
|
<p class="text-md text-gray-400 overflow-y-auto md:hidden">{{ data.description }}</p>
|
2023-03-19 19:51:55 -04:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="max-w-[58rem] mx-auto">
|
2023-03-24 18:48:45 -04:00
|
|
|
<ul>
|
2023-07-20 13:57:01 -04:00
|
|
|
<li
|
|
|
|
v-for="stream in data.streams"
|
|
|
|
:key="stream.title"
|
|
|
|
class="inline-flex m-2 hover:scale-105 transition-transform"
|
|
|
|
>
|
2023-03-31 07:50:46 -04:00
|
|
|
<StreamPreviewVue :stream="stream"></StreamPreviewVue>
|
2023-03-24 18:48:45 -04:00
|
|
|
</li>
|
|
|
|
</ul>
|
2023-03-19 19:51:55 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|