Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

feat: prerender next slide in bg

httpjamesm2466f9eeab0d
diff --git a/apps/cast/src/components/Theatre/PhotoAuditorium.tsx b/apps/cast/src/components/Theatre/PhotoAuditorium.tsx
index a67cdc8de7..f016c05d81 100644
--- a/apps/cast/src/components/Theatre/PhotoAuditorium.tsx
+++ b/apps/cast/src/components/Theatre/PhotoAuditorium.tsx
@@ -1,18 +1,44 @@
import { SlideshowContext } from 'pages/slideshow';
-import { useContext, useEffect } from 'react';
+import { useContext, useEffect, useState } from 'react';
-export default function PhotoAuditorium({ url }: { url: string }) {
+export default function PhotoAuditorium({
+ url,
+ nextSlideUrl,
+}: {
+ url: string;
+ nextSlideUrl: string;
+}) {
const { showNextSlide } = useContext(SlideshowContext);
+ const [showPreloadedNextSlide, setShowPreloadedNextSlide] = useState(false);
+ const [nextSlidePrerendered, setNextSlidePrerendered] = useState(false);
+
useEffect(() => {
- const timeout = setTimeout(() => {
- showNextSlide();
- }, 5000);
+ let timeout;
+ let prerenderTimeout;
+ if (nextSlidePrerendered) {
+ timeout = setTimeout(() => {
+ setShowPreloadedNextSlide(true);
+
+ if (showNextSlide) {
+ // wait 5s before showing next slide
+ prerenderTimeout = setTimeout(() => {
+ showNextSlide();
+ }, 5000);
+ }
+ }, 5000);
+ }
return () => {
- clearTimeout(timeout);
+ if (timeout) {
+ clearTimeout(timeout);
+
+ if (prerenderTimeout) {
+ clearTimeout(prerenderTimeout);
+ }
+ }
};
- }, [url]);
+ }, [nextSlidePrerendered, showNextSlide]);
return (
<div
@@ -40,6 +66,18 @@ export default function PhotoAuditorium({ url }: { url: string }) {
style={{
maxWidth: '100%',
maxHeight: '100%',
+ display: showPreloadedNextSlide ? 'none' : 'block',
+ }}
+ />
+ <img
+ src={nextSlideUrl}
+ style={{
+ maxWidth: '100%',
+ maxHeight: '100%',
+ display: showPreloadedNextSlide ? 'block' : 'none',
+ }}
+ onLoad={() => {
+ setNextSlidePrerendered(true);
}}
/>
</div>
diff --git a/apps/cast/src/components/Theatre/index.tsx b/apps/cast/src/components/Theatre/index.tsx
index 071ba46316..d2c8e6ab4d 100644
--- a/apps/cast/src/components/Theatre/index.tsx
+++ b/apps/cast/src/components/Theatre/index.tsx
@@ -1,20 +1,30 @@
import { FILE_TYPE } from 'constants/file';
import PhotoAuditorium from './PhotoAuditorium';
-import VideoAuditorium from './VideoAuditorium';
+// import VideoAuditorium from './VideoAuditorium';
-interface IProps {
+interface fileProp {
fileName: string;
fileURL: string;
type: FILE_TYPE;
}
+interface IProps {
+ file1: fileProp;
+ file2: fileProp;
+}
+
export default function Theatre(props: IProps) {
- switch (props.type) {
+ switch (props.file1.type && props.file2.type) {
case FILE_TYPE.IMAGE:
- return <PhotoAuditorium url={props.fileURL} />;
- case FILE_TYPE.VIDEO:
return (
- <VideoAuditorium name={props.fileName} url={props.fileURL} />
+ <PhotoAuditorium
+ url={props.file1.fileURL}
+ nextSlideUrl={props.file2.fileURL}
+ />
);
+ // case FILE_TYPE.VIDEO:
+ // return (
+ // <VideoAuditorium name={props.fileName} url={props.fileURL} />
+ // );
}
}
diff --git a/apps/cast/src/pages/slideshow.tsx b/apps/cast/src/pages/slideshow.tsx
index 32fca67355..a7f32e8172 100644
--- a/apps/cast/src/pages/slideshow.tsx
+++ b/apps/cast/src/pages/slideshow.tsx
@@ -18,6 +18,7 @@ export default function Slideshow() {
const [currentFile, setCurrentFile] = useState<EnteFile | undefined>(
undefined
);
+ const [nextFile, setNextFile] = useState<EnteFile | undefined>(undefined);
const [loading, setLoading] = useState(true);
@@ -90,10 +91,13 @@ export default function Slideshow() {
);
const nextIndex = (currentIndex + 1) % collectionFiles.length;
+ const nextNextIndex = (nextIndex + 1) % collectionFiles.length;
const nextFile = collectionFiles[nextIndex];
+ const nextNextFile = collectionFiles[nextNextIndex];
setCurrentFile(nextFile);
+ setNextFile(nextNextFile);
};
const [renderableFileURL, setRenderableFileURL] = useState<string>('');
@@ -135,9 +139,16 @@ export default function Slideshow() {
<>
<SlideshowContext.Provider value={{ showNextSlide }}>
<Theatre
- fileURL={renderableFileURL}
- type={currentFile?.metadata.fileType}
- fileName={currentFile?.metadata.title}
+ file1={{
+ fileName: currentFile?.metadata.title,
+ fileURL: renderableFileURL,
+ type: currentFile?.metadata.fileType,
+ }}
+ file2={{
+ fileName: nextFile?.metadata.title,
+ fileURL: renderableFileURL,
+ type: nextFile?.metadata.fileType,
+ }}
/>
</SlideshowContext.Provider>
{loading && <PairedSuccessfullyOverlay />}