Added checks for poll upon duplicate publish, allowing a new poll to be published if the new publish doesn't contain one.
This commit is contained in:
parent
7afa06623f
commit
07f4fa3e6e
@ -814,7 +814,6 @@ const loadCardIntoForm = async (cardData) => {
|
|||||||
|
|
||||||
// Main function to publish a new Minter Card -----------------------------------------------
|
// Main function to publish a new Minter Card -----------------------------------------------
|
||||||
const publishCard = async (cardIdentifierPrefix) => {
|
const publishCard = async (cardIdentifierPrefix) => {
|
||||||
|
|
||||||
const minterGroupData = await fetchMinterGroupMembers()
|
const minterGroupData = await fetchMinterGroupMembers()
|
||||||
const minterGroupAddresses = minterGroupData.map(m => m.member)
|
const minterGroupAddresses = minterGroupData.map(m => m.member)
|
||||||
const userAddress = userState.accountAddress
|
const userAddress = userState.accountAddress
|
||||||
@ -823,6 +822,7 @@ const publishCard = async (cardIdentifierPrefix) => {
|
|||||||
alert("You are already a Minter and cannot publish a new card!")
|
alert("You are already a Minter and cannot publish a new card!")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const header = document.getElementById("card-header").value.trim()
|
const header = document.getElementById("card-header").value.trim()
|
||||||
const content = document.getElementById("card-content").value.trim()
|
const content = document.getElementById("card-content").value.trim()
|
||||||
const links = Array.from(document.querySelectorAll(".card-link"))
|
const links = Array.from(document.querySelectorAll(".card-link"))
|
||||||
@ -834,8 +834,27 @@ const publishCard = async (cardIdentifierPrefix) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const cardIdentifier = isExistingCard ? existingCardIdentifier : `${cardIdentifierPrefix}-${await uid()}`
|
if (isExistingCard) {
|
||||||
const pollName = `${cardIdentifier}-poll`
|
if (!existingCardData || Object.keys(existingCardData).length === 0) {
|
||||||
|
const fetched = await fetchExistingCard(cardIdentifierPrefix)
|
||||||
|
if (fetched) {
|
||||||
|
existingCardData = fetched
|
||||||
|
} else {
|
||||||
|
console.warn("fetchExistingCard returned null. Possibly no existing card found.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const cardIdentifier = isExistingCard && existingCardIdentifier
|
||||||
|
? existingCardIdentifier
|
||||||
|
: `${cardIdentifierPrefix}-${await uid()}`
|
||||||
|
|
||||||
|
let existingPollName
|
||||||
|
if (existingCardData && existingCardData.poll) {
|
||||||
|
existingPollName = existingCardData.poll
|
||||||
|
}
|
||||||
|
|
||||||
|
const pollName = existingPollName || `${cardIdentifier}-poll`
|
||||||
const pollDescription = `Mintership Board Poll for ${userState.accountName}`
|
const pollDescription = `Mintership Board Poll for ${userState.accountName}`
|
||||||
|
|
||||||
const cardData = {
|
const cardData = {
|
||||||
@ -845,16 +864,16 @@ const publishCard = async (cardIdentifierPrefix) => {
|
|||||||
creator: userState.accountName,
|
creator: userState.accountName,
|
||||||
creatorAddress: userState.accountAddress,
|
creatorAddress: userState.accountAddress,
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
poll: pollName,
|
poll: pollName // either the existing poll or a new one
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let base64CardData = await objectToBase64(cardData)
|
let base64CardData = await objectToBase64(cardData)
|
||||||
if (!base64CardData) {
|
if (!base64CardData) {
|
||||||
console.log(`initial base64 object creation with objectToBase64 failed, using btoa...`)
|
console.log(`initial base64 object creation with objectToBase64 failed, using btoa...`)
|
||||||
base64CardData = btoa(JSON.stringify(cardData))
|
base64CardData = btoa(JSON.stringify(cardData))
|
||||||
}
|
}
|
||||||
|
|
||||||
await qortalRequest({
|
await qortalRequest({
|
||||||
action: "PUBLISH_QDN_RESOURCE",
|
action: "PUBLISH_QDN_RESOURCE",
|
||||||
name: userState.accountName,
|
name: userState.accountName,
|
||||||
@ -863,7 +882,7 @@ const publishCard = async (cardIdentifierPrefix) => {
|
|||||||
data64: base64CardData,
|
data64: base64CardData,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!isExistingCard){
|
if (!isExistingCard || !existingPollName) {
|
||||||
await qortalRequest({
|
await qortalRequest({
|
||||||
action: "CREATE_POLL",
|
action: "CREATE_POLL",
|
||||||
pollName,
|
pollName,
|
||||||
@ -871,26 +890,33 @@ const publishCard = async (cardIdentifierPrefix) => {
|
|||||||
pollOptions: ['Yes, No'],
|
pollOptions: ['Yes, No'],
|
||||||
pollOwnerAddress: userState.accountAddress,
|
pollOwnerAddress: userState.accountAddress,
|
||||||
})
|
})
|
||||||
alert("Card and poll published successfully!")
|
if (!isExistingCard) {
|
||||||
|
alert("Card and poll published successfully!")
|
||||||
|
} else {
|
||||||
|
alert("Existing card updated, and new poll created (since existing poll was missing)!")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
alert("Card updated successfully! (No poll updates possible)")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isExistingCard){
|
if (isExistingCard) {
|
||||||
alert("Card Updated Successfully! (No poll updates possible)")
|
|
||||||
isExistingCard = false
|
isExistingCard = false
|
||||||
|
existingCardData = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById("publish-card-form").reset()
|
document.getElementById("publish-card-form").reset()
|
||||||
document.getElementById("publish-card-view").style.display = "none"
|
document.getElementById("publish-card-view").style.display = "none"
|
||||||
document.getElementById("cards-container").style.display = "flex"
|
document.getElementById("cards-container").style.display = "flex"
|
||||||
|
|
||||||
await loadCards(minterCardIdentifierPrefix)
|
await loadCards(minterCardIdentifierPrefix)
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
||||||
console.error("Error publishing card or poll:", error)
|
console.error("Error publishing card or poll:", error)
|
||||||
alert("Failed to publish card and poll.")
|
alert("Failed to publish card and poll.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let globalVoterMap = new Map()
|
let globalVoterMap = new Map()
|
||||||
|
|
||||||
const processPollData= async (pollData, minterGroupMembers, minterAdmins, creator, cardIdentifier) => {
|
const processPollData= async (pollData, minterGroupMembers, minterAdmins, creator, cardIdentifier) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user