Check if indexdb exists

This commit is contained in:
WardPearce
2025-12-08 23:03:59 +13:00
parent e39fce51e2
commit a1c4c30d9d
4 changed files with 35 additions and 10 deletions
+1
View File
@@ -0,0 +1 @@
words = ["favourite"]
@@ -78,6 +78,7 @@
{$_('unsubscribe')}
{/if}
</button>
{#if window.indexedDB}
<button
class:inverse-surface={!favoritedChannel}
class:border={favoritedChannel}
@@ -88,6 +89,7 @@
{favoritedChannel ? $_('unfavouriteChannel') : $_('favouriteChannel')}
</div>
</button>
{/if}
{:else}
<button class="inverse-surface" disabled>
{$_('subscribe')}
+20
View File
@@ -0,0 +1,20 @@
import type { Table } from 'dexie';
import Dexie from 'dexie';
export interface FavouriteChannels {
channelId: string;
created: Date;
}
export class MaterialiousDb extends Dexie {
favouriteChannels!: Table<FavouriteChannels>;
constructor() {
super('materialious');
this.version(1).stores({
favouriteChannels: 'channelId, created'
});
}
}
export const localDb = new MaterialiousDb();
@@ -9,6 +9,8 @@ import { get } from 'svelte/store';
async function sortVideosByFavourites(
videos: (VideoBase | Video | PlaylistPageVideo)[]
): Promise<(VideoBase | Video | PlaylistPageVideo)[]> {
if (!window.indexedDB) return videos;
const favouritedChannels = (await localDb.favouriteChannels.toArray()).map(
(channel) => channel.channelId
);