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,38 +1,37 @@
|
|||
<template lang="pug">
|
||||
div
|
||||
.status
|
||||
account(v-if="withAccount" :account="status.account" :showMedia="showMedia")
|
||||
.status
|
||||
account(v-if="withAccount" :account="status.account" :showMedia="showMedia")
|
||||
|
||||
span.text-icon.letter(v-if="status.reblog") ⟳
|
||||
span.text-icon.letter(v-if="status.reblog") ⟳
|
||||
|
||||
a.date(target="_blank" :href="status.uri")
|
||||
from-now(:date="status.created_at" :now="now")
|
||||
a.date(target="_blank" :href="status.uri")
|
||||
from-now(:date="status.created_at" :now="now")
|
||||
|
||||
.content(:class="{ avatared: showMedia }")
|
||||
template(v-if="!status.reblog")
|
||||
.spoiler(v-if="status.spoiler_text" @click.stop.prevent="status.sensitive = !status.sensitive").
|
||||
{{ status.spoiler_text || 'Spoiler' }} {{ status.sensitive ? '→' : '↓' }}
|
||||
div(v-if="!status.spoiler_text || !status.sensitive")
|
||||
.text(v-html="parseEmojis(status.content, status.emojis)")
|
||||
a.media(v-for="media in status.media_attachments" :href="media.url" target="_blank")
|
||||
template(v-if="showMedia")
|
||||
img(v-if="media.type == 'image' || media.type == 'gifv'" :src="media.preview_url" :alt="media.description" :title="media.description")
|
||||
.gif(v-if="media.type == 'gifv'") GIF
|
||||
template(v-else) Hidden media
|
||||
status.reblog(v-else :status="status.reblog" :now="now" :showMedia="showMedia")
|
||||
.content(:class="{ avatared: showMedia }")
|
||||
template(v-if="!status.reblog")
|
||||
.spoiler(v-if="status.spoiler_text" @click.stop.prevent="status.sensitive = !status.sensitive").
|
||||
{{ status.spoiler_text || 'Spoiler' }} {{ status.sensitive ? '→' : '↓' }}
|
||||
div(v-if="!status.spoiler_text || !status.sensitive")
|
||||
.text(v-html="parseEmojis(status.content, status.emojis)")
|
||||
a.media(v-for="media in status.media_attachments" :href="media.url" target="_blank")
|
||||
template(v-if="showMedia")
|
||||
img(v-if="media.type == 'image' || media.type == 'gifv'" :src="media.preview_url" :alt="media.description" :title="media.description")
|
||||
.gif(v-if="media.type == 'gifv'") GIF
|
||||
template(v-else) Hidden media
|
||||
status.reblog(v-else :status="status.reblog" :now="now" :showMedia="showMedia")
|
||||
|
||||
.meta(v-if="!status.reblog")
|
||||
a.replies(@click.stop.prevent="makeReply(status)")
|
||||
span.text-icon ✉
|
||||
| {{ status.replies_count }}
|
||||
a.reblogs(:class="{ colored: status.reblogged }" @click.stop.prevent="makeReblog(status)")
|
||||
span.text-icon ⟳
|
||||
| {{ status.reblogs_count }}
|
||||
a.favourites(:class="{ colored: status.favourited }" @click.stop.prevent="makeFav(status)")
|
||||
span.text-icon ⚝
|
||||
| {{ status.favourites_count }}
|
||||
a.fil(v-if="status.in_reply_to_id" @click.stop.prevent="showReply(status.in_reply_to_id)")
|
||||
| Voir le fil
|
||||
.meta(v-if="!status.reblog")
|
||||
a.replies(@click.stop.prevent="makeReply(status)")
|
||||
span.text-icon ✉
|
||||
| {{ status.replies_count }}
|
||||
a.reblogs(:class="{ colored: status.reblogged }" @click.stop.prevent="makeReblog(status)")
|
||||
span.text-icon ⟳
|
||||
| {{ status.reblogs_count }}
|
||||
a.favourites(:class="{ colored: status.favourited }" @click.stop.prevent="makeFav(status)")
|
||||
span.text-icon ⚝
|
||||
| {{ status.favourites_count }}
|
||||
a.fil(v-if="status.in_reply_to_id" @click.stop.prevent="showReply(status.in_reply_to_id)")
|
||||
| Voir le fil
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
|
|
@ -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