aboutsummaryrefslogtreecommitdiff
path: root/src/main/assets
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2023-06-07 21:10:07 +0300
committerGravatar Vitaly Takmazov2023-06-07 21:10:07 +0300
commite83558253ef0945bdd3a71e5aa24d73361eee0e2 (patch)
treeb7f21f0f579f656aa43eb375f1be630b69c3bcc8 /src/main/assets
parent34534f222d1c2397f464521a6fa02ebea869edc6 (diff)
scripts: cleanup linter warnings about incorrect Promise usage
Diffstat (limited to 'src/main/assets')
-rw-r--r--src/main/assets/scripts.js111
1 files changed, 49 insertions, 62 deletions
diff --git a/src/main/assets/scripts.js b/src/main/assets/scripts.js
index dfd12494..4cb06966 100644
--- a/src/main/assets/scripts.js
+++ b/src/main/assets/scripts.js
@@ -314,17 +314,14 @@ function showCommentForm(mid, rid) {
body: formData,
credentials: 'omit'
}).then(handleErrors)
- .then(response => {
- if (response.ok) {
- response.json().then(result => {
- if (result.newMessage) {
- window.location.hash = `#${result.newMessage.rid}`
- } else {
- alert(result.text)
- }
- window.location.reload()
- })
+ .then(response => response.json())
+ .then(result => {
+ if (result.newMessage) {
+ window.location.hash = `#${result.newMessage.rid}`
+ } else {
+ alert(result.text)
}
+ window.location.reload()
}).catch(error => {
alert(error.message)
})
@@ -509,13 +506,11 @@ function getTags() {
credentials: 'omit'
})
.then(handleErrors)
- .then(response => {
- return response.json()
- })
+ .then(response => response.json())
.then(json => {
let tags = json.map(t => t.tag)
let input = document.getElementById('tags_input')
- })
+ }).catch(console.error)
return false
}
@@ -546,31 +541,32 @@ const registerServiceWorker = () => {
const publicKey = 'BPU0LniKKR0QiaUvILPd9AystmSOU8rWDZobxKm7IJN5HYxOSQdktRdc74TZvyRS9_kyUz7LDN6gUAmAVOmObAU'
navigator.serviceWorker.register('/sw.js', { scope: '/' })
navigator.serviceWorker.ready.then(reg => {
- reg.pushManager.subscribe({
+ return reg.pushManager.subscribe({
userVisibleOnly: true,
applicationServerKey: publicKey
- }).then(
- sub => {
- const body = [
- {
- type: 'web',
- token: JSON.stringify(sub)
- }
- ]
- fetch('/api/notifications?hash=' + document.getElementById('body').getAttribute('data-hash'), {
- method: 'PUT',
- headers: {
- 'Content-Type': 'application/json'
- },
- credentials: 'same-origin',
- body: JSON.stringify(body)
- }).then(response => {
- console.log(response.status)
- })
+ })
+ }).then(
+ sub => {
+ return [
+ {
+ type: 'web',
+ token: JSON.stringify(sub)
+ }
+ ]
+ },
+ err => console.error(err)
+ ).then(body => {
+ return fetch('/api/notifications?hash=' + document.getElementById('body').getAttribute('data-hash'), {
+ method: 'PUT',
+ headers: {
+ 'Content-Type': 'application/json'
},
- err => console.error(err)
- )
- })
+ credentials: 'same-origin',
+ body: JSON.stringify(body)
+ })
+ }).then(response => {
+ console.log(response.status)
+ }).catch(console.error)
}
function notificationsCheckPermissions(button) {
@@ -672,17 +668,12 @@ ready(() => {
body: formData,
credentials: 'omit'
}).then(handleErrors)
- .then(response => {
- if (response.ok) {
- response.json().then(result => {
- if (result.newMessage) {
- window.location.href = new URL(`/m/${result.newMessage.mid}`, window.location.href).href
- } else {
- alert(result.text)
- }
- })
+ .then(response => response.json())
+ .then(result => {
+ if (result.newMessage) {
+ window.location.href = new URL(`/m/${result.newMessage.mid}`, window.location.href).href
} else {
- alert('Something went wrong :(')
+ alert(result.text)
}
}).catch(error => {
alert(error.message)
@@ -698,19 +689,15 @@ ready(() => {
body: formData,
credentials: 'omit'
}).then(handleErrors)
- .then(response => {
- if (response.ok) {
- response.json().then(result => {
- if (result.to) {
- window.location.href = new URL('/pm/sent', window.location.href).href
- } else {
- alert('Something went wrong :(')
- }
- })
+ .then(response => response.json())
+ .then(result => {
+ if (result.to) {
+ window.location.href = new URL('/pm/sent', window.location.href).href
} else {
alert('Something went wrong :(')
}
- }).catch(error => {
+ })
+ .catch(error => {
alert(error.message)
})
e.preventDefault()
@@ -726,13 +713,13 @@ ready(() => {
})
})
Array.from(document.querySelectorAll('.a-vip')).forEach(function(e) {
- e.addEventListener('click', function(e) {
- toggleWL(
- e.target,
- e.target.closest('[data-name]').getAttribute('data-name'))
- e.preventDefault()
- })
+ e.addEventListener('click', function(e) {
+ toggleWL(
+ e.target,
+ e.target.closest('[data-name]').getAttribute('data-name'))
+ e.preventDefault()
})
+ })
Array.from(document.querySelectorAll('.ir a[data-fname], .msg-media a[data-fname]')).forEach(function(el) {
el.addEventListener('click', function(e) {
let fname = /** @type {HTMLElement} */ (e.target).closest('[data-fname]').getAttribute('data-fname')