refactor: 🎨 Formatting, remove global.content

This commit is contained in:
ThatOneCalculator 2022-03-19 11:19:53 -07:00
parent 8f8b234b1f
commit 3e135919f4
1 changed files with 13 additions and 17 deletions

View File

@ -4,9 +4,9 @@ import Scrollbar from "smooth-scrollbar"
import config from "../config.json"
const apiUrl = config.api_url
const jsConfetti = new JSConfetti()
let rawContent = ""
global.rawContent = ""
const jsConfetti = new JSConfetti()
const lineNumbers = <HTMLElement>document.querySelector(".line-numbers")
const wrapper = <HTMLPreElement>document.querySelector(".wrapper")
@ -58,9 +58,9 @@ async function postPaste(content: string, callback: Function) {
callback(data || { data: { message: "An unkown error occured!" } })
})
.catch((error) => {
.catch(() => {
callback({
data: { message: "API error occurred.. please try again." },
data: { message: "An API error occurred, please try again." },
})
})
}
@ -81,9 +81,9 @@ async function getPaste(id: string, callback: Function) {
}
callback(data || { data: { message: "An unkown error occured!" } })
})
.catch((error) => {
.catch(() => {
callback({
data: { message: "API error occurred.. please try again." },
data: { message: "An API error occurred, please try again." },
})
})
}
@ -98,10 +98,9 @@ function newPaste() {
disable(copyButton)
editor.value = ""
global.rawContent = ""
rawContent = ""
wrapper.classList.add("text-area-proper")
show(editor)
hide(codeViewPre)
hide(viewCounterLabel)
@ -124,10 +123,7 @@ function addMessage(message: string) {
function viewPaste(content: string, views: string) {
lineNumbers.innerHTML = ""
for (let i = 1; i <= content.split("\n").length; i++) {
lineNumbers.innerHTML =
lineNumbers.innerHTML +
`${i}
<br>`
lineNumbers.innerHTML = lineNumbers.innerHTML + `${i}<br>`
}
codeView.innerHTML = hljs.highlightAuto(content).value
@ -161,8 +157,8 @@ async function savePaste() {
} else {
window.history.pushState(null, "", `/~/${res["data"]["id"]}`)
global.rawContent = res["data"]["content"]
viewPaste(global.rawContent, "0")
rawContent = res["data"]["content"]
viewPaste(rawContent, "0")
const rand = Math.floor(Math.random() * 40)
@ -227,7 +223,7 @@ copyButton.addEventListener("click", function () {
window.history.pushState(null, "", "/")
newPaste()
global.rawContent = content
rawContent = content
editor.value = content
})
@ -249,8 +245,8 @@ async function handlePopstate() {
window.history.pushState(null, "", `/`)
newPaste()
} else {
global.rawContent = res["data"]["content"]
viewPaste(global.rawContent, res["data"]["views"].toString())
rawContent = res["data"]["content"]
viewPaste(rawContent, res["data"]["views"].toString())
}
})
}