2023-03-19 19:51:55 -04:00
|
|
|
<script lang="ts">
|
2023-04-10 00:12:52 -04:00
|
|
|
import { ref, type Ref } from 'vue'
|
2023-04-11 14:27:43 -04:00
|
|
|
import { useRoute } from 'vue-router'
|
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-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-04-11 14:27:43 -04:00
|
|
|
const route = useRoute()
|
2023-04-10 00:12:52 -04:00
|
|
|
const data: Ref<any | undefined> = ref()
|
2023-04-11 14:27:43 -04:00
|
|
|
const game: string = route.params.game.toString()
|
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-04-11 14:27:43 -04:00
|
|
|
game
|
2023-03-19 19:51:55 -04:00
|
|
|
}
|
|
|
|
},
|
2023-04-10 00:12:52 -04:00
|
|
|
async mounted() {
|
|
|
|
try {
|
2023-04-10 00:19:39 -04:00
|
|
|
const res = await fetch(
|
2023-04-11 14:27:43 -04:00
|
|
|
`${this.protocol}${import.meta.env.VITE_BACKEND_DOMAIN}/api/discover/${this.game}`
|
2023-04-10 00:19:39 -04:00
|
|
|
)
|
2023-04-10 11:55:41 -04:00
|
|
|
const rawData = await res.json()
|
2023-04-11 14:27:43 -04:00
|
|
|
if (rawData.status === "ok") {
|
2023-04-10 11:55:41 -04:00
|
|
|
this.data = rawData.data
|
|
|
|
} else {
|
|
|
|
this.data = { status: 'error' }
|
2023-04-10 00:12:52 -04:00
|
|
|
}
|
2023-04-10 00:19:39 -04:00
|
|
|
} catch (err) {
|
|
|
|
this.data = { status: 'error' }
|
|
|
|
console.error(err)
|
|
|
|
}
|
2023-04-11 14:27:43 -04:00
|
|
|
|
|
|
|
this.getMoreStreams()
|
2023-04-10 00:12:52 -04:00
|
|
|
},
|
2023-03-19 19:51:55 -04:00
|
|
|
methods: {
|
2023-04-11 14:27:43 -04:00
|
|
|
getMoreStreams() {
|
|
|
|
window.onscroll = async () => {
|
|
|
|
let bottomOfWindow =
|
|
|
|
document.documentElement.scrollTop + window.innerHeight ===
|
|
|
|
document.documentElement.offsetHeight
|
|
|
|
const streams = this.data.streams
|
|
|
|
if (bottomOfWindow && streams) {
|
|
|
|
const cursor = streams[streams.length - 1].cursor
|
|
|
|
if (!cursor) return
|
|
|
|
const res = await fetch(
|
|
|
|
`${this.protocol}${import.meta.env.VITE_BACKEND_DOMAIN}/api/discover/${this.game}/?cursor=${cursor}`
|
|
|
|
)
|
|
|
|
if (!res.ok) {
|
|
|
|
throw new Error('Failed to fetch data')
|
|
|
|
}
|
|
|
|
const resData = await res.json()
|
|
|
|
|
|
|
|
for (let stream of resData.data.streams) {
|
|
|
|
this.data.streams.push(stream)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2023-03-19 19:51:55 -04:00
|
|
|
abbreviate(text: number) {
|
2023-03-24 18:48:45 -04:00
|
|
|
return Intl.NumberFormat('en-US', {
|
|
|
|
//@ts-ignore
|
|
|
|
notation: 'compact',
|
|
|
|
maximumFractionDigits: 1
|
|
|
|
}).format(text)
|
2023-03-19 19:51:55 -04:00
|
|
|
}
|
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-04-10 00:12:52 -04:00
|
|
|
<loading-screen v-if="!data"></loading-screen>
|
|
|
|
<error-message v-else-if="data.status === 'error' || !data"></error-message>
|
|
|
|
|
|
|
|
<div v-else 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-04-11 14:27:43 -04:00
|
|
|
<p class="font-bold text-white text-lg">Followers: {{ abbreviate(data.followers) }}</p>
|
2023-04-11 13:52:19 -04:00
|
|
|
<p class="font-bold text-white text-lg">Viewers: {{ abbreviate(data.viewers) }}</p>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<ul class="mb-5">
|
|
|
|
<li v-for="tag in data.tags" :key="tag" class="inline-flex">
|
2023-04-11 14:27:43 -04:00
|
|
|
<span class="text-white p-1 py-0.5 mr-1 text-sm font-bold bg-ctp-overlay1 rounded-sm">{{
|
|
|
|
tag
|
|
|
|
}}</span>
|
2023-04-11 13:52:19 -04:00
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-04-11 14:27:43 -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">
|
|
|
|
<p class="font-bold text-white text-lg">Followers: {{ abbreviate(data.followers) }}</p>
|
|
|
|
<p class="font-bold text-white text-lg">Viewers: {{ abbreviate(data.viewers) }}</p>
|
|
|
|
</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-04-11 14:27:43 -04:00
|
|
|
<span class="text-white p-1 py-0.5 mr-1 text-sm font-bold bg-ctp-overlay1 rounded-sm">{{
|
|
|
|
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-04-11 14:27:43 -04:00
|
|
|
<li v-for="stream in data.streams" :key="stream" 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>
|