safetwitch/src/views/SearchPageView.vue

97 lines
3.3 KiB
Vue
Raw Normal View History

2023-04-16 12:37:35 -04:00
<script lang="ts">
2023-06-19 22:17:12 -04:00
import { ref } from 'vue'
2023-04-16 12:37:35 -04:00
import CategoryPreview from '@/components/CategoryPreview.vue'
import ErrorMessage from '@/components/ErrorMessage.vue'
import LoadingScreen from '@/components/LoadingScreen.vue'
import StreamPreviewVue from '@/components/StreamPreview.vue'
import ChannelPreview from '@/components/ChannelPreview.vue'
2023-06-19 22:17:12 -04:00
import { getEndpoint } from '@/mixins'
import type { ApiResponse, SearchResult, StreamerData } from '@/types'
2023-04-16 12:37:35 -04:00
export default {
2023-05-12 10:21:31 -04:00
inject: ['protocol'],
2023-04-16 12:37:35 -04:00
setup() {
2023-06-19 22:17:12 -04:00
let data = ref<SearchResult>()
const status = ref<"ok" | "error">()
2023-04-16 12:37:35 -04:00
return {
data,
2023-06-19 22:17:12 -04:00
status,
2023-04-16 12:37:35 -04:00
}
},
async mounted() {
2023-06-19 22:17:12 -04:00
await getEndpoint("api/search/?query=" + this.$route.query.query)
.catch(() => {
this.status = "error"
})
.then((data) => {
this.data = data as SearchResult
})
2023-04-16 12:37:35 -04:00
},
methods: {
2023-06-19 22:17:12 -04:00
getStream(channel: StreamerData) {
2023-04-16 12:37:35 -04:00
return {
...channel.stream,
streamer: {
name: channel.username,
pfp: channel.pfp
}
}
}
},
components: {
CategoryPreview,
ErrorMessage,
LoadingScreen,
StreamPreviewVue,
ChannelPreview
}
}
</script>
<template>
2023-06-19 22:17:12 -04:00
<loading-screen v-if="!data && status != 'error'"></loading-screen>
<error-message v-else-if="status == 'error'"></error-message>
2023-04-16 12:37:35 -04:00
2023-06-19 22:17:12 -04:00
<div v-else-if="data" class="p-3 space-y-5">
2023-04-16 12:37:35 -04:00
<div v-if="data.channels.length > 0">
2023-06-19 22:17:12 -04:00
<h1 class="text-white font-bold text-4xl mb-2">Channels related to "{{ $route.query.query }}"</h1>
2023-04-16 12:37:35 -04:00
<ul class="flex overflow-x-scroll overflow-y-hidden">
2023-06-19 22:17:12 -04:00
<li v-for="channel in data.channels" class="m-2 hover:scale-105 transition-transform">
2023-04-16 12:37:35 -04:00
<channel-preview :channel="channel"></channel-preview>
</li>
</ul>
</div>
<div v-if="data.categories.length > 0">
2023-06-19 22:17:12 -04:00
<h1 class="text-white font-bold text-4xl mb-2">Categories related to "{{ $route.query.query }}"</h1>
2023-04-16 12:37:35 -04:00
<ul class="flex max-w-[100vw] max-h-[27rem] overflow-x-scroll overflow-y-hidden">
2023-06-19 22:17:12 -04:00
<li v-for="category in data.categories" class="m-2 hover:scale-105 transition-transform">
2023-04-16 12:37:35 -04:00
<category-preview :category-data="category"></category-preview>
</li>
</ul>
</div>
<div v-if="data.relatedChannels.length > 0">
2023-06-19 22:17:12 -04:00
<h1 class="text-white font-bold text-4xl mb-2">Live channels with the tag "{{ $route.query.query }}"</h1>
2023-04-16 12:37:35 -04:00
<ul class="flex overflow-x-scroll space-x-5 ">
2023-06-19 22:17:12 -04:00
<li v-for="channel in data.relatedChannels">
2023-04-16 12:37:35 -04:00
<stream-preview-vue :stream="getStream(channel)"></stream-preview-vue>
</li>
</ul>
</div>
<div v-if="data.channelsWithTag.length > 0">
2023-06-19 22:17:12 -04:00
<h1 class="text-white font-bold text-4xl mb-2">Channels with the tag "{{ $route.query.query }}"</h1>
2023-04-16 12:37:35 -04:00
<ul class="inline-flex overflow-y-hidden overflow-x-scroll max-w-[100vw] space-x-5">
2023-06-19 22:17:12 -04:00
<li v-for="channel in data.channelsWithTag">
2023-04-16 12:37:35 -04:00
<channel-preview :channel="channel"></channel-preview>
</li>
</ul>
</div>
</div>
</template>