From d9c99d91c6e1cff416d22a20f0344a313acf8f1c Mon Sep 17 00:00:00 2001 From: WardPearce Date: Tue, 12 Mar 2024 07:38:54 +1300 Subject: [PATCH] Added notifications and subscriptions --- materialious/src/lib/Api/index.ts | 7 ++++++ materialious/src/lib/Api/model.ts | 9 ++++++++ materialious/src/lib/Thumbnail.svelte | 2 +- materialious/src/routes/+layout.svelte | 23 +++++++++++++++++-- .../src/routes/subscriptions/+page.svelte | 19 ++++++++++++++- .../src/routes/subscriptions/+page.ts | 6 ++++- 6 files changed, 61 insertions(+), 5 deletions(-) diff --git a/materialious/src/lib/Api/index.ts b/materialious/src/lib/Api/index.ts index a09792ce..b25e0326 100644 --- a/materialious/src/lib/Api/index.ts +++ b/materialious/src/lib/Api/index.ts @@ -57,3 +57,10 @@ export async function getSearch(search: string, options: { const resp = await fetch(path); return await resp.json(); } + +export async function getFeed(maxResults: number, page: number) { + const path = new URL(buildPath("auth/feed")); + path.search = new URLSearchParams({ max_results: maxResults.toString(), page: page.toString() }).toString(); + const resp = await fetch(path, buildAuthHeaders()); + return await resp.json(); +} \ No newline at end of file diff --git a/materialious/src/lib/Api/model.ts b/materialious/src/lib/Api/model.ts index 4a1f1287..c52052ff 100644 --- a/materialious/src/lib/Api/model.ts +++ b/materialious/src/lib/Api/model.ts @@ -155,3 +155,12 @@ export interface SearchSuggestion { query: string; suggestions: string[]; } + +export interface Notification extends VideoBase { + type: "video" | "shortVideo" | "stream"; +} + +export interface Feed { + notifications: Notification[]; + videos: Video[]; +} \ No newline at end of file diff --git a/materialious/src/lib/Thumbnail.svelte b/materialious/src/lib/Thumbnail.svelte index 4eb45e52..f75a6afc 100644 --- a/materialious/src/lib/Thumbnail.svelte +++ b/materialious/src/lib/Thumbnail.svelte @@ -3,7 +3,7 @@ import type { Video, VideoBase } from './Api/model'; import { cleanNumber, truncate } from './misc'; - export let video: VideoBase | Video; + export let video: VideoBase | Video | Notification; function videoLength(lengthSeconds: number): string { const hours = Math.floor(lengthSeconds / 3600); diff --git a/materialious/src/routes/+layout.svelte b/materialious/src/routes/+layout.svelte index 2c076d4b..e1e99784 100644 --- a/materialious/src/routes/+layout.svelte +++ b/materialious/src/routes/+layout.svelte @@ -1,7 +1,8 @@ @@ -423,7 +436,13 @@
Notifications
-

No new notifications here

+ {#if notifications.length === 0} +

No new notifications here

+ {:else} + {#each notifications as notification} + + {/each} + {/if} diff --git a/materialious/src/routes/subscriptions/+page.svelte b/materialious/src/routes/subscriptions/+page.svelte index f490414a..186f93d3 100644 --- a/materialious/src/routes/subscriptions/+page.svelte +++ b/materialious/src/routes/subscriptions/+page.svelte @@ -1,7 +1,24 @@ + +{#if data} +
+
+
+ {#each data.feed.videos as video} +
+ +
+ {/each} +
+
+{:else} + +{/if} diff --git a/materialious/src/routes/subscriptions/+page.ts b/materialious/src/routes/subscriptions/+page.ts index 43a4fe52..760657f4 100644 --- a/materialious/src/routes/subscriptions/+page.ts +++ b/materialious/src/routes/subscriptions/+page.ts @@ -1,3 +1,7 @@ -export async function load({ params }) { +import { getFeed } from '$lib/Api/index.js'; +export async function load({ params }) { + return { + feed: await getFeed(100, 1) + }; } \ No newline at end of file