Improve export entry process

Add tooltip when entry is still too long to be sent directly
Minify when entry is too long for copy-and-past submission
Add name (and emoji) for the post title when sending directly
This commit is contained in:
Hans5958 2023-03-20 17:52:15 +07:00
parent 1c0b2754cb
commit ac55fb93e3
2 changed files with 36 additions and 11 deletions

View file

@ -8,6 +8,9 @@ window.prodDomain = prodDomain
const instanceId = "2022" const instanceId = "2022"
window.instanceId = instanceId window.instanceId = instanceId
const instanceSubreddit = "placeAtlas2"
window.instanceSubreddit = instanceSubreddit
const pageTitle = "The 2022 r/place Atlas" const pageTitle = "The 2022 r/place Atlas"
window.pageTitle = pageTitle window.pageTitle = pageTitle

View file

@ -31,6 +31,8 @@ const periodsAdd = document.getElementById('periodsAdd')
const exportButton = document.getElementById("exportButton") const exportButton = document.getElementById("exportButton")
const cancelButton = document.getElementById("cancelButton") const cancelButton = document.getElementById("cancelButton")
const exportDirectPostButton = document.getElementById("exportDirectPost")
let exportDirectPostTooltip = null
const exportModalElement = document.getElementById("exportModal") const exportModalElement = document.getElementById("exportModal")
const exportModal = new bootstrap.Modal(exportModalElement) const exportModal = new bootstrap.Modal(exportModalElement)
@ -306,18 +308,38 @@ function initDraw() {
function exportJson() { function exportJson() {
const exportObject = generateExportObject() const exportObject = generateExportObject()
let jsonString = JSON.stringify(exportObject, null, "\t") let prettyJsonString = JSON.stringify(exportObject, null, "\t")
jsonString = jsonString.split("\n") prettyJsonString = " " + prettyJsonString.split("\n").join("\n ")
jsonString = jsonString.join("\n ") exportArea.value = prettyJsonString
jsonString = " " + jsonString let directPostJsonString = prettyJsonString
exportArea.value = jsonString
let directPostUrl = "https://www.reddit.com/r/placeAtlas2/submit?selftext=true&title=New%20Submission&text=" + encodeURIComponent(exportArea.value) let directPostUrl = `https://www.reddit.com/r/${instanceSubreddit}/submit?selftext=true&title=`
if (jsonString.length > 7493) { if (exportObject.id === 0) directPostUrl += `✨%20${encodeURIComponent(exportObject.name)}&text=`
directPostUrl = "https://www.reddit.com/r/placeAtlas2/submit?selftext=true&title=New%20Submission&text=" + encodeURIComponent(" " + JSON.stringify(exportObject)) else directPostUrl += `✏%20${encodeURIComponent(exportObject.name)}&text=`
} directPostUrl += "&text="
document.getElementById("exportDirectPost").href = directPostUrl
if (entryId === 0) document.getElementById("redditFlair").textContent = "New Entry" if (directPostJsonString.length + directPostJsonString > 7579) {
directPostJsonString = encodeURIComponent(" " + JSON.stringify(exportObject))
}
if (exportArea.value > 40000) {
exportArea.value = " " + JSON.stringify(exportObject)
}
directPostUrl += directPostJsonString
if (directPostUrl.length > 7579) {
// exportDirectPostButton.classList.add("disabled")
// exportDirectPostButton.ariaDisabled = true
exportDirectPostButton.dataset.bsToggle = "tooltip"
exportDirectPostButton.dataset.bsTitle = "This may not work due to the length of the entry. If needed, please copy manually."
if (!exportDirectPostTooltip) exportDirectPostTooltip = new bootstrap.Tooltip(exportDirectPostButton)
} else {
// exportDirectPostButton.classList.remove("disabled")
// exportDirectPostButton.ariaDisabled = false
exportDirectPostButton.dataset.bsTitle = ""
}
exportDirectPostButton.href = directPostUrl
if (exportObject.id === 0) document.getElementById("redditFlair").textContent = "New Entry"
else document.getElementById("redditFlair").textContent = "Edit Entry" else document.getElementById("redditFlair").textContent = "Edit Entry"
exportModal.show() exportModal.show()