mirror of
https://codeberg.org/SafeTwitch/safetwitch.git
synced 2025-01-03 11:20:07 -05:00
Add infinite scroll to categories
This commit is contained in:
parent
d3c411c348
commit
102a6811bd
1 changed files with 42 additions and 25 deletions
|
@ -1,30 +1,32 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { ref, type Ref } from 'vue'
|
import { ref, type Ref } from 'vue'
|
||||||
|
import { useRoute } from 'vue-router'
|
||||||
import StreamPreviewVue from '@/components/StreamPreview.vue'
|
import StreamPreviewVue from '@/components/StreamPreview.vue'
|
||||||
import ErrorMessage from '@/components/ErrorMessage.vue'
|
import ErrorMessage from '@/components/ErrorMessage.vue'
|
||||||
import LoadingScreen from '@/components/LoadingScreen.vue'
|
import LoadingScreen from '@/components/LoadingScreen.vue'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
async setup() {
|
async setup() {
|
||||||
|
const route = useRoute()
|
||||||
const protocol = import.meta.env.VITE_HTTPS === 'true' ? 'https://' : 'http://'
|
const protocol = import.meta.env.VITE_HTTPS === 'true' ? 'https://' : 'http://'
|
||||||
const data: Ref<any | undefined> = ref()
|
const data: Ref<any | undefined> = ref()
|
||||||
const frontend_url = protocol + import.meta.env.VITE_INSTANCE_DOMAIN
|
const frontend_url = protocol + import.meta.env.VITE_INSTANCE_DOMAIN
|
||||||
|
const game: string = route.params.game.toString()
|
||||||
|
|
||||||
return {
|
return {
|
||||||
data,
|
data,
|
||||||
frontend_url
|
frontend_url,
|
||||||
|
protocol,
|
||||||
|
game
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async mounted() {
|
async mounted() {
|
||||||
const protocol = import.meta.env.VITE_HTTPS === 'true' ? 'https://' : 'http://'
|
|
||||||
const game: string = this.$route.params.game.toString()
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch(
|
const res = await fetch(
|
||||||
`${protocol}${import.meta.env.VITE_BACKEND_DOMAIN}/api/discover/${game}`
|
`${this.protocol}${import.meta.env.VITE_BACKEND_DOMAIN}/api/discover/${this.game}`
|
||||||
)
|
)
|
||||||
const rawData = await res.json()
|
const rawData = await res.json()
|
||||||
if (rawData.status === 'ok') {
|
if (rawData.status === "ok") {
|
||||||
this.data = rawData.data
|
this.data = rawData.data
|
||||||
} else {
|
} else {
|
||||||
this.data = { status: 'error' }
|
this.data = { status: 'error' }
|
||||||
|
@ -33,8 +35,33 @@ export default {
|
||||||
this.data = { status: 'error' }
|
this.data = { status: 'error' }
|
||||||
console.error(err)
|
console.error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.getMoreStreams()
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
abbreviate(text: number) {
|
abbreviate(text: number) {
|
||||||
return Intl.NumberFormat('en-US', {
|
return Intl.NumberFormat('en-US', {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
|
@ -65,25 +92,20 @@ export default {
|
||||||
<div class="hidden md:block">
|
<div class="hidden md:block">
|
||||||
<div>
|
<div>
|
||||||
<div class="inline-flex my-1 space-x-3">
|
<div class="inline-flex my-1 space-x-3">
|
||||||
<p class="font-bold text-white text-lg">
|
<p class="font-bold text-white text-lg">Followers: {{ abbreviate(data.followers) }}</p>
|
||||||
Followers: {{ abbreviate(data.followers) }}
|
|
||||||
</p>
|
|
||||||
<p class="font-bold text-white text-lg">Viewers: {{ abbreviate(data.viewers) }}</p>
|
<p class="font-bold text-white text-lg">Viewers: {{ abbreviate(data.viewers) }}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ul class="mb-5">
|
<ul class="mb-5">
|
||||||
<li v-for="tag in data.tags" :key="tag" class="inline-flex">
|
<li v-for="tag in data.tags" :key="tag" class="inline-flex">
|
||||||
<span
|
<span class="text-white p-1 py-0.5 mr-1 text-sm font-bold bg-ctp-overlay1 rounded-sm">{{
|
||||||
class="text-white p-1 py-0.5 mr-1 text-sm font-bold bg-ctp-overlay1 rounded-sm"
|
tag
|
||||||
>{{ tag }}</span
|
}}</span>
|
||||||
>
|
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p class="text-md text-gray-400 overflow-y-auto hidden md:block">
|
<p class="text-md text-gray-400 overflow-y-auto hidden md:block">{{ data.description }}</p>
|
||||||
{{ data.description }}
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -96,10 +118,9 @@ export default {
|
||||||
|
|
||||||
<ul class="mb-5">
|
<ul class="mb-5">
|
||||||
<li v-for="tag in data.tags" :key="tag" class="inline-flex">
|
<li v-for="tag in data.tags" :key="tag" class="inline-flex">
|
||||||
<span
|
<span class="text-white p-1 py-0.5 mr-1 text-sm font-bold bg-ctp-overlay1 rounded-sm">{{
|
||||||
class="text-white p-1 py-0.5 mr-1 text-sm font-bold bg-ctp-overlay1 rounded-sm"
|
tag
|
||||||
>{{ tag }}</span
|
}}</span>
|
||||||
>
|
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
@ -109,11 +130,7 @@ export default {
|
||||||
|
|
||||||
<div class="max-w-[58rem] mx-auto">
|
<div class="max-w-[58rem] mx-auto">
|
||||||
<ul>
|
<ul>
|
||||||
<li
|
<li v-for="stream in data.streams" :key="stream" class="inline-flex m-2 hover:scale-105 transition-transform">
|
||||||
v-for="stream in data.streams"
|
|
||||||
:key="stream"
|
|
||||||
class="inline-flex m-2 hover:scale-105 transition-transform"
|
|
||||||
>
|
|
||||||
<StreamPreviewVue :stream="stream"></StreamPreviewVue>
|
<StreamPreviewVue :stream="stream"></StreamPreviewVue>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
Loading…
Reference in a new issue