diff --git a/src/components/read-mode-flow.jsx b/src/components/read-mode-flow.jsx index 054c077..32c7155 100644 --- a/src/components/read-mode-flow.jsx +++ b/src/components/read-mode-flow.jsx @@ -17,23 +17,21 @@ export default function ReadModeFlow({ cookiePermission, savedPageIndex, setSave updateBrowserTabText(pefObject.metaData.title) useEffect(() => { - // Check if the scroll action has not been performed yet - if (!hasScrolled) { - if (savedPageIndex) { - const pageId = `page-${savedPageIndex}`; - const element = document.getElementById(pageId); - - if (element) { - // Scroll the element into view smoothly and set focus on it - element.scrollIntoView({ behavior: 'smooth' }); - element.focus(); - // Mark the scroll action as performed - setHasScrolled(true); - } else { - console.error(`Error: Unable to find the specified element with id ${pageId}.`); - } + if (savedPageIndex === null && startPageIndex !== undefined) { + setSavedPageIndex(startPageIndex); + } + }, [savedPageIndex, startPageIndex]); + + useEffect(() => { + if (!hasScrolled && savedPageIndex !== null) { + const pageId = `page-${savedPageIndex}`; + const element = document.getElementById(pageId); + if (element) { + element.scrollIntoView({ behavior: 'smooth' }); + element.focus(); + setHasScrolled(true); } else { - console.error('Error: There is no saved page index or cookie.'); + console.error(`Error: Unable to find the specified element with id ${pageId}.`); } } }, [savedPageIndex, hasScrolled]); @@ -190,9 +188,6 @@ export default function ReadModeFlow({ cookiePermission, savedPageIndex, setSave startPageIndex = firstPageIndex maxPageIndex = pageIndex - 1 - // Set the first page as the current page if there's no saved page index - if (savedPageIndex === null) setSavedPageIndex(firstPageIndex); - return pagesFromPefObject }; diff --git a/src/components/upload-file.jsx b/src/components/upload-file.jsx index b43ab29..3d669ff 100644 --- a/src/components/upload-file.jsx +++ b/src/components/upload-file.jsx @@ -30,6 +30,10 @@ export default function UploadFile({ setSavedPageIndex, setReadmode, pefObject, }, []); function handleAddFile(acceptedFiles) { + + {/* for debug */} + // console.log("acceptedFiles:", acceptedFiles) + if (acceptedFiles) { if (checkIfPefFileType(acceptedFiles[0].type)) { setFileName(acceptedFiles[0].name); @@ -106,7 +110,7 @@ export default function UploadFile({ setSavedPageIndex, setReadmode, pefObject, ) : ( <> - {fileName !== 'ingen fil vald' ? ( + {(fileName !== 'ingen fil vald' && fileName !== 'filen kunde inte laddas upp.') ? ( diff --git a/src/pages/instruction.jsx b/src/pages/instruction.jsx index 47a2836..4b357ad 100644 --- a/src/pages/instruction.jsx +++ b/src/pages/instruction.jsx @@ -22,7 +22,7 @@ export default function InstructionPage({ cookiePermission, setCookiePermission

2. Välj läsläge:

Du kan välja mellan två läslägen:

@@ -49,11 +49,10 @@ export default function InstructionPage({ cookiePermission, setCookiePermission

@@ -68,9 +67,9 @@ export default function InstructionPage({ cookiePermission, setCookiePermission

- Vid anmärkningar om sidans tillgänglighet, gå till sidfoten och klicka på "Kakor och Tillgänglighet" för att komma till en sida där du kan lämna feedback och få kontaktuppgifter. + Vid anmärkningar om sidans tillgänglighet, gå till sidfoten och klicka på "Kakor och Tillgänglighet" för att komma till en sida där du kan lämna feedback och få kontaktuppgifter. -

+

diff --git a/src/pages/main.jsx b/src/pages/main.jsx index 760446a..1b477e8 100644 --- a/src/pages/main.jsx +++ b/src/pages/main.jsx @@ -29,7 +29,7 @@ export default function MainPage({ cookiePermission }) { } // If the user has allowed cookies, savedPageIndex isn't null, and a pef file is uploaded, // save the current position to the cookie when state changes - else if (cookiePermission === CookieEnum.ALLOWED && savedPageIndex && pefObject) { + else if (cookiePermission === CookieEnum.ALLOWED && savedPageIndex !== null && pefObject) { setLatestPageIndexToCookie(pefObject.metaData.identifier, savedPageIndex); } // IMPORTANT: Otherwise, set the savedPageIndex to the index of the first page in the read-mode components diff --git a/src/services/cookieManager.js b/src/services/cookieManager.js index 081c8b7..e826bd2 100644 --- a/src/services/cookieManager.js +++ b/src/services/cookieManager.js @@ -3,9 +3,9 @@ import { CookieEnum } from '../data/enums'; export function setLatestPageIndexToCookie(bookId, pageIndex) { try { - const pageId = `page-${pageIndex}` + const pageId = `page-${pageIndex}`; const cookieJson = JSON.stringify(pageId); - Cookies.set(`${bookId}-latest-position`, cookieJson, { expires: 365 }); + Cookies.set(`${bookId}-latest-position`, cookieJson, { expires: 365, sameSite: 'None', secure: true }); } catch (error) { console.error('Error setting cookie:', error); } @@ -15,9 +15,9 @@ export function getLatestPageIndexFromCookieInt(bookId) { try { const cookieJson = Cookies.get(`${bookId}-latest-position`); if (cookieJson) { - const cookieJsonToStr = JSON.parse(cookieJson) - const pageIndexStr = cookieJsonToStr.replace("page-", "") - return parseInt(pageIndexStr) + const cookieJsonToStr = JSON.parse(cookieJson); + const pageIndexStr = cookieJsonToStr.replace("page-", ""); + return parseInt(pageIndexStr); } else { return null; } @@ -29,10 +29,10 @@ export function getLatestPageIndexFromCookieInt(bookId) { export function setAllowCookie(boolean) { try { - if(boolean) { - Cookies.set("allowCookie", CookieEnum.ALLOWED, { expires: 365 }); + if (boolean) { + Cookies.set("allowCookie", CookieEnum.ALLOWED, { expires: 365, sameSite: 'None', secure: true }); } else { - Cookies.set("allowCookie", CookieEnum.DENIED, { expires: 1 }); + Cookies.set("allowCookie", CookieEnum.DENIED, { expires: 1, sameSite: 'None', secure: true }); } } catch (error) { console.error('Error setting cookie:', error); @@ -41,10 +41,10 @@ export function setAllowCookie(boolean) { export function getAllowCookie() { try { - const cookiePermission = Cookies.get("allowCookie") - return cookiePermission + const cookiePermission = Cookies.get("allowCookie"); + return cookiePermission; } catch (error) { console.error('Error getting cookie:', error); return null; } -} \ No newline at end of file +}