Refactor casting dialog and add thumbnails (#184)
This commit is contained in:
1 parent
f58137b326
commit
af1fa0b401
17 files changed
+525
-393
No files matched your search
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import VideoListRow from "./Home/VideoListRow.svelte";
|
||||
import VideoListRow from "lib/VideoFeed/VideoListRow.svelte";
|
||||
import { bookmarksStore } from "lib/Stores";
|
||||
|
||||
export let visibility: boolean;
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { PlayletApi } from "lib/Api/PlayletApi";
|
||||
import { playletStateStore } from "lib/Stores";
|
||||
|
||||
export let author: string | undefined = undefined;
|
||||
export let authorId: string | undefined = undefined;
|
||||
export let authorThumbnails: any[] | undefined = undefined;
|
||||
export let channelHandle: string | undefined = undefined;
|
||||
export let subCount: number | undefined = undefined;
|
||||
|
||||
// svelte-ignore unused-export-let
|
||||
export let type: string = undefined;
|
||||
|
||||
let modal;
|
||||
let tvName = "Roku TV";
|
||||
let invidiousInstance;
|
||||
|
||||
playletStateStore.subscribe((value) => {
|
||||
tvName = value?.device?.friendly_name ?? "Roku TV";
|
||||
invidiousInstance = value?.invidious?.current_instance;
|
||||
});
|
||||
|
||||
function getThumbnailUrl() {
|
||||
if (!authorThumbnails || authorThumbnails.length === 0) {
|
||||
return "";
|
||||
}
|
||||
const authorThumbnail = authorThumbnails[authorThumbnails.length - 1];
|
||||
let url = authorThumbnail.url;
|
||||
if (url.startsWith("//")) {
|
||||
url = "https:" + url;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
async function openChannelOnTv() {
|
||||
await PlayletApi.openChannel(authorId);
|
||||
}
|
||||
|
||||
function openInvidiousInNewTab() {
|
||||
let url = `${invidiousInstance}/channel/${authorId}`;
|
||||
window.open(url);
|
||||
}
|
||||
</script>
|
||||
|
||||
<button class="w-60 p-2" on:click={modal.showModal()}>
|
||||
<div class="card card-compact bg-base-100 shadow-xl border border-neutral">
|
||||
<figure class="relative">
|
||||
<img
|
||||
class="w-44 rounded-full aspect-square object-cover"
|
||||
loading="lazy"
|
||||
width="176"
|
||||
height="176"
|
||||
src={getThumbnailUrl()}
|
||||
alt={author}
|
||||
/>
|
||||
</figure>
|
||||
<div class="card-body">
|
||||
<h3 class="card-title text-base line-clamp-1 min-h-8">{author}</h3>
|
||||
<div>{subCount} subscribers</div>
|
||||
<div>{channelHandle || ""}</div>
|
||||
</div>
|
||||
</div>
|
||||
</button>
|
||||
<!-- TODO:P2 a dialog for every video is very slow. Need to reuse the same one -->
|
||||
<dialog bind:this={modal} id="modal_{authorId}" class="modal">
|
||||
<form method="dialog" class="modal-box bg-base-100">
|
||||
<h3 class="text-lg m-5">{author}</h3>
|
||||
<div class="flex flex-col">
|
||||
<button class="btn m-2" on:click={openChannelOnTv}>
|
||||
Open on {tvName}
|
||||
</button>
|
||||
<button class="btn m-2" on:click={openInvidiousInNewTab}>
|
||||
Open in Invidious
|
||||
</button>
|
||||
<button class="btn m-2">Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
<form method="dialog" class="modal-backdrop">
|
||||
<button>close</button>
|
||||
</form>
|
||||
</dialog>
|
||||
@@ -1,114 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { PlayletApi } from "lib/Api/PlayletApi";
|
||||
import { playletStateStore } from "lib/Stores";
|
||||
|
||||
export let title: string | undefined = undefined;
|
||||
export let author: string | undefined = undefined;
|
||||
export let playlistId: string | undefined = undefined;
|
||||
export let playlistThumbnail: string | undefined = undefined;
|
||||
export let videoCount: number | undefined = undefined;
|
||||
export let videos: any[] | undefined = undefined;
|
||||
|
||||
// svelte-ignore unused-export-let
|
||||
export let type: string = undefined;
|
||||
|
||||
let modal;
|
||||
let tvName = "Roku TV";
|
||||
let invidiousInstance;
|
||||
|
||||
playletStateStore.subscribe((value) => {
|
||||
tvName = value?.device?.friendly_name ?? "Roku TV";
|
||||
invidiousInstance = value?.invidious?.current_instance;
|
||||
});
|
||||
|
||||
function getThumbnailUrl(quality: string = "medium") {
|
||||
let url = "";
|
||||
if (playlistThumbnail) {
|
||||
url = playlistThumbnail;
|
||||
if (url.startsWith("/") && invidiousInstance) {
|
||||
url = invidiousInstance + url;
|
||||
}
|
||||
} else if (videos && videos.length) {
|
||||
const video = videos[0];
|
||||
if (video.videoThumbnails) {
|
||||
const videoThumbnail =
|
||||
video.videoThumbnails.find(
|
||||
(thumbnail) => thumbnail.quality === quality
|
||||
) || video.videoThumbnails[0];
|
||||
url = videoThumbnail.url;
|
||||
}
|
||||
if (url.startsWith("/") && invidiousInstance) {
|
||||
url = invidiousInstance + url;
|
||||
}
|
||||
}
|
||||
if (url === "") {
|
||||
url = `${invidiousInstance}/vi/-----------/mqdefault.jpg`;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
async function playPlaylistOnTv() {
|
||||
await PlayletApi.playPlaylist(playlistId, title, videoCount);
|
||||
}
|
||||
|
||||
async function queuePlaylistOnTv() {
|
||||
await PlayletApi.queuePlaylist(playlistId, title, videoCount);
|
||||
}
|
||||
|
||||
async function openPlaylistOnTv() {
|
||||
await PlayletApi.openPlaylist(playlistId);
|
||||
}
|
||||
|
||||
function openInvidiousInNewTab() {
|
||||
let url = `${invidiousInstance}/playlist?list=${playlistId}`;
|
||||
window.open(url);
|
||||
}
|
||||
</script>
|
||||
|
||||
<button class="w-80 p-2" on:click={modal.showModal()}>
|
||||
<div class="card card-compact bg-base-100 shadow-xl border border-neutral">
|
||||
<figure class="relative">
|
||||
<img
|
||||
class="w-full rounded-box aspect-video object-cover"
|
||||
loading="lazy"
|
||||
width="320"
|
||||
height="180"
|
||||
src={getThumbnailUrl()}
|
||||
alt={title}
|
||||
/>
|
||||
<div
|
||||
class="absolute bottom-2 right-0 bg-black/70 text-white text-sm rounded-sm pt-1 pb-1 pr-2 pl-2"
|
||||
>
|
||||
{videoCount} videos
|
||||
</div>
|
||||
</figure>
|
||||
<div class="card-body">
|
||||
<h3 class="card-title text-base line-clamp-2 min-h-12">{title}</h3>
|
||||
<div class="font-semibold">{author}</div>
|
||||
</div>
|
||||
</div>
|
||||
</button>
|
||||
<!-- TODO:P2 a dialog for every video is very slow. Need to reuse the same one -->
|
||||
<dialog bind:this={modal} id="modal_{playlistId}" class="modal">
|
||||
<form method="dialog" class="modal-box bg-base-100">
|
||||
<h3 class="text-lg m-5">{title}</h3>
|
||||
<div class="flex flex-col">
|
||||
<button class="btn m-2" on:click={playPlaylistOnTv}>
|
||||
Play on {tvName}
|
||||
</button>
|
||||
<button class="btn m-2" on:click={queuePlaylistOnTv}>
|
||||
Queue on {tvName}
|
||||
</button>
|
||||
<button class="btn m-2" on:click={openPlaylistOnTv}>
|
||||
Open on {tvName}
|
||||
</button>
|
||||
<button class="btn m-2" on:click={openInvidiousInNewTab}>
|
||||
Open in Invidious
|
||||
</button>
|
||||
<button class="btn m-2">Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
<form method="dialog" class="modal-backdrop">
|
||||
<button>close</button>
|
||||
</form>
|
||||
</dialog>
|
||||
@@ -1,256 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { PlayletApi } from "lib/Api/PlayletApi";
|
||||
import { playletStateStore } from "lib/Stores";
|
||||
import VideoStartAt from "lib/VideoStartAt.svelte";
|
||||
|
||||
export let title: string | undefined = undefined;
|
||||
export let videoId: string | undefined = undefined;
|
||||
export let author: string | undefined = undefined;
|
||||
export let videoThumbnails: any[] | undefined = undefined;
|
||||
export let viewCount: number | undefined = undefined;
|
||||
export let publishedText: string | undefined = undefined;
|
||||
export let isUpcoming: boolean = undefined;
|
||||
export let premiereTimestamp: number | undefined = undefined;
|
||||
export let lengthSeconds: number = undefined;
|
||||
export let liveNow: boolean = undefined;
|
||||
|
||||
// svelte-ignore unused-export-let
|
||||
export let type: string = undefined;
|
||||
// svelte-ignore unused-export-let
|
||||
export let authorId: string = undefined;
|
||||
// svelte-ignore unused-export-let
|
||||
export let authorUrl: string = undefined;
|
||||
// svelte-ignore unused-export-let
|
||||
export let authorVerified: boolean = undefined;
|
||||
// svelte-ignore unused-export-let
|
||||
export let description: string = undefined;
|
||||
// svelte-ignore unused-export-let
|
||||
export let descriptionHtml: string = undefined;
|
||||
// svelte-ignore unused-export-let
|
||||
export let viewCountText: string = undefined;
|
||||
// svelte-ignore unused-export-let
|
||||
export let published: number = undefined;
|
||||
// svelte-ignore unused-export-let
|
||||
export let premium: boolean = undefined;
|
||||
// svelte-ignore unused-export-let
|
||||
export let index: number = undefined;
|
||||
// svelte-ignore unused-export-let
|
||||
export let indexId: string = undefined;
|
||||
|
||||
let modal;
|
||||
let tvName = "Roku TV";
|
||||
let invidiousInstance;
|
||||
let videoStartAtChecked;
|
||||
let videoStartAtTimestamp;
|
||||
|
||||
playletStateStore.subscribe((value) => {
|
||||
tvName = value?.device?.friendly_name ?? "Roku TV";
|
||||
invidiousInstance = value?.invidious?.current_instance;
|
||||
});
|
||||
|
||||
function getViewCountDateText() {
|
||||
if (isUpcoming) {
|
||||
return `Premeres in ${getFormattedTimeLeft(premiereTimestamp)}`;
|
||||
}
|
||||
const pubText = publishedText || "";
|
||||
const viewCountText = formatViewCount(viewCount);
|
||||
|
||||
if (pubText === "" && viewCountText === "") {
|
||||
return "";
|
||||
}
|
||||
|
||||
return `${pubText} • ${viewCountText}`;
|
||||
}
|
||||
|
||||
function getFormattedTimeLeft(unixTimestamp) {
|
||||
if (unixTimestamp === "invalid") {
|
||||
return "N/A";
|
||||
}
|
||||
|
||||
const currentTime = Math.floor(Date.now() / 1000);
|
||||
let timeLeft = unixTimestamp - currentTime;
|
||||
if (timeLeft <= 0) {
|
||||
return "now";
|
||||
}
|
||||
|
||||
if (timeLeft < 60) {
|
||||
let result = `${timeLeft} second`;
|
||||
if (timeLeft > 1) {
|
||||
result += "s";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
timeLeft = timeLeft / 60.0;
|
||||
if (timeLeft < 60) {
|
||||
timeLeft = Math.floor(timeLeft);
|
||||
let result = `${timeLeft} minute`;
|
||||
if (timeLeft > 1) {
|
||||
result += "s";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
timeLeft = timeLeft / 60.0;
|
||||
if (timeLeft < 24) {
|
||||
timeLeft = Math.floor(timeLeft);
|
||||
let result = `${timeLeft} hour`;
|
||||
if (timeLeft > 1) {
|
||||
result += "s";
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
timeLeft = timeLeft / 24.0;
|
||||
timeLeft = Math.floor(timeLeft);
|
||||
let result = `${timeLeft} day`;
|
||||
if (timeLeft > 1) {
|
||||
result += "s";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
function getThumbnailUrl(quality: string = "medium") {
|
||||
if (!videoThumbnails || videoThumbnails.length === 0) {
|
||||
return "";
|
||||
}
|
||||
const videoThumbnail =
|
||||
videoThumbnails.find((thumbnail) => thumbnail.quality === quality) ||
|
||||
videoThumbnails[0];
|
||||
let url = videoThumbnail.url;
|
||||
if (url.startsWith("/") && invidiousInstance) {
|
||||
url = invidiousInstance + url;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
function formatViewCount(viewCount) {
|
||||
if (isNaN(viewCount)) {
|
||||
return "";
|
||||
}
|
||||
if (viewCount < 1000) {
|
||||
return `${formatFloat(viewCount)} views`;
|
||||
}
|
||||
|
||||
viewCount = viewCount / 1000;
|
||||
if (viewCount < 1000) {
|
||||
return `${formatFloat(viewCount)}K views`;
|
||||
}
|
||||
|
||||
viewCount = viewCount / 1000;
|
||||
if (viewCount < 1000) {
|
||||
return `${formatFloat(viewCount)}M views`;
|
||||
}
|
||||
|
||||
viewCount = viewCount / 1000;
|
||||
return `${formatFloat(viewCount)}B views`;
|
||||
}
|
||||
|
||||
function formatFloat(X) {
|
||||
X = X * 10;
|
||||
X = X + 0.5;
|
||||
X = Math.floor(X);
|
||||
X = X / 10;
|
||||
return X;
|
||||
}
|
||||
|
||||
function getFormattedTime(length) {
|
||||
const hours = Math.floor(length / 3600);
|
||||
const minutes = Math.floor((length / 60) % 60);
|
||||
const seconds = length % 60;
|
||||
|
||||
const secondsString = seconds < 10 ? `0${seconds}` : seconds.toString();
|
||||
const minutesString =
|
||||
minutes < 10 && hours > 0 ? `0${minutes}` : minutes.toString();
|
||||
|
||||
let formattedTime = minutesString + ":" + secondsString;
|
||||
|
||||
if (hours > 0) {
|
||||
formattedTime = hours.toString() + ":" + formattedTime;
|
||||
}
|
||||
|
||||
return formattedTime;
|
||||
}
|
||||
|
||||
function isVideoLive() {
|
||||
if (liveNow) {
|
||||
return true;
|
||||
}
|
||||
return lengthSeconds === 0 && viewCount === 0;
|
||||
}
|
||||
|
||||
async function playVideoOnTv() {
|
||||
const timestamp = videoStartAtChecked ? videoStartAtTimestamp : undefined;
|
||||
await PlayletApi.playVideo(videoId, timestamp, title, author);
|
||||
}
|
||||
|
||||
async function queueVideoOnTv() {
|
||||
const timestamp = videoStartAtChecked ? videoStartAtTimestamp : undefined;
|
||||
await PlayletApi.queueVideo(videoId, timestamp, title, author);
|
||||
}
|
||||
|
||||
function openInvidiousInNewTab() {
|
||||
let url = `${invidiousInstance}/watch?v=${videoId}`;
|
||||
if (videoStartAtChecked && videoStartAtTimestamp) {
|
||||
url += `&t=${videoStartAtTimestamp}`;
|
||||
}
|
||||
window.open(url);
|
||||
}
|
||||
</script>
|
||||
|
||||
<button class="w-80 p-2" on:click={modal.showModal()}>
|
||||
<div class="card card-compact bg-base-100 shadow-xl border border-neutral">
|
||||
<figure class="relative">
|
||||
<img
|
||||
class="w-full rounded-box aspect-video object-cover"
|
||||
loading="lazy"
|
||||
width="320"
|
||||
height="180"
|
||||
src={getThumbnailUrl()}
|
||||
alt={title}
|
||||
/>
|
||||
{#if isVideoLive()}
|
||||
<div
|
||||
class="absolute bottom-2 right-0 bg-red-500 text-white text-sm rounded-sm font-bold pt-1 pb-1 pr-2 pl-2"
|
||||
>
|
||||
LIVE
|
||||
</div>
|
||||
{:else if lengthSeconds}
|
||||
<div
|
||||
class="absolute bottom-2 right-0 bg-black/70 text-white text-sm rounded-sm pt-1 pb-1 pr-2 pl-2"
|
||||
>
|
||||
{getFormattedTime(lengthSeconds)}
|
||||
</div>
|
||||
{/if}
|
||||
</figure>
|
||||
<div class="card-body">
|
||||
<h3 class="card-title text-base line-clamp-2 min-h-12">{title}</h3>
|
||||
<div class="font-semibold">{author}</div>
|
||||
<div>{getViewCountDateText()}</div>
|
||||
</div>
|
||||
</div>
|
||||
</button>
|
||||
<!-- TODO:P2 a dialog for every video is very slow. Need to reuse the same one -->
|
||||
<dialog bind:this={modal} id="modal_{videoId}" class="modal">
|
||||
<form method="dialog" class="modal-box bg-base-100">
|
||||
<h3 class="text-lg m-5">{title}</h3>
|
||||
<div class="flex flex-col">
|
||||
<VideoStartAt
|
||||
bind:checked={videoStartAtChecked}
|
||||
bind:timestamp={videoStartAtTimestamp}
|
||||
{lengthSeconds}
|
||||
/>
|
||||
<button class="btn m-2" on:click={playVideoOnTv}>Play on {tvName}</button>
|
||||
<button class="btn m-2" on:click={queueVideoOnTv}
|
||||
>Queue on {tvName}
|
||||
</button>
|
||||
<button class="btn m-2" on:click={openInvidiousInNewTab}
|
||||
>Open in Invidious</button
|
||||
>
|
||||
<button class="btn m-2">Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
<form method="dialog" class="modal-backdrop">
|
||||
<button>close</button>
|
||||
</form>
|
||||
</dialog>
|
||||
@@ -1,263 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { InvidiousApi } from "lib/Api/InvidiousApi";
|
||||
import { invidiousVideoApiStore, playletStateStore } from "lib/Stores";
|
||||
import VideoCell from "lib/Screens/Home/VideoCell.svelte";
|
||||
import PlaylistCell from "lib/Screens/Home/PlaylistCell.svelte";
|
||||
import ChannelCell from "./ChannelCell.svelte";
|
||||
|
||||
// TODO:P1 figure out why some uncached feeds (e.g. channels/ucid/videos) get hit twice
|
||||
export let feed: any = undefined;
|
||||
export let videos = [];
|
||||
|
||||
enum FeedLoadState {
|
||||
None,
|
||||
Loading,
|
||||
Loaded,
|
||||
LoadedPage,
|
||||
Error,
|
||||
}
|
||||
|
||||
let feedLoadState = FeedLoadState.None;
|
||||
let feedSourcesIndex = 0;
|
||||
|
||||
let itemWidths = [];
|
||||
|
||||
let carouselElement;
|
||||
let carouselElementIntersecting = false;
|
||||
|
||||
let scrollStart = 0;
|
||||
let scrollEnd = 0;
|
||||
|
||||
// w-80|w-60 p-2: 320px|240px + 16px padding on each side
|
||||
const videoItemWidth = 320 + 16 * 2;
|
||||
const channelItemWidth = 240 + 16 * 2;
|
||||
|
||||
const intersectionObserver = new IntersectionObserver(
|
||||
function (entries) {
|
||||
carouselElementIntersecting = entries[0].isIntersecting;
|
||||
if (carouselElementIntersecting) {
|
||||
loadRow();
|
||||
}
|
||||
},
|
||||
{ threshold: [0] }
|
||||
);
|
||||
|
||||
$: {
|
||||
if (
|
||||
carouselElement &&
|
||||
carouselElementIntersecting &&
|
||||
itemWidths &&
|
||||
itemWidths.length
|
||||
) {
|
||||
recalculateVisibileCells();
|
||||
}
|
||||
}
|
||||
|
||||
$: {
|
||||
if (videos && scrollEnd >= videos.length - 1) {
|
||||
loadRow();
|
||||
}
|
||||
}
|
||||
|
||||
$: {
|
||||
if (carouselElement) {
|
||||
intersectionObserver.observe(carouselElement);
|
||||
}
|
||||
}
|
||||
|
||||
let invidiousApi = new InvidiousApi();
|
||||
|
||||
playletStateStore.subscribe((value) => {
|
||||
invidiousApi.instance = value?.invidious?.current_instance;
|
||||
invidiousApi.userCountryCode = value?.device?.user_country_code ?? "US";
|
||||
invidiousApi.isLoggedIn = value.invidious?.logged_in ?? false;
|
||||
loadRow();
|
||||
});
|
||||
|
||||
invidiousVideoApiStore.subscribe((value) => {
|
||||
invidiousApi.endpoints = value;
|
||||
loadRow();
|
||||
});
|
||||
|
||||
async function loadRow() {
|
||||
if (!invidiousApi.canMakeRequest()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!carouselElementIntersecting) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (scrollEnd < videos.length - 3) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
feedLoadState === FeedLoadState.Loading ||
|
||||
feedLoadState === FeedLoadState.Loaded
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
feedLoadState = FeedLoadState.Loading;
|
||||
|
||||
let totalFetchedItems = 0;
|
||||
|
||||
while (true) {
|
||||
const feedSources = feed.feedSources;
|
||||
if (feedSourcesIndex >= feedSources.length) {
|
||||
break;
|
||||
}
|
||||
|
||||
const feedSource = feedSources[feedSourcesIndex];
|
||||
feedSource.state = feedSource.state || {};
|
||||
if (
|
||||
feedSource.state.loadState === FeedLoadState.Loaded ||
|
||||
feedSource.state.loadState === FeedLoadState.Error
|
||||
) {
|
||||
feedSourcesIndex++;
|
||||
continue;
|
||||
}
|
||||
|
||||
invidiousApi.markFeedSourcePagination(feedSource);
|
||||
|
||||
try {
|
||||
const result = await invidiousApi.makeRequest(feedSource);
|
||||
if (!result) {
|
||||
feedSource.state.loadState = FeedLoadState.Error;
|
||||
feedSourcesIndex++;
|
||||
if (feedSourcesIndex >= feedSources.length) {
|
||||
feedLoadState = FeedLoadState.Loaded;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
const hasContinuation = !!result.continuation;
|
||||
if (hasContinuation) {
|
||||
feedSource.state.continuation = result.continuation;
|
||||
}
|
||||
|
||||
if (result.items.length > 0) {
|
||||
const paginationType = feedSource.state.paginationType;
|
||||
if (paginationType === "Continuation" && hasContinuation) {
|
||||
feedSource.state.loadState = FeedLoadState.LoadedPage;
|
||||
} else if (paginationType === "Pages") {
|
||||
feedSource.state.loadState = FeedLoadState.LoadedPage;
|
||||
} else {
|
||||
feedSource.state.loadState = FeedLoadState.Loaded;
|
||||
}
|
||||
} else {
|
||||
feedSource.state.loadState = FeedLoadState.Loaded;
|
||||
}
|
||||
|
||||
if (
|
||||
feedSource.state.loadState === FeedLoadState.Loaded &&
|
||||
feedSourcesIndex === feedSources.length - 1
|
||||
) {
|
||||
feedLoadState = FeedLoadState.Loaded;
|
||||
} else {
|
||||
feedLoadState = FeedLoadState.LoadedPage;
|
||||
}
|
||||
|
||||
if (result && result.items) {
|
||||
const newVideos = result.items;
|
||||
|
||||
newVideos.forEach((item) => {
|
||||
if (item.videoId) {
|
||||
item.type = "video";
|
||||
} else if (item.playlistId) {
|
||||
item.type = "playlist";
|
||||
}
|
||||
});
|
||||
|
||||
const newItemWidths = newVideos.map((video) => {
|
||||
if (video.type === "channel") {
|
||||
return channelItemWidth;
|
||||
} else {
|
||||
return videoItemWidth;
|
||||
}
|
||||
});
|
||||
|
||||
itemWidths = [...itemWidths, ...newItemWidths];
|
||||
videos = [...(videos || []), ...newVideos];
|
||||
|
||||
totalFetchedItems += result.items.length;
|
||||
if (totalFetchedItems >= 3) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
// TODO:P0 handle case of unauthenticated calls
|
||||
// TODO:P0 handle case of popular feed disabled
|
||||
// If we're done loading all the feed, but still have no videos, hide the whole component.
|
||||
console.error(error);
|
||||
feedSource.state.loadState = FeedLoadState.Error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function recalculateVisibileCells() {
|
||||
let scrollLeft = carouselElement.scrollLeft;
|
||||
const clientWidth = carouselElement.clientWidth || window.innerWidth;
|
||||
|
||||
let _scrollStart = 0;
|
||||
while (
|
||||
_scrollStart < itemWidths.length &&
|
||||
scrollLeft > itemWidths[_scrollStart]
|
||||
) {
|
||||
scrollLeft -= itemWidths[_scrollStart];
|
||||
_scrollStart++;
|
||||
}
|
||||
|
||||
let _scrollEnd = _scrollStart;
|
||||
while (
|
||||
_scrollEnd < itemWidths.length &&
|
||||
scrollLeft + clientWidth > itemWidths[_scrollEnd]
|
||||
) {
|
||||
scrollLeft -= itemWidths[_scrollEnd];
|
||||
_scrollEnd++;
|
||||
}
|
||||
|
||||
_scrollStart = Math.max(0, _scrollStart - 1);
|
||||
_scrollEnd = Math.min(itemWidths.length - 1, _scrollEnd + 1);
|
||||
|
||||
if (_scrollStart !== scrollStart) {
|
||||
scrollStart = _scrollStart;
|
||||
}
|
||||
if (_scrollEnd !== scrollEnd) {
|
||||
scrollEnd = _scrollEnd;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- Hide rows that are loaded but have no videos. Typically a
|
||||
disabled feed (like popular) or unauthenticated.
|
||||
TODO:P0 show action nodes (action to login)
|
||||
-->
|
||||
{#if feedLoadState !== FeedLoadState.Loaded || videos.length !== 0}
|
||||
<div class="text-lg font-semibold m-4">
|
||||
{feed.title}
|
||||
</div>
|
||||
<div
|
||||
class="carousel carousel-center rounded-box w-full space-x-4"
|
||||
style="min-height: 16rem;"
|
||||
bind:this={carouselElement}
|
||||
on:scroll={recalculateVisibileCells}
|
||||
>
|
||||
{#each videos as video, i}
|
||||
<div
|
||||
class="carousel-item {video.type === 'channel' ? 'w-60' : 'w-80'} p-2"
|
||||
>
|
||||
{#if i >= scrollStart && i <= scrollEnd}
|
||||
{#if video.type === "video"}
|
||||
<VideoCell {...video} />
|
||||
{:else if video.type === "playlist"}
|
||||
<PlaylistCell {...video} />
|
||||
{:else if video.type === "channel"}
|
||||
<ChannelCell {...video} />
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import VideoListRow from "lib/Screens/Home/VideoListRow.svelte";
|
||||
import VideoListRow from "lib/VideoFeed/VideoListRow.svelte";
|
||||
import { homeLayoutFileStore } from "lib/Stores";
|
||||
|
||||
export let visibility: boolean;
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
import { InvidiousApi } from "lib/Api/InvidiousApi";
|
||||
import { PlayletApi } from "lib/Api/PlayletApi";
|
||||
import { playletStateStore, searchHistoryStore } from "lib/Stores";
|
||||
import VideoCell from "lib/Screens/Home/VideoCell.svelte";
|
||||
import PlaylistCell from "lib/Screens/Home/PlaylistCell.svelte";
|
||||
import VideoCell from "lib/VideoFeed/VideoCell.svelte";
|
||||
import PlaylistCell from "lib/VideoFeed/PlaylistCell.svelte";
|
||||
import ChannelCell from "lib/VideoFeed/ChannelCell.svelte";
|
||||
import SearchThinIcon from "assets/search-thin-icon.svg.svelte";
|
||||
import FiltersIcon from "assets/filters.svg.svelte";
|
||||
import ChannelCell from "./Home/ChannelCell.svelte";
|
||||
import SearchFilters from "./Search/SearchFilters.svelte";
|
||||
|
||||
export let visibility: boolean;
|
||||
|
||||
Reference in new issue
Block a user