refs #662 Add mixin to reload timeline

This commit is contained in:
AkiraFukushima 2018-11-04 14:33:47 +09:00
parent 968039b5ae
commit 68d5346585
9 changed files with 50 additions and 159 deletions

View File

@ -32,10 +32,12 @@
import { mapState, mapGetters } from 'vuex'
import Toot from './Cards/Toot'
import scrollTop from '../../utils/scroll'
import reloadable from '~/src/renderer/components/mixins/reloadable'
export default {
name: 'directmessages',
components: { Toot },
mixins: [reloadable],
data () {
return {
focusedId: null
@ -132,33 +134,7 @@ export default {
async reload () {
this.$store.commit('TimelineSpace/changeLoading', true)
try {
const account = await this.$store.dispatch('TimelineSpace/localAccount', this.$route.params.id).catch((err) => {
this.$message({
message: this.$t('message.account_load_error'),
type: 'error'
})
throw err
})
await this.$store.dispatch('TimelineSpace/stopUserStreaming')
await this.$store.dispatch('TimelineSpace/stopLocalStreaming')
await this.$store.dispatch('TimelineSpace/Contents/DirectMessages/fetchTimeline', account)
.catch(() => {
this.$message({
message: this.$t('message.timeline_fetch_error'),
type: 'error'
})
})
await this.$store.dispatch('TimelineSpace/Contents/Local/fetchLocalTimeline', account)
this.$store.dispatch('TimelineSpace/startUserStreaming', account)
.catch(() => {
this.$message({
message: this.$t('message.start_streaming_error'),
type: 'error'
})
})
this.$store.dispatch('TimelineSpace/startLocalStreaming', account)
await this.reloadable()
} finally {
this.$store.commit('TimelineSpace/changeLoading', false)
}

View File

@ -29,10 +29,12 @@
import { mapState, mapGetters } from 'vuex'
import Toot from './Cards/Toot'
import scrollTop from '../../utils/scroll'
import reloadable from '~/src/renderer/components/mixins/reloadable'
export default {
name: 'favourites',
components: { Toot },
mixins: [reloadable],
data () {
return {
heading: true,
@ -123,19 +125,7 @@ export default {
async reload () {
this.$store.commit('TimelineSpace/changeLoading', true)
try {
const account = await this.$store.dispatch('TimelineSpace/localAccount', this.$route.params.id).catch((err) => {
this.$message({
message: this.$t('message.account_load_error'),
type: 'error'
})
throw err
})
await this.$store.dispatch('TimelineSpace/stopUserStreaming')
await this.$store.dispatch('TimelineSpace/stopLocalStreaming')
await this.$store.dispatch('TimelineSpace/Contents/Home/fetchTimeline', account)
await this.$store.dispatch('TimelineSpace/Contents/Local/fetchLocalTimeline', account)
const account = await this.reloadable()
await this.$store.dispatch('TimelineSpace/Contents/Favourites/fetchFavourites', account)
.catch(() => {
this.$message({
@ -143,9 +133,6 @@ export default {
type: 'error'
})
})
this.$store.dispatch('TimelineSpace/startUserStreaming', account)
this.$store.dispatch('TimelineSpace/startLocalStreaming', account)
} finally {
this.$store.commit('TimelineSpace/changeLoading', false)
}

View File

@ -14,7 +14,7 @@
v-on:delete="deleteToot"
@focusNext="focusNext"
@focusPrev="focusPrev"
@selectToot="focusToot(index)"
@selectToot="focusToot(message)"
>
</toot>
</div>
@ -31,10 +31,12 @@
import { mapState, mapGetters } from 'vuex'
import Toot from '../Cards/Toot'
import scrollTop from '../../../utils/scroll'
import reloadable from '~/src/renderer/components/mixins/reloadable'
export default {
name: 'tag',
components: { Toot },
mixins: [reloadable],
props: ['tag'],
data () {
return {
@ -158,20 +160,8 @@ export default {
const tag = this.tag
this.$store.commit('TimelineSpace/changeLoading', true)
try {
const account = await this.$store.dispatch('TimelineSpace/localAccount', this.$route.params.id).catch((err) => {
this.$message({
message: this.$t('message.account_load_error'),
type: 'error'
})
throw err
})
await this.$store.dispatch('TimelineSpace/stopUserStreaming')
await this.$store.dispatch('TimelineSpace/stopLocalStreaming')
await this.reloadable()
await this.$store.dispatch('TimelineSpace/Contents/Hashtag/Tag/stopStreaming')
await this.$store.dispatch('TimelineSpace/Contents/Hashtag/Tag/fetchTimeline', account)
await this.$store.dispatch('TimelineSpace/Contents/Local/fetchLocalTimeline', account)
await this.$store.dispatch('TimelineSpace/Contents/Hashtag/Tag/fetch', tag)
.catch(() => {
this.$message({
@ -179,9 +169,6 @@ export default {
type: 'error'
})
})
this.$store.dispatch('TimelineSpace/startUserStreaming', account)
this.$store.dispatch('TimelineSpace/startLocalStreaming', account)
this.$store.dispatch('TimelineSpace/Contents/Hashtag/Tag/startStreaming', tag)
.catch(() => {
this.$message({

View File

@ -32,10 +32,12 @@
import { mapState, mapGetters } from 'vuex'
import Toot from './Cards/Toot'
import scrollTop from '../../utils/scroll'
import reloadable from '~/src/renderer/components/mixins/reloadable'
export default {
name: 'home',
components: { Toot },
mixins: [reloadable],
data () {
return {
focusedId: null
@ -132,33 +134,7 @@ export default {
async reload () {
this.$store.commit('TimelineSpace/changeLoading', true)
try {
const account = await this.$store.dispatch('TimelineSpace/localAccount', this.$route.params.id).catch((err) => {
this.$message({
message: this.$t('message.account_load_error'),
type: 'error'
})
throw err
})
await this.$store.dispatch('TimelineSpace/stopUserStreaming')
await this.$store.dispatch('TimelineSpace/stopLocalStreaming')
await this.$store.dispatch('TimelineSpace/Contents/Home/fetchTimeline', account)
.catch(() => {
this.$message({
message: this.$t('message.timeline_fetch_error'),
type: 'error'
})
})
await this.$store.dispatch('TimelineSpace/Contents/Local/fetchLocalTimeline', account)
this.$store.dispatch('TimelineSpace/startUserStreaming', account)
.catch(() => {
this.$message({
message: this.$t('message.start_streaming_error'),
type: 'error'
})
})
this.$store.dispatch('TimelineSpace/startLocalStreaming', account)
await this.reloadable()
} finally {
this.$store.commit('TimelineSpace/changeLoading', false)
}

View File

@ -31,11 +31,13 @@
import { mapState, mapGetters } from 'vuex'
import Toot from '../Cards/Toot'
import scrollTop from '../../../utils/scroll'
import reloadable from '~/src/renderer/components/mixins/reloadable'
export default {
name: 'list',
props: ['list_id'],
components: { Toot },
mixins: [reloadable],
data () {
return {
focusedId: null
@ -157,20 +159,8 @@ export default {
async reload () {
this.$store.commit('TimelineSpace/changeLoading', true)
try {
const account = await this.$store.dispatch('TimelineSpace/localAccount', this.$route.params.id).catch((err) => {
this.$message({
message: this.$t('message.account_load_error'),
type: 'error'
})
throw err
})
await this.$store.dispatch('TimelineSpace/stopUserStreaming')
await this.$store.dispatch('TimelineSpace/stopLocalStreaming')
await this.reloadable()
await this.$store.dispatch('TimelineSpace/Contents/Lists/Show/stopStreaming')
await this.$store.dispatch('TimelineSpace/Contents/Lists/Show/fetchTimeline', account)
await this.$store.dispatch('TimelineSpace/Contents/Local/fetchLocalTimeline', account)
await this.$store.dispatch('TimelineSpace/Contents/Lists/Show/fetchTimeline', this.list_id)
.catch(() => {
this.$message({
@ -178,9 +168,6 @@ export default {
type: 'error'
})
})
this.$store.dispatch('TimelineSpace/startUserStreaming', account)
this.$store.dispatch('TimelineSpace/startLocalStreaming', account)
this.$store.dispatch('TimelineSpace/Contents/Lists/Show/startStreaming', this.list_id)
.catch(() => {
this.$message({

View File

@ -32,10 +32,12 @@
import { mapState, mapGetters } from 'vuex'
import Toot from './Cards/Toot'
import scrollTop from '../../utils/scroll'
import reloadable from '~/src/renderer/components/mixins/reloadable'
export default {
name: 'local',
components: { Toot },
mixins: [reloadable],
data () {
return {
focusedId: null
@ -131,33 +133,7 @@ export default {
async reload () {
this.$store.commit('TimelineSpace/changeLoading', true)
try {
const account = await this.$store.dispatch('TimelineSpace/localAccount', this.$route.params.id).catch((err) => {
this.$message({
message: this.$t('message.account_load_error'),
type: 'error'
})
throw err
})
await this.$store.dispatch('TimelineSpace/stopUserStreaming')
await this.$store.dispatch('TimelineSpace/stopLocalStreaming')
await this.$store.dispatch('TimelineSpace/Contents/Home/fetchTimeline', account)
await this.$store.dispatch('TimelineSpace/Contents/Local/fetchLocalTimeline', account)
.catch(() => {
this.$message({
message: this.$t('message.timeline_fetch_error'),
type: 'error'
})
})
this.$store.dispatch('TimelineSpace/startUserStreaming', account)
this.$store.dispatch('TimelineSpace/startLocalStreaming', account)
.catch(() => {
this.$message({
message: this.$t('message.start_streaming_error'),
type: 'error'
})
})
await this.reloadable()
} finally {
this.$store.commit('TimelineSpace/changeLoading', false)
}

View File

@ -30,10 +30,12 @@
import { mapState, mapGetters } from 'vuex'
import Notification from './Cards/Notification'
import scrollTop from '../../utils/scroll'
import reloadable from '~/src/renderer/components/mixins/reloadable'
export default {
name: 'notifications',
components: { Notification },
mixins: [reloadable],
data () {
return {
focusedId: null
@ -126,18 +128,7 @@ export default {
async reload () {
this.$store.commit('TimelineSpace/changeLoading', true)
try {
const account = await this.$store.dispatch('TimelineSpace/localAccount', this.$route.params.id).catch((err) => {
this.$message({
message: this.$t('message.account_load_error'),
type: 'error'
})
throw err
})
await this.$store.dispatch('TimelineSpace/stopUserStreaming')
await this.$store.dispatch('TimelineSpace/stopLocalStreaming')
await this.$store.dispatch('TimelineSpace/Contents/Home/fetchTimeline', account)
await this.$store.dispatch('TimelineSpace/Contents/Local/fetchLocalTimeline', account)
const account = await this.reloadable()
await this.$store.dispatch('TimelineSpace/Contents/Notifications/fetchNotifications', account)
.catch(() => {
this.$message({
@ -147,8 +138,6 @@ export default {
})
this.$store.dispatch('TimelineSpace/Contents/Notifications/resetBadge')
this.$store.dispatch('TimelineSpace/startUserStreaming', account)
this.$store.dispatch('TimelineSpace/startLocalStreaming', account)
} finally {
this.$store.commit('TimelineSpace/changeLoading', false)
}

View File

@ -32,10 +32,12 @@
import { mapState, mapGetters } from 'vuex'
import Toot from './Cards/Toot'
import scrollTop from '../../utils/scroll'
import reloadable from '~/src/renderer/components/mixins/reloadable'
export default {
name: 'public',
components: { Toot },
mixins: [reloadable],
data () {
return {
focusedId: null
@ -151,19 +153,8 @@ export default {
async reload () {
this.$store.commit('TimelineSpace/changeLoading', true)
try {
const account = await this.$store.dispatch('TimelineSpace/localAccount', this.$route.params.id).catch((err) => {
this.$message({
message: this.$t('message.account_load_error'),
type: 'error'
})
throw err
})
await this.$store.dispatch('TimelineSpace/stopUserStreaming')
await this.$store.dispatch('TimelineSpace/stopLocalStreaming')
await this.reloadable()
await this.$store.dispatch('TimelineSpace/Contents/Public/stopPublicStreaming')
await this.$store.dispatch('TimelineSpace/Contents/Home/fetchTimeline', account)
await this.$store.dispatch('TimelineSpace/Contents/Local/fetchLocalTimeline', account)
await this.$store.dispatch('TimelineSpace/Contents/Public/fetchPublicTimeline')
.catch(() => {
this.$message({
@ -171,9 +162,6 @@ export default {
type: 'error'
})
})
this.$store.dispatch('TimelineSpace/startUserStreaming', account)
this.$store.dispatch('TimelineSpace/startLocalStreaming', account)
this.$store.dispatch('TimelineSpace/Contents/Public/startPublicStreaming')
.catch(() => {
this.$message({

View File

@ -0,0 +1,25 @@
<script>
export default {
name: 'reloadable',
methods: {
async reloadable () {
const account = await this.$store.dispatch('TimelineSpace/localAccount', this.$route.params.id).catch((err) => {
this.$message({
message: this.$t('message.account_load_error'),
type: 'error'
})
throw err
})
await this.$store.dispatch('TimelineSpace/stopUserStreaming')
await this.$store.dispatch('TimelineSpace/stopLocalStreaming')
await this.$store.dispatch('TimelineSpace/Contents/Home/fetchTimeline', account)
await this.$store.dispatch('TimelineSpace/Contents/Local/fetchLocalTimeline', account)
this.$store.dispatch('TimelineSpace/startUserStreaming', account)
this.$store.dispatch('TimelineSpace/startLocalStreaming', account)
return account
}
}
}
</script>