Make UserView more readable and better overall
This commit is contained in:
parent
b3deccc0c2
commit
c769e6a3ba
@ -1,26 +1,30 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { ref, inject } from 'vue'
|
import { ref, inject } from 'vue'
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
|
|
||||||
import VideoPlayer from '@/components/VideoPlayer.vue'
|
import VideoPlayer from '@/components/VideoPlayer.vue'
|
||||||
import TwitchChat from '@/components/TwitchChat.vue'
|
import TwitchChat from '@/components/TwitchChat.vue'
|
||||||
import ErrorMessage from '@/components/ErrorMessage.vue'
|
import ErrorMessage from '@/components/ErrorMessage.vue'
|
||||||
import FollowButton from '@/components/FollowButton.vue'
|
import FollowButton from '@/components/FollowButton.vue'
|
||||||
import LoadingScreen from '@/components/LoadingScreen.vue'
|
import LoadingScreen from '@/components/LoadingScreen.vue'
|
||||||
|
|
||||||
|
import type { StreamerData, ApiResponse } from '@/types'
|
||||||
|
import { truncate, abbreviate, getEndpoint } from '@/mixins'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
inject: ["rootBackendUrl"],
|
||||||
async setup() {
|
async setup() {
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const username = route.params.username
|
const username = route.params.username
|
||||||
const data = ref()
|
const data = ref<StreamerData>()
|
||||||
const protocol = inject('protocol')
|
const status = ref<"ok" | "error">()
|
||||||
|
const rootBackendUrl = inject('rootBackendUrl')
|
||||||
const videoOptions = {
|
const videoOptions = {
|
||||||
autoplay: true,
|
autoplay: true,
|
||||||
controls: true,
|
controls: true,
|
||||||
sources: [
|
sources: [
|
||||||
{
|
{
|
||||||
src: `${protocol}${
|
src: `${rootBackendUrl}/proxy/stream/${username}/hls.m3u8`,
|
||||||
import.meta.env.SAFETWITCH_BACKEND_DOMAIN
|
|
||||||
}/proxy/stream/${username}/hls.m3u8`,
|
|
||||||
type: 'application/vnd.apple.mpegurl'
|
type: 'application/vnd.apple.mpegurl'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@ -29,10 +33,19 @@ export default {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
data,
|
data,
|
||||||
|
status,
|
||||||
videoOptions,
|
videoOptions,
|
||||||
protocol
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
async mounted() {
|
||||||
|
const username = this.$route.params.username
|
||||||
|
|
||||||
|
const userData: ApiResponse = await getEndpoint("api/users/" + username)
|
||||||
|
.catch(() => {
|
||||||
|
this.status = "error"
|
||||||
|
})
|
||||||
|
this.data = userData.data as StreamerData
|
||||||
|
},
|
||||||
components: {
|
components: {
|
||||||
VideoPlayer,
|
VideoPlayer,
|
||||||
TwitchChat,
|
TwitchChat,
|
||||||
@ -40,39 +53,8 @@ export default {
|
|||||||
FollowButton,
|
FollowButton,
|
||||||
LoadingScreen
|
LoadingScreen
|
||||||
},
|
},
|
||||||
async mounted() {
|
|
||||||
const username = this.$route.params.username
|
|
||||||
|
|
||||||
try {
|
|
||||||
const res = await fetch(
|
|
||||||
`${this.protocol}${import.meta.env.SAFETWITCH_BACKEND_DOMAIN}/api/users/${username}`
|
|
||||||
)
|
|
||||||
const rawData = await res.json()
|
|
||||||
if (rawData.status === 'ok') {
|
|
||||||
this.data = rawData.data
|
|
||||||
} else {
|
|
||||||
this.data = { status: 'error' }
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error)
|
|
||||||
this.data = { status: 'error' }
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
methods: {
|
||||||
truncate(value: string, length: number) {
|
truncate, abbreviate
|
||||||
if (value.length > length) {
|
|
||||||
return value.substring(0, length) + '...'
|
|
||||||
} else {
|
|
||||||
return value
|
|
||||||
}
|
|
||||||
},
|
|
||||||
abbreviate(text: number) {
|
|
||||||
return Intl.NumberFormat('en-US', {
|
|
||||||
//@ts-ignore
|
|
||||||
notation: 'compact',
|
|
||||||
maximumFractionDigits: 1
|
|
||||||
}).format(text)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@ -80,7 +62,7 @@ export default {
|
|||||||
<template>
|
<template>
|
||||||
<loading-screen v-if="!data"></loading-screen>
|
<loading-screen v-if="!data"></loading-screen>
|
||||||
|
|
||||||
<error-message v-else-if="data.status === 'error'"></error-message>
|
<error-message v-else-if="status === 'error'"></error-message>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
v-else
|
v-else
|
||||||
@ -132,7 +114,7 @@ export default {
|
|||||||
<div v-else class="w-full">
|
<div v-else class="w-full">
|
||||||
<ul class="text-xs font-bold text-left md:text-right space-x-1 space-y-1 overflow-y-auto">
|
<ul class="text-xs font-bold text-left md:text-right space-x-1 space-y-1 overflow-y-auto">
|
||||||
<li
|
<li
|
||||||
v-for="tag in data.stream.tags"
|
v-for="tag in data.stream!.tags"
|
||||||
:key="tag"
|
:key="tag"
|
||||||
class="inline-flex bg-ctp-mantle p-1.5 px-2 rounded-md"
|
class="inline-flex bg-ctp-mantle p-1.5 px-2 rounded-md"
|
||||||
>
|
>
|
||||||
@ -158,7 +140,7 @@ export default {
|
|||||||
<hr class="my-auto w-full bg-gray-200 rounded-full opacity-40" />
|
<hr class="my-auto w-full bg-gray-200 rounded-full opacity-40" />
|
||||||
|
|
||||||
<ul class="flex font-semibold text-md justify-start flex-wrap flex-row">
|
<ul class="flex font-semibold text-md justify-start flex-wrap flex-row">
|
||||||
<li v-for="link in data.socials" :key="link">
|
<li v-for="link in data.socials">
|
||||||
<a :href="link.link" class="text-white hover:text-gray-400 mr-4">
|
<a :href="link.link" class="text-white hover:text-gray-400 mr-4">
|
||||||
<v-icon :name="`bi-${link.type}`" class="w-6 h-6 mr-1"></v-icon>
|
<v-icon :name="`bi-${link.type}`" class="w-6 h-6 mr-1"></v-icon>
|
||||||
<span>{{ link.name }}</span>
|
<span>{{ link.name }}</span>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user