Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

playlist scroll pos #1120

Merged
merged 4 commits into from
Sep 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion web/ts/stream-playlist.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import { DataStore } from "./data-store/data-store";
import { StreamPlaylistEntry } from "./data-store/stream-playlist";

function onVisible(element, callback) {
new IntersectionObserver((entries, observer) => {
entries.forEach((entry) => {
if (entry.intersectionRatio > 0) {
callback(element);
observer.disconnect();
}
});
}).observe(element);
}

export class StreamPlaylist {
private streamId: number;
private elem: HTMLElement;
Expand All @@ -19,11 +30,18 @@ export class StreamPlaylist {
const { prev, next } = this.findNextAndPrev();
this.elem.dispatchEvent(new CustomEvent("update", { detail: { list: this.list, prev, next } }));

// if playlist is hidden and will be visible later
onVisible(this.elem, () => this.scrollSelectedIntoView());

setTimeout(() => {
this.elem.querySelector(".--selected")?.scrollIntoView({ block: "center" });
this.scrollSelectedIntoView();
}, 10);
}

public scrollSelectedIntoView() {
this.elem.querySelector(".--selected").scrollIntoView({ block: "center" });
}

private findNextAndPrev(): { next: StreamPlaylistEntry; prev: StreamPlaylistEntry } {
const streamIndex = this.list.findIndex((e) => e.streamId == this.streamId);
const prevIndex = streamIndex - 1 >= 0 ? streamIndex - 1 : null;
Expand Down
Loading