From 92bef30e4dae0eba99187a847c23ede83be9ff5b Mon Sep 17 00:00:00 2001 From: dragongoose Date: Thu, 30 Nov 2023 19:17:31 -0500 Subject: [PATCH] More efficient following streamer tab, only show live streamers and hide if empty #56 --- src/mixins.ts | 32 ++++++++++++++++++++++++++++++++ src/views/HomepageView.vue | 16 +++++++--------- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/mixins.ts b/src/mixins.ts index a4616cc..da813a4 100644 --- a/src/mixins.ts +++ b/src/mixins.ts @@ -1,3 +1,6 @@ +import { getFollows } from '@/settingsManager' +import type { StreamerData } from '@/types' + const language = localStorage.getItem('language') || 'en-us' const https = import.meta.env.SAFETWITCH_HTTPS.slice() === 'true' const protocol = https ? 'https://' : 'http://' @@ -88,3 +91,32 @@ export function getTimeFromQuery(query: string) { time += times[2] 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 { + 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 +} diff --git a/src/views/HomepageView.vue b/src/views/HomepageView.vue index 46c11d3..110fa2e 100644 --- a/src/views/HomepageView.vue +++ b/src/views/HomepageView.vue @@ -6,20 +6,22 @@ import ErrorMessage from '@/components/ErrorMessage.vue' import LoadingScreen from '@/components/LoadingScreen.vue' import CategoryPreview from '@/components/CategoryPreview.vue' -import { getEndpoint } from '@/mixins' +import { getEndpoint, followersStreaming } from '@/mixins' import type { CategoryPreview as CategoryPreviewInterface } from '@/types' +import { getFollows } from '@/settingsManager' export default { inject: ['protocol'], async setup() { let data = ref() let status = ref<'ok' | 'error'>() + let following = ref() return { data, status, filterTags: '', - following: ref([]) + following, } }, methods: { @@ -69,13 +71,9 @@ export default { async mounted() { window.onscroll = this.getNextCategory - let following = localStorage.getItem('following') - if (following) { - this.following = JSON.parse(following) - } else { - this.following = [] - } + this.following = await followersStreaming(getFollows()); + // get discover page await getEndpoint('api/discover') .catch(() => { this.status = 'error' @@ -98,7 +96,7 @@ export default {
-
+

Following

Streamers you follow