Bookmarks web app part 2 (#178)

* Message for no bookmarks

* feed lazy loading

* cached fetch

* Versioned cache

* comment
This commit is contained in:
Brahim Hadriche authored and GitHub committed 2023-10-24 13:41:13 -04:00
1 parent 57fa1c5c3f
commit 072b93728a
3 files changed
+150 -64

No files matched your search

@@ -6,7 +6,7 @@
import ChannelCell from "./ChannelCell.svelte";
export let feed: any = undefined;
export let videos = undefined;
export let videos = [];
enum FeedLoadState {
None,
@@ -22,6 +22,7 @@
let itemWidths = [];
let carouselElement;
let carouselElementIntersecting = false;
let scrollStart = 0;
let scrollEnd = 0;
@@ -30,8 +31,23 @@
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 && itemWidths && itemWidths.length) {
if (
carouselElement &&
carouselElementIntersecting &&
itemWidths &&
itemWidths.length
) {
recalculateVisibileCells();
}
}
@@ -42,6 +58,12 @@
}
}
$: {
if (carouselElement) {
intersectionObserver.observe(carouselElement);
}
}
let invidiousApi = new InvidiousApi();
playletStateStore.subscribe((value) => {
@@ -61,6 +83,14 @@
return;
}
if (!carouselElementIntersecting) {
return;
}
if (scrollEnd < videos.length - 3) {
return;
}
if (
feedLoadState === FeedLoadState.Loading ||
feedLoadState === FeedLoadState.Loaded
@@ -191,29 +221,26 @@
}
</script>
{#if videos}
<div class="text-lg font-semibold m-4">
{feed.title}
</div>
<div
class="carousel carousel-center rounded-box w-full space-x-4"
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}
<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}
</div>
{/each}
</div>
{/if}
{/if}
</div>
{/each}
</div>