diff --git a/pages/resources.js b/pages/resources.js
index 1477ebe..f1f102e 100644
--- a/pages/resources.js
+++ b/pages/resources.js
@@ -1,34 +1,262 @@
-import Link from 'next/link';
-import React from 'react';
-import Footer from '@/components/footer';
-import Head from 'next/head';
+import React, { useState, useEffect } from "react";
+import Footer from "@/components/footer";
+import Head from "next/head";
+import Link from "next/link";
function ResourcesKnhts() {
- return (
- <>
-
- Resources
-
-
-
-
-
-
-
-
The Kenya National Health Terminology Service Resources
-
These are a list of resources. Click on each to download:
-
- Kenya National eHealth Policy 2016-2030
- Kenya Health Sector Strategic Plan 2018-23
- Digital Health Act 15 of 2023
- DRAFT KE-NHDD Governance Framework - Dec 5 2023
- DRAFT Kenya HIS Certification Framework - Draft 06FEB2017_KJO-edits_clean
-
-
-
-
- >
+ const [uploadedFiles, setUploadedFiles] = useState([]);
+ const [selectedFiles, setSelectedFiles] = useState([]);
+ const [uploadSuccess, setUploadSuccess] = useState(false);
+ const [uploadError, setUploadError] = useState(null);
+
+ useEffect(() => {
+ // Initialize IndexedDB database
+ const request = indexedDB.open("uploadedFilesDB", 1);
+
+ request.onerror = (event) => {
+ console.error("IndexedDB error:", event.target.error);
+ };
+
+ request.onupgradeneeded = (event) => {
+ const db = event.target.result;
+ const objectStore = db.createObjectStore("uploadedFiles", {
+ keyPath: "name",
+ });
+ objectStore.createIndex("name", "name", { unique: true });
+ };
+
+ request.onsuccess = (event) => {
+ const db = event.target.result;
+ const transaction = db.transaction("uploadedFiles", "readonly");
+ const objectStore = transaction.objectStore("uploadedFiles");
+ const getAllRequest = objectStore.getAll();
+
+ getAllRequest.onsuccess = (event) => {
+ setUploadedFiles(event.target.result);
+ };
+ };
+ }, []);
+
+ const handleFileSelect = (event) => {
+ const filesArray = Array.from(event.target.files);
+ setSelectedFiles([...selectedFiles, ...filesArray]);
+ };
+
+ const handleFileUpload = () => {
+ if (selectedFiles.length === 0) {
+ console.error("No files selected");
+ return;
+ }
+
+ const request = indexedDB.open("uploadedFilesDB", 1);
+
+ request.onerror = (event) => {
+ console.error("IndexedDB error:", event.target.error);
+ };
+
+ request.onsuccess = (event) => {
+ const db = event.target.result;
+ const transaction = db.transaction("uploadedFiles", "readwrite");
+ const objectStore = transaction.objectStore("uploadedFiles");
+
+ selectedFiles.forEach((file) => {
+ // Check if file with the same name already exists
+ const existingFile = uploadedFiles.find((f) => f.name === file.name);
+ if (existingFile) {
+ alert(
+ `File '${file.name}' already exists. Please choose a different name.`
+ );
+ } else {
+ objectStore.add(file);
+ }
+ });
+
+ transaction.oncomplete = () => {
+ setUploadedFiles([...uploadedFiles, ...selectedFiles]);
+ setSelectedFiles([]);
+ setUploadSuccess(true);
+
+ setTimeout(() => {
+ setUploadSuccess(false);
+ }, 3000); // Reset upload success message after 3 seconds
+ };
+ };
+ };
+
+ const handleDeleteFile = (fileName) => {
+ const confirmation = window.confirm(
+ "Confirm deletion of this file? You won't be able to undo this action."
);
+ if (confirmation) {
+ const request = indexedDB.open("uploadedFilesDB", 1);
+
+ request.onerror = (event) => {
+ console.error("IndexedDB error:", event.target.error);
+ };
+
+ request.onsuccess = (event) => {
+ const db = event.target.result;
+ const transaction = db.transaction("uploadedFiles", "readwrite");
+ const objectStore = transaction.objectStore("uploadedFiles");
+
+ objectStore.delete(fileName);
+
+ transaction.oncomplete = () => {
+ const updatedFiles = uploadedFiles.filter(
+ (file) => file.name !== fileName
+ );
+ setUploadedFiles(updatedFiles);
+ };
+ };
+ }
+ };
+
+ return (
+ <>
+
+ Resources
+
+
+
+
+
+
+
+
+ The Kenya National Health Terminology Service Resources
+
+
+ These are a list of resources. Click on each to download or upload a
+ new resource:
+
+
+
+
+ Kenya National eHealth Policy 2016-2030{" "}
+
+
+
+
+ Kenya Health Sector Strategic Plan 2018-23{" "}
+
+
+
+
+ Digital Health Act 15 of 2023{" "}
+
+
+
+
+ DRAFT KE-NHDD Governance Framework - Dec 5 2023{" "}
+
+
+
+
+ DRAFT Kenya HIS Certification Framework - Draft
+ 06FEB2017_KJO-edits_clean{" "}
+
+
+
+ {uploadError && (
+
+ {uploadError}
+
+ )}
+
+
+
+ Kenya National eHealth Policy 2016-2030{" "}
+
+
+
+
+ {uploadedFiles.map((file, index) => (
+
+
+ {file.name}
+
+ handleDeleteFile(file.name)}>
+ Delete
+
+
+ ))}
+
+ {uploadSuccess && (
+
+ Files uploaded successfully!
+
+ )}
+
+
+ You can also add resources by uploading files.
+
+
+
+
+ Upload
+
+
+
+
+ >
+ );
}
export default ResourcesKnhts;