diff --git a/packages/web-client/src/routes/(feed)/(splash)/up-down/+layout.svelte b/packages/web-client/src/routes/(feed)/(splash)/up-down/+layout.svelte new file mode 100644 index 000000000..3d4d314cc --- /dev/null +++ b/packages/web-client/src/routes/(feed)/(splash)/up-down/+layout.svelte @@ -0,0 +1,13 @@ + + + + Up Down | Hot or Not + + + + + + + diff --git a/packages/web-client/src/routes/(feed)/(splash)/up-down/+page.ts b/packages/web-client/src/routes/(feed)/(splash)/up-down/+page.ts new file mode 100644 index 000000000..551c1dbb3 --- /dev/null +++ b/packages/web-client/src/routes/(feed)/(splash)/up-down/+page.ts @@ -0,0 +1,25 @@ +export const ssr = false + +import type { PageLoad } from './$types' +import { redirect } from '@sveltejs/kit' +import { postCache } from '$lib/helpers/backend' + +export const load: PageLoad = async ({ fetch }) => { + const res = await postCache( + fetch, + ).get_top_posts_aggregated_from_canisters_on_this_network_for_hot_or_not_feed( + BigInt(0), + BigInt(1), + ) + + if ('Ok' in res && res.Ok[0]) { + throw redirect( + 307, + `/up-down/${res.Ok[0].publisher_canister_id.toText()}@${ + res.Ok[0].post_id + }`, + ) + } else { + throw redirect(307, '/up-down/no-videos') + } +} diff --git a/packages/web-client/src/routes/(feed)/(splash)/up-down/[id=videoId]/+page.svelte b/packages/web-client/src/routes/(feed)/(splash)/up-down/[id=videoId]/+page.svelte new file mode 100644 index 000000000..38d0cd3ff --- /dev/null +++ b/packages/web-client/src/routes/(feed)/(splash)/up-down/[id=videoId]/+page.svelte @@ -0,0 +1,226 @@ + + + + Up Down | Hot or Not + + + + {#each videos as post, i (i)} + + {#if currentVideoIndex - 2 < i && currentVideoIndex + keepVideosLoadedCount > i} + + hideSplashScreen(500)} + on:watchedPercentage={({ detail }) => recordView(detail)} + on:videoUnavailable={() => handleUnavailableVideo(i)} + index={i} + playFormat="hls" + {Hls} + inView={i == currentVideoIndex && $playerState.visible} + uid={post.video_uid} /> + + + + + + {/if} + + {/each} + {#if showError} + +
+
+ Error loading posts. Please, refresh the page. +
+ +
+
+ {/if} + {#if loading} + +
+
Loading
+
+
+ {/if} + {#if noMoreVideos} + +
+ +
+ There are no more videos to vote on +
+
+ +
+
+
+ {/if} +
diff --git a/packages/web-client/src/routes/(feed)/(splash)/up-down/[id=videoId]/+page.ts b/packages/web-client/src/routes/(feed)/(splash)/up-down/[id=videoId]/+page.ts new file mode 100644 index 000000000..b9b052f14 --- /dev/null +++ b/packages/web-client/src/routes/(feed)/(splash)/up-down/[id=videoId]/+page.ts @@ -0,0 +1,54 @@ +export const ssr = false +export const prerender = false + +import { Principal } from '@dfinity/principal' +import type { PageLoad } from './$types' +import type { PostPopulated } from '$lib/helpers/feed' +import { individualUser } from '$lib/helpers/backend' +import Log from '$lib/utils/Log' + +export const load: PageLoad = async ({ params, fetch }) => { + try { + const id = params.id.split('@') + const postId = BigInt(Number(id[1])) + const principal = Principal.from(id[0]) + let cachedPost: PostPopulated | undefined = undefined + + try { + const { idb } = await import('$lib/idb') + cachedPost = await idb.get('watch', params.id) + } catch (e) { + Log('error', 'Error while accessing IDB', { + error: e, + from: 'feedLoad', + type: 'idb', + }) + cachedPost = undefined + } + + if (cachedPost) { + return { post: cachedPost } + } else { + const r = await individualUser( + principal, + fetch, + ).get_individual_post_details_by_id(postId) + if (r.video_uid) { + return { + post: { + ...r, + publisher_canister_id: id[0], + created_by_user_principal_id: + r.created_by_user_principal_id.toText(), + post_id: postId, + score: BigInt(0), + } as PostPopulated, + } + } else { + return + } + } + } catch (e) { + return + } +} diff --git a/packages/web-client/src/routes/(feed)/(splash)/up-down/no-videos/+page.svelte b/packages/web-client/src/routes/(feed)/(splash)/up-down/no-videos/+page.svelte new file mode 100644 index 000000000..c0713c50b --- /dev/null +++ b/packages/web-client/src/routes/(feed)/(splash)/up-down/no-videos/+page.svelte @@ -0,0 +1,22 @@ + + +
+ +
+ There are no videos to vote on +
+
+ +
+
diff --git a/packages/web-client/src/routes/(feed)/+layout.svelte b/packages/web-client/src/routes/(feed)/+layout.svelte index 26f80fd4e..10670d9b3 100644 --- a/packages/web-client/src/routes/(feed)/+layout.svelte +++ b/packages/web-client/src/routes/(feed)/+layout.svelte @@ -50,7 +50,7 @@ $: pathname = $page.url.pathname
- {#if !pathname.includes('hotornot')} + {#if !pathname.includes('hotornot') && !pathname.includes('up-down')} {/if}