Skip to content

Commit

Permalink
Only show playable videos in "Continue watching" list
Browse files Browse the repository at this point in the history
  • Loading branch information
niklashigi committed Apr 19, 2020
1 parent 83748e7 commit bb38833
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions source/libs/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface CollectionItem {
image: Image
title: string
titleID: string
playbackAction?: any
edit?: any
}

Expand Down
12 changes: 9 additions & 3 deletions source/libs/fetch-my-videos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ let baseUrl = null
export default async function fetchMyVideos(): Promise<Video[]> {
const storefront = await fetchStorefront()

const collection = storefront.collections.filter(c => c.edit)[0]
const collection = storefront.collections.find(c => c.edit)
if (!collection) throw new Error('No videos found!')

browser.storage.local.set({ [await getCacheKey()]: collection.items as any })

return collection.items.map(parseCollectionItem)
return parseCollectionItems(collection.items)
}

export async function getCachedVideos(): Promise<Video[]> {
const key = await getCacheKey()
const { [key]: items } = await browser.storage.local.get([key])
if (!items) return []

return (items as any).map(parseCollectionItem)
return parseCollectionItems(items as any)
}

async function getCacheKey(): Promise<string> {
Expand All @@ -34,6 +34,12 @@ async function fetchStorefront(): Promise<Storefront> {
return (await (await fetch(endpointUrl)).json()) as Storefront
}

function parseCollectionItems(items: CollectionItem[]): Video[] {
return items
.filter(item => item.playbackAction)
.map(parseCollectionItem)
}

function parseCollectionItem(item: CollectionItem): Video {
const id = item.titleID

Expand Down

0 comments on commit bb38833

Please sign in to comment.