Implemented arl login, settings loading and fixed toast display

This commit is contained in:
RemixDev
2021-05-06 08:56:03 +02:00
parent 9dbe0a5cb7
commit 0b1c5a8718
8 changed files with 4965 additions and 8899 deletions

View File

@@ -1,11 +1,11 @@
export function fetchData(key, data = {}) {
export function fetchData(key, data = {}, method = 'GET') {
const url = new URL(`${window.location.origin}/api/${key}`)
Object.keys(data).forEach(key => {
url.searchParams.append(key, data[key])
})
return fetch(url.href)
return fetch(url.href, {method})
.then(response => response.json())
.catch(() => {})
}

View File

@@ -22,23 +22,31 @@ export const toast = function(msg, icon = null, dismiss = true, id = null) {
const messages = toast.querySelectorAll('.toast-message')
messages.forEach(message => {
message.innerHTML = msg
message.innerText = msg
})
})
}
if (icon) {
let iconNode = document.createElement('span')
iconNode.classList.add('toast-icon')
if (icon == 'loading') {
icon = `<div class="circle-loader"></div>`
let loader = document.createElement('div')
loader.classList.add('circle-loader')
iconNode.appendChild(loader)
} else {
icon = `<i class="material-icons">${icon}</i>`
let materialIcon = document.createElement('i')
materialIcon.classList.add('material-icons')
materialIcon.appendChild(document.createTextNode(icon))
iconNode.appendChild(materialIcon)
}
toastElement.forEach(toast => {
const icons = toast.querySelectorAll('.toast-icon')
icons.forEach(toastIcon => {
toastIcon.innerHTML = icon
toastIcon.parentNode.replaceChild(iconNode, toastIcon)
})
})
}
@@ -54,17 +62,31 @@ export const toast = function(msg, icon = null, dismiss = true, id = null) {
}, 3000)
}
} else {
let iconNode = document.createElement('span')
iconNode.classList.add('toast-icon')
if (icon == null) {
icon = ''
iconNode.appendChild(document.createTextNode(''))
} else if (icon == 'loading') {
icon = `<div class="circle-loader"></div>`
let loader = document.createElement('div')
loader.classList.add('circle-loader')
iconNode.appendChild(loader)
} else {
icon = `<i class="material-icons">${icon}</i>`
let materialIcon = document.createElement('i')
materialIcon.classList.add('material-icons')
materialIcon.appendChild(document.createTextNode(icon))
iconNode.appendChild(materialIcon)
}
let messageNode = document.createElement('span')
messageNode.classList.add('toast-message')
messageNode.appendChild(document.createTextNode(msg))
let toastNode = document.createElement('toast')
toastNode.appendChild(iconNode)
toastNode.appendChild(messageNode)
let toastObj = Toastify({
...sharedOptions,
text: `<span class="toast-icon">${icon}</span><span class="toast-message">${msg}</toast>`,
node: toastNode,
duration: dismiss ? 3000 : 0,
className: dismiss ? 'dismissable' : '',
onClick: function() {