catchEmit
This commit is contained in:
parent
e95b8a606d
commit
edc9a87db8
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -17,6 +17,12 @@ export default {
|
|||
},
|
||||
saveOptionCouple(couple) {
|
||||
this.emit('save', couple)
|
||||
},
|
||||
catchEmit(req) {
|
||||
return req.catch(err => {
|
||||
this.emitError(err)
|
||||
throw err
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,14 +60,13 @@ export default {
|
|||
onScroll(event) {
|
||||
if(!this.loadingOlder && event.target.scrollHeight - event.target.clientHeight - event.target.scrollTop - 100 < 0) {
|
||||
this.loadingOlder = true
|
||||
this.rest
|
||||
this.catchEmit(this.rest
|
||||
.get("/timelines/home", { params: { limit: this.buffer,
|
||||
max_id: this.statues[this.statues.length - 1].id } })
|
||||
max_id: this.statues[this.statues.length - 1].id } }))
|
||||
.then(res => {
|
||||
this.statues.push.apply(this.statues, res.data)
|
||||
this.loadingOlder = false
|
||||
})
|
||||
.catch(this.emitError)
|
||||
} else if(event.target.scrollTop < 20) {
|
||||
this.statues.splice(this.buffer)
|
||||
}
|
||||
|
@ -92,19 +91,16 @@ export default {
|
|||
return (!status.in_reply_to_id || this.reply) && (!status.reblog || this.reblog)
|
||||
},
|
||||
onStatusMark(action) {
|
||||
this.rest.post(`/statuses/${action.id}/${action.type}`)
|
||||
this.catchEmit(this.rest.post(`/statuses/${action.id}/${action.type}`))
|
||||
.then(action.callback)
|
||||
.catch(this.emitError)
|
||||
},
|
||||
onNotificationDismiss(id) {
|
||||
this.rest.post('/notifications/dismiss', { id: id })
|
||||
this.catchEmit(this.rest.post('/notifications/dismiss', { id: id }))
|
||||
.then(() => this.removeNotification(id))
|
||||
.catch(this.emitError)
|
||||
},
|
||||
onNotificationsClear() {
|
||||
this.rest.post('/notifications/clear')
|
||||
this.catchEmit(this.rest.post('/notifications/clear'))
|
||||
.then(() => this.notifications.splice(0, this.notifications.length))
|
||||
.catch(this.emitError)
|
||||
},
|
||||
setupStream() {
|
||||
const ws = new WebSocket(
|
||||
|
@ -138,15 +134,11 @@ export default {
|
|||
}
|
||||
},
|
||||
created() {
|
||||
this.rest
|
||||
.get("/timelines/home", { params: { limit: this.buffer } })
|
||||
this.catchEmit(this.rest.get("/timelines/home", { params: { limit: this.buffer } }))
|
||||
.then(res => this.statues.push.apply(this.statues, res.data))
|
||||
.catch(this.emitError)
|
||||
|
||||
this.rest
|
||||
.get("/notifications", { params: { limit: this.buffer } })
|
||||
this.catchEmit(this.rest.get("/notifications", { params: { limit: this.buffer } }))
|
||||
.then(res => this.notifications.push.apply(this.notifications, res.data))
|
||||
.catch(this.emitError)
|
||||
|
||||
this.setupStream()
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
setting-boolean(:id="'showMedia'" :title="'Show medias'" :value="showMedia" @change="saveOptionCouple")
|
||||
client(v-if="server && token" v-bind="$props")
|
||||
.auth(v-else)
|
||||
form(@submit.prevent="setServer")
|
||||
form(@submit.prevent="makeAuth")
|
||||
p
|
||||
label(for="server") Server:
|
||||
input#server(v-model="newServer" required)
|
||||
|
@ -73,25 +73,23 @@ export default { //TODO: Use oauth
|
|||
};
|
||||
},
|
||||
methods: {
|
||||
setServer() {
|
||||
axios.get(`https://${this.newServer}/api/v1/accounts/verify_credentials`, {
|
||||
headers: { Authorization: "Bearer " + this.newToken },
|
||||
getMe(server, token) {
|
||||
return this.catchEmit(axios.get(`https://${server}/api/v1/accounts/verify_credentials`, {
|
||||
headers: { Authorization: "Bearer " + token },
|
||||
timeout: this.timeout
|
||||
}).then(() => this.saveOptions({ ...this.$props,
|
||||
}))
|
||||
},
|
||||
makeAuth() {
|
||||
this.getMe(this.newServer, this.newToken)
|
||||
.then(() => this.saveOptions({ ...this.$props,
|
||||
server: this.newServer, token: this.newToken }))
|
||||
.catch(this.emitError)
|
||||
}
|
||||
},
|
||||
created() {
|
||||
if(this.server && this.token) {
|
||||
axios.get(`https://${this.server}/api/v1/accounts/verify_credentials`, {
|
||||
headers: { Authorization: "Bearer " + this.token },
|
||||
timeout: this.timeout
|
||||
}).then(res => this.account = res.data)
|
||||
.catch(err => {
|
||||
this.emitError(err)
|
||||
this.account.display_name = 'Failed'
|
||||
})
|
||||
this.getMe(this.server, this.token)
|
||||
.then(res => this.account = res.data)
|
||||
.catch(() => this.account.display_name = 'Failed')
|
||||
} else{
|
||||
this.account.display_name = 'First connection'
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<template lang="pug">
|
||||
div
|
||||
.status
|
||||
account(v-if="withAccount" :account="status.account" :showMedia="showMedia")
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
<template lang="pug">
|
||||
.nextcloud-news(v-show="showEmpty || unreaded.length > 0 || !server || !token || !username")
|
||||
service-header(:emit="emit")
|
||||
template(#title) Nextcloud News
|
||||
template(#title)
|
||||
| Nextcloud News
|
||||
span.note(v-if="unreaded.length > 0") ({{ unreaded.length }})
|
||||
template(#settings)
|
||||
setting-int(:id="'update'" :title="'Update interval'" :value="update" @change="saveOptionCouple")
|
||||
setting-int(:id="'buffer'" :title="'Buffer size'" :value="buffer" @change="saveOptionCouple")
|
||||
|
@ -78,12 +80,11 @@ export default {
|
|||
},
|
||||
methods: {
|
||||
loadData() {
|
||||
this.rest.get("/items", { params: { batchSize: this.buffer, type: 3, getRead: false } })
|
||||
this.catchEmit(this.rest.get("/items", { params: { batchSize: this.buffer, type: 3, getRead: false } }))
|
||||
.then(res => this.unreaded = res.data.items.map(n => {
|
||||
n.open = false
|
||||
return n
|
||||
}))
|
||||
.catch(this.emitError)
|
||||
},
|
||||
removeNews(id) {
|
||||
for (var i = this.unreaded.length - 1; i >= 0; i--) {
|
||||
|
@ -94,17 +95,15 @@ export default {
|
|||
}
|
||||
},
|
||||
makeRead(id) {
|
||||
this.rest.put(`/items/${id}/read`)
|
||||
this.catchEmit(this.rest.put(`/items/${id}/read`))
|
||||
.then(() => this.removeNews(id))
|
||||
.catch(this.emitError)
|
||||
},
|
||||
setServer() {
|
||||
axios.get(`https://${this.newServer}/index.php/apps/news/api/v1-2/folders`, {
|
||||
this.catchEmit(axios.get(`https://${this.newServer}/index.php/apps/news/api/v1-2/folders`, {
|
||||
headers: { Authorization: 'Basic ' + btoa(this.newUsername + ':' + this.newToken) },
|
||||
timeout: this.timeout
|
||||
}).then(() => this.saveOptions({ ...this.$props,
|
||||
})).then(() => this.saveOptions({ ...this.$props,
|
||||
server: this.newServer, token: this.newToken, username: this.newUsername }))
|
||||
.catch(this.emitError)
|
||||
}
|
||||
},
|
||||
created() {
|
||||
|
|
|
@ -119,17 +119,15 @@ export default {
|
|||
this.loadForecast()
|
||||
},
|
||||
getWeather(params) {
|
||||
return this.rest.get('weather', { params: params })
|
||||
.catch(this.emitError)
|
||||
return this.catchEmit(this.rest.get('weather', { params: params }))
|
||||
},
|
||||
loadForecast() {
|
||||
if(this.weathers[this.selected]) {
|
||||
this.rest.get('forecast', { params: {
|
||||
this.catchEmit(this.rest.get('forecast', { params: {
|
||||
id: this.weathers[this.selected].id,
|
||||
cnt: this.forecastLimit
|
||||
}})
|
||||
}}))
|
||||
.then(res => this.forecast = res.data.list)
|
||||
.catch(this.emitError)
|
||||
}
|
||||
},
|
||||
formatDate(dt) {
|
||||
|
|
5
main.css
5
main.css
|
@ -32,6 +32,11 @@ input, select, button {
|
|||
font-size: 1.2em;
|
||||
}
|
||||
|
||||
.note {
|
||||
font-size: .7em;
|
||||
vertical-align: text-top;
|
||||
}
|
||||
|
||||
.letter {
|
||||
margin: 0 .5em;
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue