feat: 🏗️ add event bus to manage updating episode list
This commit is contained in:
parent
624c52c231
commit
ce0e6e06bc
@ -100,6 +100,7 @@
|
|||||||
import { NcActionButton, NcActionLink, NcActions, NcAvatar, NcListItem, NcModal, NcProgressBar } from '@nextcloud/vue'
|
import { NcActionButton, NcActionLink, NcActions, NcAvatar, NcListItem, NcModal, NcProgressBar } from '@nextcloud/vue'
|
||||||
import { durationToSeconds, formatEpisodeTimestamp, formatLocaleDate } from '../../utils/time.js'
|
import { durationToSeconds, formatEpisodeTimestamp, formatLocaleDate } from '../../utils/time.js'
|
||||||
import Download from 'vue-material-design-icons/Download.vue'
|
import Download from 'vue-material-design-icons/Download.vue'
|
||||||
|
import { EventBus } from '../../store/bus.js'
|
||||||
import Loading from '../Atoms/Loading.vue'
|
import Loading from '../Atoms/Loading.vue'
|
||||||
import Modal from '../Atoms/Modal.vue'
|
import Modal from '../Atoms/Modal.vue'
|
||||||
import OpenInNew from 'vue-material-design-icons/OpenInNew.vue'
|
import OpenInNew from 'vue-material-design-icons/OpenInNew.vue'
|
||||||
@ -172,6 +173,7 @@ export default {
|
|||||||
this.loading = true
|
this.loading = true
|
||||||
const episodes = await axios.get(generateUrl('/apps/repod/episodes/list?url={url}', { url: this.url }))
|
const episodes = await axios.get(generateUrl('/apps/repod/episodes/list?url={url}', { url: this.url }))
|
||||||
this.episodes = [...episodes.data].sort((a, b) => new Date(b.pubDate?.date) - new Date(a.pubDate?.date))
|
this.episodes = [...episodes.data].sort((a, b) => new Date(b.pubDate?.date) - new Date(a.pubDate?.date))
|
||||||
|
EventBus.$on('updateEpisodesList', this.updateList)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
showError(t('repod', 'Could not fetch episodes'))
|
showError(t('repod', 'Could not fetch episodes'))
|
||||||
@ -179,6 +181,9 @@ export default {
|
|||||||
this.loading = false
|
this.loading = false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
destroyed() {
|
||||||
|
EventBus.$off('updateEpisodesList')
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
formatLocaleDate,
|
formatLocaleDate,
|
||||||
hasEnded(episode) {
|
hasEnded(episode) {
|
||||||
@ -199,7 +204,7 @@ export default {
|
|||||||
async markAs(episode, read) {
|
async markAs(episode, read) {
|
||||||
try {
|
try {
|
||||||
this.loadingAction = true
|
this.loadingAction = true
|
||||||
const action = {
|
episode.action = {
|
||||||
podcast: this.url,
|
podcast: this.url,
|
||||||
episode: episode.url,
|
episode: episode.url,
|
||||||
guid: episode.guid,
|
guid: episode.guid,
|
||||||
@ -209,13 +214,8 @@ export default {
|
|||||||
position: read ? durationToSeconds(episode.duration) : 0,
|
position: read ? durationToSeconds(episode.duration) : 0,
|
||||||
total: durationToSeconds(episode.duration),
|
total: durationToSeconds(episode.duration),
|
||||||
}
|
}
|
||||||
await axios.post(generateUrl('/apps/gpoddersync/episode_action/create'), [action])
|
await axios.post(generateUrl('/apps/gpoddersync/episode_action/create'), [episode.action])
|
||||||
this.episodes = this.episodes.map((e) => {
|
this.updateList(episode)
|
||||||
if (e.url === episode.url) {
|
|
||||||
e.action = action
|
|
||||||
}
|
|
||||||
return e
|
|
||||||
})
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
showError(t('repod', 'Could not change the status of the episode'))
|
showError(t('repod', 'Could not change the status of the episode'))
|
||||||
@ -223,6 +223,9 @@ export default {
|
|||||||
this.loadingAction = false
|
this.loadingAction = false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
updateList(episode) {
|
||||||
|
this.episodes = this.episodes.map((e) => e.url === episode.url ? episode : e)
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
3
src/store/bus.js
Normal file
3
src/store/bus.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import Vue from 'vue'
|
||||||
|
|
||||||
|
export const EventBus = new Vue()
|
Loading…
Reference in New Issue
Block a user