fix: redirect when slideshow visited improperly
This commit is contained in:
parent
5e574d588f
commit
1f5d39af59
|
@ -1,5 +1,6 @@
|
||||||
// import { Inter } from 'next/font/google';
|
// import { Inter } from 'next/font/google';
|
||||||
import PairedSuccessfullyOverlay from 'components/PairedSuccessfullyOverlay';
|
import PairedSuccessfullyOverlay from 'components/PairedSuccessfullyOverlay';
|
||||||
|
import { useRouter } from 'next/router';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { syncCollections } from 'services/collectionService';
|
import { syncCollections } from 'services/collectionService';
|
||||||
import { syncFiles } from 'services/fileService';
|
import { syncFiles } from 'services/fileService';
|
||||||
|
@ -16,28 +17,40 @@ export default function Slideshow() {
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
const init = async () => {
|
const init = async () => {
|
||||||
const collections = await syncCollections();
|
try {
|
||||||
|
const collections = await syncCollections();
|
||||||
|
|
||||||
// get requested collection id from localStorage
|
// get requested collection id from localStorage
|
||||||
const requestedCollectionID =
|
const requestedCollectionID =
|
||||||
window.localStorage.getItem('targetCollectionId');
|
window.localStorage.getItem('targetCollectionId');
|
||||||
|
|
||||||
const files = await syncFiles('normal', collections, () => {});
|
const files = await syncFiles('normal', collections, () => {});
|
||||||
|
|
||||||
if (requestedCollectionID) {
|
if (requestedCollectionID) {
|
||||||
const collectionFiles = files.filter(
|
const collectionFiles = files.filter(
|
||||||
(file) => file.collectionID === Number(requestedCollectionID)
|
(file) =>
|
||||||
);
|
file.collectionID === Number(requestedCollectionID)
|
||||||
|
);
|
||||||
|
|
||||||
setCollectionFiles(collectionFiles);
|
setCollectionFiles(collectionFiles);
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
router.push('/');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
init();
|
try {
|
||||||
|
init();
|
||||||
|
} catch (e) {
|
||||||
|
router.push('/');
|
||||||
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (collectionFiles.length < 1 || !currentFile) return;
|
||||||
// create interval to change slide
|
// create interval to change slide
|
||||||
const interval = setInterval(() => {
|
const interval = setInterval(() => {
|
||||||
// set the currentFile to the next file in the collection for the slideshow
|
// set the currentFile to the next file in the collection for the slideshow
|
||||||
|
@ -71,7 +84,6 @@ export default function Slideshow() {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (currentFile) {
|
if (currentFile) {
|
||||||
console.log(currentFile);
|
|
||||||
getRenderableFileURL();
|
getRenderableFileURL();
|
||||||
}
|
}
|
||||||
}, [currentFile]);
|
}, [currentFile]);
|
||||||
|
|
Loading…
Reference in a new issue