Header,Footer und dashboard bekommen Daten von IndexedDB statt von Window Objekt

This commit is contained in:
ISA
2024-10-31 14:01:09 +01:00
parent 2fd61c7f7c
commit f2143daa51
5 changed files with 90 additions and 137 deletions

View File

@@ -1,14 +1,7 @@
"use client"; // Wichtig, um sicherzustellen, dass der Code nur auf dem Client ausgeführt wird
"use client"; // app/Footer.jsx
import React, { useEffect, useState, useRef } from "react";
import { Icon } from "@iconify/react";
// indexDB-Funktionen nur im Browser importieren
let storePDF, getPDF;
if (typeof window !== "undefined") {
const indexedDBModule = require("../utils/indexedDB");
storePDF = indexedDBModule.storePDF;
getPDF = indexedDBModule.getPDF;
}
import { storePDF, getPDF } from "../utils/indexedDB"; // Korrekte Importe für die PDF-Funktionen
function Footer() {
const [pdfName, setPdfName] = useState("");
@@ -35,38 +28,36 @@ function Footer() {
];
useEffect(() => {
if (typeof window !== "undefined" && getPDF && storePDF) {
async function loadAndStorePDFs() {
try {
for (const fileName of pdfFiles) {
const storedPdf = await getPDF(fileName);
if (!storedPdf) {
const response = await fetch(`/doku/${fileName}`);
const pdfBlob = await response.blob();
await storePDF(fileName, pdfBlob);
console.log(`${fileName} in IndexedDB gespeichert.`);
}
async function loadAndStorePDFs() {
try {
for (const fileName of pdfFiles) {
const storedPdf = await getPDF(fileName);
if (!storedPdf) {
const response = await fetch(`/doku/${fileName}`);
const pdfBlob = await response.blob();
await storePDF(fileName, pdfBlob);
console.log(`${fileName} in IndexedDB gespeichert.`);
}
} catch (error) {
console.error("Fehler beim Laden oder Speichern der PDFs:", error);
}
} catch (error) {
console.error("Fehler beim Laden oder Speichern der PDFs:", error);
}
}
if (typeof window !== "undefined") {
loadAndStorePDFs();
}
}, [getPDF, storePDF]);
}, []);
const loadPDF = async (fileName) => {
if (typeof window !== "undefined" && getPDF) {
const storedPdf = await getPDF(fileName);
if (storedPdf) {
const pdfUrl = URL.createObjectURL(storedPdf);
window.open(pdfUrl, "_blank"); // Öffnet die PDF in einem neuen Tab
setPdfName(fileName);
setShowSlider(false);
} else {
console.error("PDF nicht in IndexedDB gefunden");
}
const storedPdf = await getPDF(fileName);
if (storedPdf) {
const pdfUrl = URL.createObjectURL(storedPdf);
window.open(pdfUrl, "_blank"); // Öffnet die PDF in einem neuen Tab
setPdfName(fileName);
setShowSlider(false);
} else {
console.error("PDF nicht in IndexedDB gefunden");
}
};