From 44779e3e6d2b84c52b018eb48fcbcbe6f561ca38 Mon Sep 17 00:00:00 2001 From: dragongoose Date: Sun, 4 Feb 2024 21:12:26 -0500 Subject: [PATCH] Fix translation and add infinte scroll onto the following streams page --- src/mixins.ts | 17 ++++++++++------- src/views/HomepageView.vue | 29 ++++++++++++++++++++--------- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/mixins.ts b/src/mixins.ts index 20fc55e..7c2101c 100644 --- a/src/mixins.ts +++ b/src/mixins.ts @@ -95,25 +95,28 @@ export function getTimeFromQuery(query: string) { * Returns a string of online streamers from a * array of string of the request streamers * @param streamers the array of streamers + * @param cursor which 35 streamer chunk to fetch * @returns the streamers in that list that are online */ -export async function followersStreaming(streamers: string[]): Promise { +export async function followersStreaming(streamers: string[], cursor: number): Promise { // do not make request if no followers if (streamers.length == 0) { return [] } - let data: string[] = [] + let res: string[] = [] + + const payloadData = streamers.slice(cursor, cursor + 35) + const payload = { - streamers + streamers: payloadData } await postEndpoint('api/users/isLive/bulk', payload) - .then((res: string[]) => { - data = res + .then((data: string[]) => { + res = [...res, ...data] }) - - return data + return res } diff --git a/src/views/HomepageView.vue b/src/views/HomepageView.vue index fdc518a..a6c7783 100644 --- a/src/views/HomepageView.vue +++ b/src/views/HomepageView.vue @@ -66,6 +66,17 @@ export default { this.data.push(category) } } + }, + async handleFollowingScroll(event: UIEvent) { + let el = event.target as HTMLUListElement + let fullyScrolled = el.scrollLeft === (el.scrollWidth - el.clientWidth) + console.log(el) + if (!fullyScrolled) return; + + if (!this.following) return; + let offset = this.following.length / 35 + let newFollowers = await followersStreaming(getFollows(), offset) + this.following = [ ...this.following, ...newFollowers] } }, async mounted() { @@ -79,8 +90,8 @@ export default { .then((data: CategoryPreviewInterface[]) => { this.data = data }) - - this.following = await followersStreaming(getFollows()) + + this.following = await followersStreaming(getFollows(), 0) }, components: { StreamPreviewVue, @@ -92,14 +103,14 @@ export default {