Improve performance of presentation to load slides faster

This commit is contained in:
Alex Lion
2024-12-30 20:20:48 -05:00
parent 3300bd210d
commit e66da3192d
5 changed files with 32 additions and 26 deletions

View File

@@ -1,3 +1,9 @@
### v.2.3.1
### Fixes and improvements
- Improve performance of presentation to load slides faster
### v.2.3.0 ### v.2.3.0
### Features ### Features

View File

@@ -5,6 +5,8 @@ export class Manager {
this.context = context; this.context = context;
this.currentPage = parseInt(context.el.dataset.currentPage); this.currentPage = parseInt(context.el.dataset.currentPage);
this.maxPage = parseInt(context.el.dataset.maxPage); this.maxPage = parseInt(context.el.dataset.maxPage);
localStorage.setItem("slide-position", this.currentPage);
} }
init() { init() {
@@ -31,19 +33,14 @@ export class Manager {
window.addEventListener("keydown", (e) => { window.addEventListener("keydown", (e) => {
if ((e.target.tagName || "").toLowerCase() != "input") { if ((e.target.tagName || "").toLowerCase() != "input") {
e.preventDefault();
switch (e.key) { switch (e.key) {
case "ArrowUp":
this.prevPage();
break;
case "ArrowLeft": case "ArrowLeft":
e.preventDefault();
this.prevPage(); this.prevPage();
break; break;
case "ArrowRight": case "ArrowRight":
this.nextPage(); e.preventDefault();
break;
case "ArrowDown":
this.nextPage(); this.nextPage();
break; break;
} }
@@ -168,6 +165,7 @@ export class Manager {
if (this.currentPage == this.maxPage - 1) return; if (this.currentPage == this.maxPage - 1) return;
this.currentPage += 1; this.currentPage += 1;
localStorage.setItem("slide-position", this.currentPage);
this.context.pushEventTo(this.context.el, "current-page", { this.context.pushEventTo(this.context.el, "current-page", {
page: this.currentPage.toString(), page: this.currentPage.toString(),
}); });
@@ -177,6 +175,7 @@ export class Manager {
if (this.currentPage == 0) return; if (this.currentPage == 0) return;
this.currentPage -= 1; this.currentPage -= 1;
localStorage.setItem("slide-position", this.currentPage);
this.context.pushEventTo(this.context.el, "current-page", { this.context.pushEventTo(this.context.el, "current-page", {
page: this.currentPage.toString(), page: this.currentPage.toString(),
}); });

View File

@@ -19,6 +19,7 @@ export class Presenter {
controls: false, controls: false,
swipeAngle: false, swipeAngle: false,
startIndex: this.currentPage, startIndex: this.currentPage,
speed: 0,
loop: false, loop: false,
nav: false, nav: false,
}); });
@@ -29,8 +30,13 @@ export class Presenter {
this.context.handleEvent("page", (data) => { this.context.handleEvent("page", (data) => {
//set current page //set current page
if (this.currentPage == data.current_page) {
return;
}
this.currentPage = parseInt(data.current_page); this.currentPage = parseInt(data.current_page);
this.slider.goTo(data.current_page); this.slider.goTo(data.current_page);
}); });
this.context.handleEvent("chat-visible", (data) => { this.context.handleEvent("chat-visible", (data) => {
@@ -103,35 +109,37 @@ export class Presenter {
window.addEventListener("keyup", (e) => { window.addEventListener("keyup", (e) => {
if (e.target.tagName.toLowerCase() != "input") { if (e.target.tagName.toLowerCase() != "input") {
e.preventDefault();
switch (e.key) { switch (e.key) {
case "f": // F case "f": // F
e.preventDefault();
this.fullscreen(); this.fullscreen();
break; break;
case "ArrowUp":
window.opener.dispatchEvent(
new KeyboardEvent("keydown", { key: "ArrowUp" })
);
break;
case "ArrowLeft": case "ArrowLeft":
e.preventDefault();
window.opener.dispatchEvent( window.opener.dispatchEvent(
new KeyboardEvent("keydown", { key: "ArrowLeft" }) new KeyboardEvent("keydown", { key: "ArrowLeft" })
); );
break; break;
case "ArrowRight": case "ArrowRight":
e.preventDefault();
window.opener.dispatchEvent( window.opener.dispatchEvent(
new KeyboardEvent("keydown", { key: "ArrowRight" }) new KeyboardEvent("keydown", { key: "ArrowRight" })
); );
break; break;
case "ArrowDown":
window.opener.dispatchEvent(
new KeyboardEvent("keydown", { key: "ArrowDown" })
);
break;
} }
} }
}); });
window.addEventListener("storage", (e) => {
console.log(e)
if (e.key == "slide-position") {
console.log("settings new value " + Date.now())
this.currentPage = parseInt(e.newValue);
this.slider.goTo(e.newValue);
}
})
} }
update() { update() {

View File

@@ -27,13 +27,6 @@ defmodule ClaperWeb.EventLive.Presenter do
if connected?(socket) do if connected?(socket) do
Claper.Events.Event.subscribe(event.uuid) Claper.Events.Event.subscribe(event.uuid)
Claper.Presentations.subscribe(event.presentation_file.id) Claper.Presentations.subscribe(event.presentation_file.id)
Presence.track(
self(),
"event:#{event.uuid}",
socket.assigns.current_user.id,
%{}
)
end end
endpoint_config = Application.get_env(:claper, ClaperWeb.Endpoint)[:url] endpoint_config = Application.get_env(:claper, ClaperWeb.Endpoint)[:url]

View File

@@ -1,7 +1,7 @@
defmodule Claper.MixProject do defmodule Claper.MixProject do
use Mix.Project use Mix.Project
@version "2.3.0" @version "2.3.1"
def project do def project do
[ [