// // NOTE - Change isTestMode to false prior to actual release ---- !important - You may also change identifier if you want to not show older cards. const testMode = true; const cardIdentifierPrefix = "testMB-board-card"; let isExistingCard = false; let existingCardData = {}; let existingCardIdentifier = {}; const loadMinterBoardPage = async () => { // Clear existing content on the page const bodyChildren = document.body.children; for (let i = bodyChildren.length - 1; i >= 0; i--) { const child = bodyChildren[i]; if (!child.classList.contains("menu")) { child.remove(); } } // Add the "Minter Board" content const mainContent = document.createElement("div"); mainContent.innerHTML = `
The Minter Board is a place to publish information about yourself in order to obtain support from existing Minters and Minter Admins on the Qortal network. You may publish a header, content, and links to other QDN-published content in order to support you in your mission. Minter Admins and Existing Minters will then support you (or not) by way of a vote on your card. Card details you publish, along with existing poll results, and comments from others, will be displayed here. Good Luck on your Qortal journey to becoming a minter!
Refreshing cards...
"; await loadCards(); }); document.getElementById("cancel-publish-button").addEventListener("click", async () => { const cardsContainer = document.getElementById("cards-container"); cardsContainer.style.display = "flex"; // Restore visibility const publishCardView = document.getElementById("publish-card-view"); publishCardView.style.display = "none"; // Hide the publish form }); document.getElementById("add-link-button").addEventListener("click", async () => { const linksContainer = document.getElementById("links-container"); const newLinkInput = document.createElement("input"); newLinkInput.type = "text"; newLinkInput.className = "card-link"; newLinkInput.placeholder = "Enter QDN link"; linksContainer.appendChild(newLinkInput); }); document.getElementById("publish-card-form").addEventListener("submit", async (event) => { event.preventDefault(); await publishCard(); }); await loadCards(); } //Main function to load the Minter Cards ---------------------------------------- const loadCards = async () => { const cardsContainer = document.getElementById("cards-container"); cardsContainer.innerHTML = "Loading cards...
"; try { const response = await qortalRequest({ action: "SEARCH_QDN_RESOURCES", service: "BLOG_POST", query: cardIdentifierPrefix, mode: "ALL" }); if (!response || !Array.isArray(response) || response.length === 0) { cardsContainer.innerHTML = "No cards found.
"; return; } // Validate cards and filter const validatedCards = await Promise.all( response.map(async card => { const isValid = await validateCardStructure(card); return isValid ? card : null; }) ); const validCards = validatedCards.filter(card => card !== null); if (validCards.length === 0) { cardsContainer.innerHTML = "No valid cards found.
"; return; } // Sort cards by timestamp descending (newest first) validCards.sort((a, b) => { const timestampA = a.updated || a.created || 0; const timestampB = b.updated || b.created || 0; return timestampB - timestampA; }); // Display skeleton cards immediately cardsContainer.innerHTML = ""; validCards.forEach(card => { const skeletonHTML = createSkeletonCardHTML(card.identifier); cardsContainer.insertAdjacentHTML("beforeend", skeletonHTML); }); // Fetch and update each card validCards.forEach(async card => { try { const cardDataResponse = await qortalRequest({ action: "FETCH_QDN_RESOURCE", name: card.name, service: "BLOG_POST", identifier: card.identifier, }); if (!cardDataResponse) { console.warn(`Skipping invalid card: ${JSON.stringify(card)}`); removeSkeleton(card.identifier); return; } // Skip cards without polls if (!cardDataResponse.poll) { console.warn(`Skipping card with no poll: ${card.identifier}`); removeSkeleton(card.identifier); return; } // Fetch poll results const pollResults = await fetchPollResults(cardDataResponse.poll); // Generate final card HTML const finalCardHTML = await createCardHTML(cardDataResponse, pollResults, card.identifier); replaceSkeleton(card.identifier, finalCardHTML); } catch (error) { console.error(`Error processing card ${card.identifier}:`, error); removeSkeleton(card.identifier); // Silently remove skeleton on error } }); } catch (error) { console.error("Error loading cards:", error); cardsContainer.innerHTML = "Failed to load cards.
"; } }; const removeSkeleton = (cardIdentifier) => { const skeletonCard = document.getElementById(`skeleton-${cardIdentifier}`); if (skeletonCard) { skeletonCard.remove(); // Remove the skeleton silently } }; const replaceSkeleton = (cardIdentifier, htmlContent) => { const skeletonCard = document.getElementById(`skeleton-${cardIdentifier}`); if (skeletonCard) { skeletonCard.outerHTML = htmlContent; } }; // Function to create a skeleton card const createSkeletonCardHTML = (cardIdentifier) => { return `${header}
Published by: ${creator} on ${formattedDate}
${commentDataResponse.creator}:
${commentDataResponse.content}
${timestamp}