Improvements
This commit is contained in:
parent
cc70df90af
commit
cf65818eb4
|
@ -35,6 +35,7 @@
|
||||||
if (item) {
|
if (item) {
|
||||||
let loginData = JSON.parse(item)
|
let loginData = JSON.parse(item)
|
||||||
this.$store.dispatch('isLoggedIn', loginData)
|
this.$store.dispatch('isLoggedIn', loginData)
|
||||||
|
this.$store.dispatch('startEventListening', '?action=events')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h3 class="title is-6" v-if="currentItem.name" v-text="currentItem.name"></h3>
|
<h3 class="title is-6" v-if="currentItem.name" v-text="currentItem.name"></h3>
|
||||||
<div class="content is-pre" v-html="main_content"></div>
|
<div class="content" v-html="main_content"></div>
|
||||||
|
|
||||||
<div class="photos">
|
<div class="photos">
|
||||||
<div class="photo" v-for="photo in photo_rest" :key="photo">
|
<div class="photo" v-for="photo in photo_rest" :key="photo">
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<template>
|
<template>
|
||||||
<div style="margin-top: 20px">
|
<div class="short-timeline">
|
||||||
<div class="box small-item" style="margin-bottom: 4px" v-for="(item, i) in timeline.items" :key="i">
|
<div class="box small-item" style="margin-bottom: 4px" v-for="(item, i) in timeline.items" :key="i">
|
||||||
<div class="name" v-text="text(item)"></div>
|
<div class="name" v-text="text(item)"></div>
|
||||||
<div class="time" v-text="niceTime(item)"></div>
|
<div class="time" v-text="niceTime(item)"></div>
|
||||||
|
@ -36,8 +36,13 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
.short-timeline {
|
||||||
|
margin-top: 20px;
|
||||||
|
position: fixed;
|
||||||
|
max-width: 280px;
|
||||||
|
}
|
||||||
.small-item {
|
.small-item {
|
||||||
font-size: 10px;
|
font-size: 12px;
|
||||||
}
|
}
|
||||||
.box {
|
.box {
|
||||||
padding: 6px;
|
padding: 6px;
|
||||||
|
|
|
@ -59,7 +59,7 @@
|
||||||
.then(() => {
|
.then(() => {
|
||||||
item._is_read = true
|
item._is_read = true
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
this.$store.dispatch('fetchChannels')
|
// this.$store.dispatch('fetchChannels')
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
handleScroll() {
|
handleScroll() {
|
||||||
|
@ -77,7 +77,7 @@
|
||||||
child.$props.item._is_read = true
|
child.$props.item._is_read = true
|
||||||
let item = child.$props.item
|
let item = child.$props.item
|
||||||
this.markRead(this.channel.uid, item).then(() => {
|
this.markRead(this.channel.uid, item).then(() => {
|
||||||
this.$store.dispatch('fetchChannels')
|
// this.$store.dispatch('fetchChannels')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import router from './router'
|
||||||
import store from './store'
|
import store from './store'
|
||||||
import 'bulma'
|
import 'bulma'
|
||||||
import '@/styles.scss'
|
import '@/styles.scss'
|
||||||
|
import '@primer/css/utilities/index.scss';
|
||||||
|
|
||||||
Vue.config.productionTip = false
|
Vue.config.productionTip = false
|
||||||
|
|
||||||
|
|
50
src/store.js
50
src/store.js
|
@ -63,6 +63,9 @@ export default new Vuex.Store({
|
||||||
state.microsubEndpoint = endpoints.microsubEndpoint
|
state.microsubEndpoint = endpoints.microsubEndpoint
|
||||||
},
|
},
|
||||||
createEventSource(state, url) {
|
createEventSource(state, url) {
|
||||||
|
if (state.eventSource !== null) {
|
||||||
|
state.eventSource.close()
|
||||||
|
}
|
||||||
state.eventSource = new EventSource(state.microsubEndpoint + url + "&access_token=" + state.access_token, {
|
state.eventSource = new EventSource(state.microsubEndpoint + url + "&access_token=" + state.access_token, {
|
||||||
// headers: {
|
// headers: {
|
||||||
// 'Authorization': 'Bearer ' + this.state.access_token
|
// 'Authorization': 'Bearer ' + this.state.access_token
|
||||||
|
@ -83,15 +86,24 @@ export default new Vuex.Store({
|
||||||
state.eventSource.addEventListener('error', evt => {
|
state.eventSource.addEventListener('error', evt => {
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
console.log(evt)
|
console.log(evt)
|
||||||
|
if (evt.message === "network error") {
|
||||||
|
state.eventSource.close()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
state.eventSource.addEventListener('new item', evt => {
|
state.eventSource.addEventListener('new item', evt => {
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
console.log(evt)
|
console.log(evt)
|
||||||
|
|
||||||
let item = JSON.parse(evt.data)
|
try {
|
||||||
// eslint-disable-next-line
|
let newItemMsg = JSON.parse(evt.data)
|
||||||
state.timeline.items = [...state.timeline.items, item]
|
if (state.channel.uid === newItemMsg.channel) {
|
||||||
state.globalTimeline.items = _.take([item, ...state.globalTimeline.items], 10)
|
state.timeline.items = [...state.timeline.items, newItemMsg.item]
|
||||||
|
}
|
||||||
|
state.globalTimeline.items = _.takeRight([...state.globalTimeline.items, newItemMsg.item], 10)
|
||||||
|
} catch (e) {
|
||||||
|
// eslint-disable-next-line
|
||||||
|
console.log(e)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
state.eventSource.addEventListener('new item in channel', evt => {
|
state.eventSource.addEventListener('new item in channel', evt => {
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
|
@ -152,7 +164,13 @@ export default new Vuex.Store({
|
||||||
commit('newAccessToken', response)
|
commit('newAccessToken', response)
|
||||||
},
|
},
|
||||||
markRead(x, {channel, entry}) {
|
markRead(x, {channel, entry}) {
|
||||||
let url = this.state.microsubEndpoint + '?action=timeline&method=mark_read&channel=' + encodeURIComponent(channel) + '&entry=' + encodeURIComponent(entry);
|
let entries = '';
|
||||||
|
if (Array.isArray(entry)) {
|
||||||
|
entries = _(entry).map(uid => '&entry[]='+encodeURIComponent(uid)).join("")
|
||||||
|
} else {
|
||||||
|
entries = '&entry=' + encodeURIComponent(entry)
|
||||||
|
}
|
||||||
|
let url = this.state.microsubEndpoint + '?action=timeline&method=mark_read&channel=' + encodeURIComponent(channel) + entries;
|
||||||
return fetch(url, {
|
return fetch(url, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -193,21 +211,23 @@ export default new Vuex.Store({
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
bottomReached() {
|
bottomReached() {
|
||||||
let count = 0
|
// eslint-disable-next-line
|
||||||
let uids = []
|
console.log('bottomReached')
|
||||||
|
|
||||||
let items = this.state.timeline.items
|
let items = this.state.timeline.items
|
||||||
uids = _.map(_.filter(items, item => !item._is_read), item => item._id)
|
// eslint-disable-next-line
|
||||||
|
console.log(items)
|
||||||
|
let uids = _(items).reject('_is_read').map('_id').value()
|
||||||
|
// eslint-disable-next-line
|
||||||
|
console.log(uids)
|
||||||
|
|
||||||
items.forEach((item) => {
|
items.forEach((item) => {
|
||||||
if (item && !item._is_read) {
|
if (item && !item._is_read) {
|
||||||
item._is_read = true
|
item._is_read = true
|
||||||
count++;
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (count > 0) {
|
if (uids.length > 0) {
|
||||||
this.dispatch('markRead', {channel: this.state.channel.uid, 'entry[]': uids})
|
return this.dispatch('markRead', {channel: this.state.channel.uid, 'entry': uids})
|
||||||
.then(() => {
|
|
||||||
this.dispatch('fetchChannels')
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
startEventListening({commit}, url) {
|
startEventListening({commit}, url) {
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
@import 'bulmaswatch.min.css';
|
//@import 'bulmaswatch.min.css';
|
||||||
|
|
||||||
.mb-20 {
|
.mb-20 {
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.mt-20 {
|
.mt-20 {
|
||||||
margin-top: 20px;
|
margin-top: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -111,7 +111,6 @@
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
if (this.$store.state.logged_in) {
|
if (this.$store.state.logged_in) {
|
||||||
this.$store.dispatch('startEventListening', '?action=events')
|
|
||||||
this.$store.dispatch('fetchChannels')
|
this.$store.dispatch('fetchChannels')
|
||||||
this.$store.dispatch('fetchTimeline', {uid: this.uid})
|
this.$store.dispatch('fetchTimeline', {uid: this.uid})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user