Check if indexdb exists
This commit is contained in:
@@ -0,0 +1 @@
|
||||
words = ["favourite"]
|
||||
@@ -78,16 +78,18 @@
|
||||
{$_('unsubscribe')}
|
||||
{/if}
|
||||
</button>
|
||||
<button
|
||||
class:inverse-surface={!favoritedChannel}
|
||||
class:border={favoritedChannel}
|
||||
onclick={toggleFavourited}
|
||||
>
|
||||
<i>star</i>
|
||||
<div class="tooltip">
|
||||
{favoritedChannel ? $_('unfavouriteChannel') : $_('favouriteChannel')}
|
||||
</div>
|
||||
</button>
|
||||
{#if window.indexedDB}
|
||||
<button
|
||||
class:inverse-surface={!favoritedChannel}
|
||||
class:border={favoritedChannel}
|
||||
onclick={toggleFavourited}
|
||||
>
|
||||
<i>star</i>
|
||||
<div class="tooltip">
|
||||
{favoritedChannel ? $_('unfavouriteChannel') : $_('favouriteChannel')}
|
||||
</div>
|
||||
</button>
|
||||
{/if}
|
||||
{:else}
|
||||
<button class="inverse-surface" disabled>
|
||||
{$_('subscribe')}
|
||||
|
||||
@@ -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
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user