From e39fce51e2505a912d580f6c7f9daa420e1ee6a1 Mon Sep 17 00:00:00 2001 From: WardPearce Date: Mon, 8 Dec 2025 23:03:07 +1300 Subject: [PATCH] Implemeneted favourited system --- materialious/electron/package-lock.json | 14 ++++++-- materialious/electron/package.json | 3 +- .../electron/src/rt/electron-plugins.js | 2 ++ materialious/package-lock.json | 11 ++++-- materialious/package.json | 3 +- materialious/src/lib/api/model.ts | 6 ++++ .../src/lib/components/Thumbnail.svelte | 4 +++ .../src/lib/components/watch/Author.svelte | 32 +++++++++++++++++ materialious/src/lib/i18n/locales/en.json | 4 ++- .../src/routes/(app)/subscriptions/+page.ts | 36 +++++++++++++++++-- 10 files changed, 105 insertions(+), 10 deletions(-) diff --git a/materialious/electron/package-lock.json b/materialious/electron/package-lock.json index b633e070..559efb4e 100644 --- a/materialious/electron/package-lock.json +++ b/materialious/electron/package-lock.json @@ -1,16 +1,17 @@ { "name": "Materialious", - "version": "1.12.0", + "version": "1.12.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "Materialious", - "version": "1.12.0", + "version": "1.12.3", "license": "MIT", "dependencies": { "@capacitor-community/electron": "^5.0.0", "bgutils-js": "^3.2.0", + "capacitor-nodejs": "https://github.com/hampoelz/capacitor-nodejs/releases/download/v1.0.0-beta.9/capacitor-nodejs.tgz", "chokidar": "~5.0.0", "electron-is-dev": "~2.0.0", "electron-serve": "~3.0.0", @@ -1885,6 +1886,15 @@ "node": ">= 0.4" } }, + "node_modules/capacitor-nodejs": { + "version": "1.0.0-beta.9", + "resolved": "https://github.com/hampoelz/capacitor-nodejs/releases/download/v1.0.0-beta.9/capacitor-nodejs.tgz", + "integrity": "sha512-4EU/QBolfuyHiMtwd1nxZ4wsK243tGE4VttKvVBG+x1yQuK9EIlEf3lbRjFXfjrJMTZNCqaP6glmdfj9Zo7KVg==", + "license": "MIT", + "peerDependencies": { + "@capacitor/core": ">=7.0.0" + } + }, "node_modules/chalk": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", diff --git a/materialious/electron/package.json b/materialious/electron/package.json index 20564efa..1b662e42 100644 --- a/materialious/electron/package.json +++ b/materialious/electron/package.json @@ -24,6 +24,7 @@ "dependencies": { "@capacitor-community/electron": "^5.0.0", "bgutils-js": "^3.2.0", + "capacitor-nodejs": "https://github.com/hampoelz/capacitor-nodejs/releases/download/v1.0.0-beta.9/capacitor-nodejs.tgz", "chokidar": "~5.0.0", "electron-is-dev": "~2.0.0", "electron-serve": "~3.0.0", @@ -43,4 +44,4 @@ "capacitor", "electron" ] -} \ No newline at end of file +} diff --git a/materialious/electron/src/rt/electron-plugins.js b/materialious/electron/src/rt/electron-plugins.js index b33b2826..5f312366 100644 --- a/materialious/electron/src/rt/electron-plugins.js +++ b/materialious/electron/src/rt/electron-plugins.js @@ -1,4 +1,6 @@ /* eslint-disable @typescript-eslint/no-var-requires */ +const CapacitorNodejs = require('../../../node_modules/capacitor-nodejs/electron/dist/plugin.js'); module.exports = { + CapacitorNodejs, } \ No newline at end of file diff --git a/materialious/package-lock.json b/materialious/package-lock.json index 578b800b..640e22d0 100644 --- a/materialious/package-lock.json +++ b/materialious/package-lock.json @@ -1,12 +1,12 @@ { "name": "materialious", - "version": "1.12.0", + "version": "1.12.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "materialious", - "version": "1.12.0", + "version": "1.12.3", "hasInstallScript": true, "dependencies": { "@capacitor-community/electron": "^5.0.1", @@ -25,6 +25,7 @@ "bgutils-js": "^3.2.0", "capacitor-nodejs": "https://github.com/hampoelz/capacitor-nodejs/releases/download/v1.0.0-beta.9/capacitor-nodejs.tgz", "dayjs": "^1.11.19", + "dexie": "^4.2.1", "fuse.js": "^7.0.0", "googlevideo": "^4.0.4", "he": "^1.2.0", @@ -5669,6 +5670,12 @@ "integrity": "sha512-69sM5yrHfFLJt0AZ9QqZXGCPfJ7fQjvpln3Rq5+PS03LD32Ost1Q9N+eEnaQwGRIriKkMImXD56ocjQmfjbV3w==", "license": "MIT" }, + "node_modules/dexie": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/dexie/-/dexie-4.2.1.tgz", + "integrity": "sha512-Ckej0NS6jxQ4Po3OrSQBFddayRhTCic2DoCAG5zacOfOVB9P2Q5Xc5uL/nVa7ZVs+HdMnvUPzLFCB/JwpB6Csg==", + "license": "Apache-2.0" + }, "node_modules/dezalgo": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/dezalgo/-/dezalgo-1.0.4.tgz", diff --git a/materialious/package.json b/materialious/package.json index 47aa1561..91fdcdda 100644 --- a/materialious/package.json +++ b/materialious/package.json @@ -57,6 +57,7 @@ "bgutils-js": "^3.2.0", "capacitor-nodejs": "https://github.com/hampoelz/capacitor-nodejs/releases/download/v1.0.0-beta.9/capacitor-nodejs.tgz", "dayjs": "^1.11.19", + "dexie": "^4.2.1", "fuse.js": "^7.0.0", "googlevideo": "^4.0.4", "he": "^1.2.0", @@ -73,4 +74,4 @@ "svelte-infinite-loading": "^1.4.0", "youtubei.js": "^16.0.1" } -} \ No newline at end of file +} diff --git a/materialious/src/lib/api/model.ts b/materialious/src/lib/api/model.ts index 9e372e0e..7fca2490 100644 --- a/materialious/src/lib/api/model.ts +++ b/materialious/src/lib/api/model.ts @@ -23,6 +23,9 @@ export interface VideoBase { lengthSeconds: number; viewCountText: string; viewCount?: number; + // Means it was given preference in rankings due to + // a users settings + promotedBy?: 'favourited'; } export interface ResolvedUrl { @@ -205,6 +208,9 @@ export interface PlaylistPageVideo extends Omit { indexId: string; authorId: string; viewCount: number; + // Means it was given preference in rankings due to + // a users settings + promotedBy?: 'favourited'; } export interface ChannelContentVideos { diff --git a/materialious/src/lib/components/Thumbnail.svelte b/materialious/src/lib/components/Thumbnail.svelte index 6753e44c..2260246c 100644 --- a/materialious/src/lib/components/Thumbnail.svelte +++ b/materialious/src/lib/components/Thumbnail.svelte @@ -229,6 +229,10 @@

{video.author}

{/if} + {#if video.promotedBy === 'favourited'} + star + {/if} + {#if !('publishedText' in video) && 'viewCountText' in video} • {video.viewCountText ?? cleanNumber(video.viewCount ?? 0)} diff --git a/materialious/src/lib/components/watch/Author.svelte b/materialious/src/lib/components/watch/Author.svelte index 292bcf9a..2265ff89 100644 --- a/materialious/src/lib/components/watch/Author.svelte +++ b/materialious/src/lib/components/watch/Author.svelte @@ -6,6 +6,8 @@ import { truncate } from '$lib/misc'; import { authStore, interfaceLowBandwidthMode, isAndroidTvStore } from '$lib/store'; import { _ } from '$lib/i18n'; + import { localDb } from '$lib/dexie'; + import { onMount } from 'svelte'; let { video, @@ -13,6 +15,16 @@ hideSubscribe = false }: { video: VideoPlay; subscribed?: boolean; hideSubscribe?: boolean } = $props(); + let favoritedChannel = $state(false); + + const favoriteChannelItem = localDb.favouriteChannels.filter((item) => { + return item.channelId === video.authorId; + }); + + onMount(async () => { + favoritedChannel = (await favoriteChannelItem.count()) > 0; + }); + async function toggleSubscribed() { if (subscribed) { await deleteUnsubscribe(video.authorId); @@ -22,6 +34,16 @@ subscribed = !subscribed; } + + async function toggleFavourited() { + if (favoritedChannel) { + await favoriteChannelItem.delete(); + favoritedChannel = false; + } else { + await localDb.favouriteChannels.add({ channelId: video.authorId, created: new Date() }); + favoritedChannel = true; + } + }