An attempt to fix list performance with virtual list (#100)
This commit is contained in:
1 parent
d9dd6bc2f7
commit
a070343a78
2 files changed
+40
-8
No files matched your search
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- Video duration formatting in cast dialog
|
||||
- (Removed) Workaround for Invidious token expiring due to misconfigured instance
|
||||
- Crash when loading the home screen [#83](https://github.com/iBicha/playlet/issues/83)
|
||||
- Performance of home screen in web app
|
||||
|
||||
## [0.10.1] - 2023-06-28
|
||||
|
||||
|
||||
@@ -1,14 +1,31 @@
|
||||
<script lang="ts">
|
||||
import { InvidiousApi } from "./InvidiousApi";
|
||||
import {
|
||||
invidiousVideoApiStore,
|
||||
playletStateStore,
|
||||
} from "./Stores";
|
||||
import { invidiousVideoApiStore, playletStateStore } from "./Stores";
|
||||
import VideoCell from "./VideoCell.svelte";
|
||||
|
||||
export let requestData: any = undefined;
|
||||
export let videoRowData = undefined;
|
||||
|
||||
let carouselElement;
|
||||
|
||||
let scrollStart = 0;
|
||||
let scrollEnd = 0;
|
||||
|
||||
// w-80 p-2: 320px + 16px padding on each side
|
||||
const itemWidth = 320 + 16 * 2;
|
||||
|
||||
$: {
|
||||
if (videoRowData && !Array.isArray(videoRowData)) {
|
||||
if (
|
||||
carouselElement &&
|
||||
videoRowData.videos &&
|
||||
videoRowData.videos.length
|
||||
) {
|
||||
recalculateVisibileCells();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let invidiousApi = new InvidiousApi();
|
||||
|
||||
playletStateStore.subscribe((value) => {
|
||||
@@ -29,6 +46,14 @@
|
||||
videoRowData = result;
|
||||
}
|
||||
}
|
||||
|
||||
function recalculateVisibileCells() {
|
||||
const scrollLeft = carouselElement.scrollLeft;
|
||||
const clientWidth = carouselElement.clientWidth;
|
||||
|
||||
scrollStart = Math.floor(scrollLeft / itemWidth) - 1;
|
||||
scrollEnd = Math.ceil((scrollLeft + clientWidth) / itemWidth) + 1;
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if videoRowData}
|
||||
@@ -37,13 +62,19 @@
|
||||
<svelte:self videoRowData={child} />
|
||||
{/each}
|
||||
{:else if videoRowData.title && videoRowData.videos}
|
||||
<div class="text-lg font-semibold m-4">{videoRowData.title}</div>
|
||||
<div class="text-lg font-semibold m-4">
|
||||
{videoRowData.title}
|
||||
</div>
|
||||
<div
|
||||
class="carousel carousel-center rounded-box w-full space-x-4"
|
||||
bind:this={carouselElement}
|
||||
on:scroll={recalculateVisibileCells}
|
||||
>
|
||||
{#each videoRowData.videos as video}
|
||||
<div class="carousel-item">
|
||||
<VideoCell {...video} />
|
||||
{#each videoRowData.videos as video, i}
|
||||
<div class="carousel-item w-80 p-2">
|
||||
{#if i >= scrollStart && i <= scrollEnd}
|
||||
<VideoCell {...video} />
|
||||
{/if}
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user