0
Fork 0
mirror of https://codeberg.org/SafeTwitch/safetwitch.git synced 2024-12-22 13:22:58 -05:00

More efficient following streamer tab, only show live streamers and hide if empty #56

This commit is contained in:
dragongoose 2023-11-30 19:17:31 -05:00
parent 9cb646da10
commit 92bef30e4d
No known key found for this signature in database
GPG key ID: 01397EEC371CDAA5
2 changed files with 39 additions and 9 deletions

View file

@ -1,3 +1,6 @@
import { getFollows } from '@/settingsManager'
import type { StreamerData } from '@/types'
const language = localStorage.getItem('language') || 'en-us' const language = localStorage.getItem('language') || 'en-us'
const https = import.meta.env.SAFETWITCH_HTTPS.slice() === 'true' const https = import.meta.env.SAFETWITCH_HTTPS.slice() === 'true'
const protocol = https ? 'https://' : 'http://' const protocol = https ? 'https://' : 'http://'
@ -88,3 +91,32 @@ export function getTimeFromQuery(query: string) {
time += times[2] time += times[2]
return time return time
} }
/**
* Returns a string of online streamers from a
* array of string of the request streamers
* @param streamers the array of streamers
* @returns the streamers in that list that are online
*/
export async function followersStreaming(streamers: string[]): Promise<string[]> {
const payload = {
streamers: streamers
}
// do not make request if no followers
if (streamers.length == 0) {
return []
}
const data: StreamerData[] = await postEndpoint('api/users/bulk', payload)
const liveStreamers: string[] = []
for (let streamer of data) {
if (streamer.isLive) {
liveStreamers.push(streamer.login)
}
}
return liveStreamers
}

View file

@ -6,20 +6,22 @@ import ErrorMessage from '@/components/ErrorMessage.vue'
import LoadingScreen from '@/components/LoadingScreen.vue' import LoadingScreen from '@/components/LoadingScreen.vue'
import CategoryPreview from '@/components/CategoryPreview.vue' import CategoryPreview from '@/components/CategoryPreview.vue'
import { getEndpoint } from '@/mixins' import { getEndpoint, followersStreaming } from '@/mixins'
import type { CategoryPreview as CategoryPreviewInterface } from '@/types' import type { CategoryPreview as CategoryPreviewInterface } from '@/types'
import { getFollows } from '@/settingsManager'
export default { export default {
inject: ['protocol'], inject: ['protocol'],
async setup() { async setup() {
let data = ref<CategoryPreviewInterface[]>() let data = ref<CategoryPreviewInterface[]>()
let status = ref<'ok' | 'error'>() let status = ref<'ok' | 'error'>()
let following = ref<string[]>()
return { return {
data, data,
status, status,
filterTags: '', filterTags: '',
following: ref([]) following,
} }
}, },
methods: { methods: {
@ -69,13 +71,9 @@ export default {
async mounted() { async mounted() {
window.onscroll = this.getNextCategory window.onscroll = this.getNextCategory
let following = localStorage.getItem('following') this.following = await followersStreaming(getFollows());
if (following) {
this.following = JSON.parse(following)
} else {
this.following = []
}
// get discover page
await getEndpoint('api/discover') await getEndpoint('api/discover')
.catch(() => { .catch(() => {
this.status = 'error' this.status = 'error'
@ -98,7 +96,7 @@ export default {
<error-message v-else-if="status == 'error'"></error-message> <error-message v-else-if="status == 'error'"></error-message>
<div v-else-if="data" class="max-w-5xl mx-auto"> <div v-else-if="data" class="max-w-5xl mx-auto">
<div v-if="following.length > 0" class="p-2 text-white"> <div v-if="following && following.length > 0" class="p-2 text-white">
<h1 class="font-bold text-5xl">Following</h1> <h1 class="font-bold text-5xl">Following</h1>
<p class="text-xl">Streamers you follow</p> <p class="text-xl">Streamers you follow</p>
<ul class="flex overflow-x-scroll space-x-2 flex-nowrap h-[22rem] items-center"> <ul class="flex overflow-x-scroll space-x-2 flex-nowrap h-[22rem] items-center">