// IndexedDB setup let db; const DB_NAME = 'IconStackDB'; const STORE_NAME = 'savedIcons'; const DB_VERSION = 1; // Toast management let currentToast = null; // Initialize IndexedDB function initDB() { return new Promise((resolve, reject) => { const request = indexedDB.open(DB_NAME, DB_VERSION); request.onerror = () => reject(request.error); request.onsuccess = () => { db = request.result; resolve(db); }; request.onupgradeneeded = (event) => { const db = event.target.result; if (!db.objectStoreNames.contains(STORE_NAME)) { const store = db.createObjectStore(STORE_NAME, { keyPath: 'id', autoIncrement: true }); store.createIndex('name', 'name', { unique: true }); store.createIndex('createdAt', 'createdAt', { unique: false }); } }; }); } // Function to retrieve all saved icons async function getAllSavedIcons() { const transaction = db.transaction([STORE_NAME], 'readonly'); const store = transaction.objectStore(STORE_NAME); const request = store.getAll(); return new Promise((resolve, reject) => { request.onsuccess = () => resolve(request.result); request.onerror = () => reject(request.error); }); } // Function to show toast notifications function showToast(message, type = 'primary') { if (currentToast) { currentToast.hide(); } // Check if toast container exists, create if not let toastContainer = document.querySelector('.toast-container'); if (!toastContainer) { toastContainer = document.createElement('div'); toastContainer.className = 'toast-container position-fixed top-0 end-0 p-3'; document.body.appendChild(toastContainer); } // Create toast element const toastId = 'toast-' + Date.now(); const toast = document.createElement('div'); toast.className = `toast hide align-items-center border-0 py-2 px-3 bg-${type} text-white`; toast.id = toastId; toast.setAttribute('role', 'alert'); toast.setAttribute('aria-live', 'assertive'); toast.setAttribute('aria-atomic', 'true'); toast.style.setProperty('--bs-toast-max-width', 'auto'); toast.innerHTML = `
Create and save some icons using the Stack Generator to see them here.