refs #3301 Rewrite TimelineSpace/Contents/Lists with composition API

This commit is contained in:
AkiraFukushima 2022-06-15 23:24:25 +09:00
parent f6aa14d54e
commit c640e29019
No known key found for this signature in database
GPG Key ID: B6E51BAC4DE1A957
5 changed files with 325 additions and 300 deletions

View File

@ -6,83 +6,82 @@
</el-button>
</div>
<template v-for="account in members">
<user
:user="account"
:remove="true"
@removeAccount="removeAccount"
></user>
<user :user="account" :remove="true" @removeAccount="removeAccount"></user>
</template>
</div>
</template>
<script>
import { mapState } from 'vuex'
import User from '~/src/renderer/components/molecules/User'
<script lang="ts">
import { computed, defineComponent, onMounted, toRefs } from 'vue'
import { ElMessage } from 'element-plus'
import { useI18next } from 'vue3-i18next'
import { Entity } from 'megalodon'
import { useStore } from '@/store'
import User from '@/components/molecules/User.vue'
import { MUTATION_TYPES as CONTENTS_MUTATION } from '@/store/TimelineSpace/Contents'
import { ACTION_TYPES } from '@/store/TimelineSpace/Contents/Lists/Edit'
import {
MUTATION_TYPES as ADD_LIST_MEMBER_MUTATION,
ACTION_TYPES as ADD_LIST_MEMBER_ACTION
} from '@/store/TimelineSpace/Modals/AddListMember'
export default {
export default defineComponent({
name: 'edit-list',
props: ['list_id'],
components: { User },
computed: {
...mapState({
members: (state) => state.TimelineSpace.Contents.Lists.Edit.members,
}),
},
created() {
this.init()
},
methods: {
async init() {
this.$store.commit('TimelineSpace/Contents/changeLoading', true)
setup(props) {
const { list_id } = toRefs(props)
const space = 'TimelineSpace/Contents/Lists/Edit'
const store = useStore()
const i18n = useI18next()
const members = computed(() => store.state.TimelineSpace.Contents.Lists.Edit.members)
onMounted(async () => {
await init()
})
const init = async () => {
store.commit(`TimelineSpace/Contents/${CONTENTS_MUTATION.CHANGE_LOADING}`, true)
try {
await this.$store.dispatch(
'TimelineSpace/Contents/Lists/Edit/fetchMembers',
this.list_id
)
await store.dispatch(`${space}/${ACTION_TYPES.FETCH_MEMBERS}`, list_id.value)
} catch (err) {
this.$message({
message: this.$t('message.members_fetch_error'),
type: 'error',
ElMessage({
message: i18n.t('message.members_fetch_error'),
type: 'error'
})
} finally {
this.$store.commit('TimelineSpace/Contents/changeLoading', false)
store.commit(`TimelineSpace/Contents/${CONTENTS_MUTATION.CHANGE_LOADING}`, false)
}
},
async removeAccount(account) {
this.$store.commit('TimelineSpace/Contents/changeLoading', true)
}
const removeAccount = async (account: Entity.Account) => {
store.commit(`TimelineSpace/Contents/${CONTENTS_MUTATION.CHANGE_LOADING}`, true)
try {
await this.$store.dispatch(
'TimelineSpace/Contents/Lists/Edit/removeAccount',
{
account: account,
listId: this.list_id,
}
)
await this.$store.dispatch(
'TimelineSpace/Contents/Lists/Edit/fetchMembers',
this.list_id
)
await store.dispatch(`${space}/${ACTION_TYPES.REMOVE_ACCOUNT}`, {
account: account,
listId: list_id.value
})
await store.dispatch(`${space}/${ACTION_TYPES.FETCH_MEMBERS}`, list_id.value)
} catch (err) {
this.$message({
message: this.$t('message.remove_user_error'),
type: 'error',
ElMessage({
message: i18n.t('message.remove_user_error'),
type: 'error'
})
} finally {
this.$store.commit('TimelineSpace/Contents/changeLoading', false)
store.commit(`TimelineSpace/Contents/${CONTENTS_MUTATION.CHANGE_LOADING}`, false)
}
},
addAccount() {
this.$store.commit(
'TimelineSpace/Modals/AddListMember/setListId',
this.list_id
)
this.$store.dispatch(
'TimelineSpace/Modals/AddListMember/changeModal',
true
)
},
},
}
}
const addAccount = () => {
store.commit(`TimelineSpace/Modals/AddListMember/${ADD_LIST_MEMBER_MUTATION.SET_LIST_ID}`, list_id.value)
store.dispatch(`TimelineSpace/Modals/AddListMember/${ADD_LIST_MEMBER_ACTION.CHANGE_MODAL}`, true)
}
return {
addAccount,
members,
removeAccount
}
}
})
</script>
<style lang="scss" scoped>

View File

@ -9,7 +9,7 @@
</el-form>
</div>
<div class="list" v-for="list in lists" :key="list.id">
<router-link tag="div" class="title" :to="`/${id()}/lists/${list.id}`">
<router-link tag="div" class="title" :to="`/${id}/lists/${list.id}`">
{{ list.title }}
</router-link>
<div class="tools">
@ -24,72 +24,90 @@
</div>
</template>
<script>
import { mapState } from 'vuex'
<script lang="ts">
import { computed, defineComponent, onMounted, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { Entity } from 'megalodon'
import { useI18next } from 'vue3-i18next'
import { useRoute, useRouter } from 'vue-router'
import { useStore } from '@/store'
import { MUTATION_TYPES as TIMELINE_MUTATION } from '@/store/TimelineSpace'
import { ACTION_TYPES } from '@/store/TimelineSpace/Contents/Lists/Index'
import { ACTION_TYPES as SIDE_MENU_ACTION } from '@/store/TimelineSpace/SideMenu'
export default {
export default defineComponent({
name: 'lists',
data() {
return {
title: '',
creating: false
}
},
computed: {
...mapState({
lists: state => state.TimelineSpace.Contents.Lists.Index.lists,
loadingBackground: state => state.App.theme.wrapper_mask_color
setup() {
const space = 'TimelineSpace/Contents/Lists/Index'
const store = useStore()
const route = useRoute()
const router = useRouter()
const i18n = useI18next()
const title = ref<string>('')
const creating = ref<boolean>(false)
const lists = computed(() => store.state.TimelineSpace.Contents.Lists.Index.lists)
const loadingBackground = computed(() => store.state.App.theme.wrapper_mask_color)
const id = computed(() => route.params.id)
onMounted(() => {
store.commit(`TimelineSpace/${TIMELINE_MUTATION.CHANGE_LOADING}`, true)
fetch().finally(() => {
store.commit(`TimelineSpace/${TIMELINE_MUTATION.CHANGE_LOADING}`, false)
})
})
},
created() {
this.$store.commit('TimelineSpace/changeLoading', true)
this.fetch().finally(() => {
this.$store.commit('TimelineSpace/changeLoading', false)
})
},
methods: {
id() {
return this.$route.params.id
},
fetch() {
return this.$store.dispatch('TimelineSpace/Contents/Lists/Index/fetchLists').catch(() => {
this.$message({
message: this.$t('message.lists_fetch_error'),
const fetch = async () => {
return store.dispatch(`${space}/${ACTION_TYPES.FETCH_LISTS}`).catch(() => {
ElMessage({
message: i18n.t('message.lists_fetch_error'),
type: 'error'
})
})
},
async createList() {
this.creating = true
}
const createList = async () => {
creating.value = true
try {
await this.$store.dispatch('TimelineSpace/Contents/Lists/Index/createList', this.title)
await this.$store.dispatch('TimelineSpace/Contents/Lists/Index/fetchLists')
await store.dispatch(`${space}/${ACTION_TYPES.CREATE_LIST}`, title.value)
await store.dispatch(`${space}/${ACTION_TYPES.FETCH_LISTS}`)
} catch (err) {
this.$message({
message: this.$t('message.list_create_error'),
ElMessage({
message: i18n.t('message.list_create_error'),
type: 'error'
})
} finally {
this.creating = false
creating.value = false
}
await this.$store.dispatch('TimelineSpace/SideMenu/fetchLists')
},
edit(list) {
return this.$router.push(`/${this.id()}/lists/${list.id}/edit`)
},
del(list) {
this.$confirm(this.$t('lists.index.delete.confirm.message'), this.$t('lists.index.delete.confirm.title'), {
confirmButtonText: this.$t('lists.index.delete.confirm.ok'),
cancelButtonText: this.$t('lists.index.delete.confirm.cancel'),
await store.dispatch(`TimelineSpace/SideMenu/${SIDE_MENU_ACTION.FETCH_LISTS}`)
}
const edit = (list: Entity.List) => {
return router.push(`/${id.value}/lists/${list.id}/edit`)
}
const del = (list: Entity.List) => {
ElMessageBox.confirm(i18n.t('lists.index.delete.confirm.message'), i18n.t('lists.index.delete.confirm.title'), {
confirmButtonText: i18n.t('lists.index.delete.confirm.ok'),
cancelButtonText: i18n.t('lists.index.delete.confirm.cancel'),
type: 'warning'
})
.then(() => {
this.$store.dispatch('TimelineSpace/Contents/Lists/Index/deleteList', list)
store.dispatch(`${space}/${ACTION_TYPES.DELETE_LIST}`, list)
})
.catch(() => {})
}
return {
id,
creating,
title,
lists,
loadingBackground,
createList,
edit,
del
}
}
}
})
</script>
<style lang="scss" scoped>

View File

@ -29,256 +29,248 @@
</div>
</template>
<script>
import { mapState, mapGetters } from 'vuex'
<script lang="ts">
import { defineComponent, toRefs, ref, computed, onMounted, onBeforeUpdate, watch, onBeforeUnmount, onUnmounted } from 'vue'
import moment from 'moment'
import Toot from '~/src/renderer/components/organisms/Toot'
import { EventEmitter } from '~/src/renderer/components/event'
import { ScrollPosition } from '~/src/renderer/components/utils/scroll'
import { ElMessage } from 'element-plus'
import { useI18next } from 'vue3-i18next'
import { Entity } from 'megalodon'
import { useStore } from '@/store'
import Toot from '@/components/organisms/Toot.vue'
import { EventEmitter } from '@/components/event'
import { ScrollPosition } from '@/components/utils/scroll'
import { MUTATION_TYPES as CONTENTS_MUTATION } from '@/store/TimelineSpace/Contents'
import { MUTATION_TYPES as HEADER_MUTATION } from '@/store/TimelineSpace/HeaderMenu'
import { ACTION_TYPES, MUTATION_TYPES } from '@/store/TimelineSpace/Contents/Lists/Show'
import { MUTATION_TYPES as TIMELINE_MUTATION } from '@/store/TimelineSpace'
export default {
data() {
return {
focusedId: null,
scrollPosition: null,
observer: null,
scrollTime: null,
resizeTime: null
}
},
export default defineComponent({
name: 'list',
props: ['list_id'],
components: { Toot },
computed: {
...mapState({
openSideBar: state => state.TimelineSpace.Contents.SideBar.openSideBar,
backgroundColor: state => state.App.theme.background_color,
startReload: state => state.TimelineSpace.HeaderMenu.reload,
timeline: state => state.TimelineSpace.Contents.Lists.Show.timeline,
lazyLoading: state => state.TimelineSpace.Contents.Lists.Show.lazyLoading,
heading: state => state.TimelineSpace.Contents.Lists.Show.heading,
scrolling: state => state.TimelineSpace.Contents.Lists.Show.scrolling
}),
...mapGetters('TimelineSpace/Modals', ['modalOpened']),
shortcutEnabled: function () {
if (this.modalOpened) {
return false
setup(props) {
const space = 'TimelineSpace/Contents/Lists/Show'
const store = useStore()
const i18n = useI18next()
const { list_id } = toRefs(props)
const focusedId = ref<string | null>(null)
const scrollPosition = ref<ScrollPosition | null>(null)
const observer = ref<ResizeObserver | null>(null)
const scrollTime = ref<moment.Moment | null>(null)
const resizeTime = ref<moment.Moment | null>(null)
const scroller = ref<any>(null)
const timeline = computed(() => store.state.TimelineSpace.Contents.Lists.Show.timeline)
const lazyLoading = computed(() => store.state.TimelineSpace.Contents.Lists.Show.lazyLoading)
const heading = computed(() => store.state.TimelineSpace.Contents.Lists.Show.heading)
const scrolling = computed(() => store.state.TimelineSpace.Contents.Lists.Show.scrolling)
const openSideBar = computed(() => store.state.TimelineSpace.Contents.SideBar.openSideBar)
const startReload = computed(() => store.state.TimelineSpace.HeaderMenu.reload)
const modalOpened = computed(() => store.getters[`TimelineSpace/Modals/modalOpened`])
const currentFocusedIndex = computed(() => timeline.value.findIndex(toot => focusedId.value === toot.uri + toot.id))
onMounted(() => {
document.getElementById('scroller')?.addEventListener('scroll', onScroll)
store.commit(`TimelineSpace/Contents/${CONTENTS_MUTATION.CHANGE_LOADING}`, true)
load().finally(() => {
store.commit(`TimelineSpace/Contents/${CONTENTS_MUTATION.CHANGE_LOADING}`, false)
})
const el = document.getElementById('scroller')
if (el) {
scrollPosition.value = new ScrollPosition(el)
scrollPosition.value.prepare()
observer.value = new ResizeObserver(() => {
if (scrollPosition.value && !heading.value && !lazyLoading.value && !scrolling.value) {
resizeTime.value = moment()
scrollPosition.value?.restore()
}
})
const scrollWrapper = el.getElementsByClassName('vue-recycle-scroller__item-wrapper')[0]
observer.value?.observe(scrollWrapper)
}
if (!this.focusedId) {
return true
}
// Sometimes toots are deleted, so perhaps focused toot don't exist.
const currentIndex = this.timeline.findIndex(toot => this.focusedId === toot.uri + toot.id)
return currentIndex === -1
}
},
created() {
this.$store.commit('TimelineSpace/Contents/changeLoading', true)
this.load().finally(() => {
this.$store.commit('TimelineSpace/Contents/changeLoading', false)
})
},
mounted() {
document.getElementById('scroller').addEventListener('scroll', this.onScroll)
EventEmitter.on('focus-timeline', () => {
// If focusedId does not change, we have to refresh focusedId because Toot component watch change events.
const previousFocusedId = this.focusedId
this.focusedId = 0
this.$nextTick(function () {
this.focusedId = previousFocusedId
onBeforeUpdate(() => {
if (scrollPosition.value) {
scrollPosition.value.prepare()
}
})
watch(list_id, () => {
store.commit(`TimelineSpace/Contents/${CONTENTS_MUTATION.CHANGE_LOADING}`, true)
load().finally(() => {
store.commit(`TimelineSpace/Contents/${CONTENTS_MUTATION.CHANGE_LOADING}`, false)
})
})
const el = document.getElementById('scroller')
this.scrollPosition = new ScrollPosition(el)
this.scrollPosition.prepare()
this.observer = new ResizeObserver(() => {
if (this.scrollPosition && !this.heading && !this.lazyLoading && !this.scrolling) {
this.resizeTime = moment()
this.scrollPosition.restore()
}
})
const scrollWrapper = el.getElementsByClassName('vue-recycle-scroller__item-wrapper')[0]
this.observer.observe(scrollWrapper)
},
beforeUpdate() {
if (this.scrollPosition) {
this.scrollPosition.prepare()
}
},
watch: {
list_id: function () {
this.$store.commit('TimelineSpace/Contents/changeLoading', true)
this.load().finally(() => {
this.$store.commit('TimelineSpace/Contents/changeLoading', false)
})
},
startReload: function (newState, oldState) {
if (!oldState && newState) {
this.reload().finally(() => {
this.$store.commit('TimelineSpace/HeaderMenu/changeReload', false)
watch(startReload, (newVal, oldVal) => {
if (!oldVal && newVal) {
reload().finally(() => {
store.commit(`TimelineSpace/HeaderMenu/${HEADER_MUTATION.CHANGE_RELOAD}`, false)
})
}
},
focusedId: function (newState, _oldState) {
if (newState && this.heading) {
this.$store.commit('TimelineSpace/Contents/Lists/Show/changeHeading', false)
} else if (newState === null && !this.heading) {
this.$store.commit('TimelineSpace/Contents/Lists/Show/changeHeading', true)
})
onBeforeUnmount(() => {
store.dispatch(`${space}/${ACTION_TYPES.STOP_STREAMING}`)
observer.value?.disconnect()
})
onUnmounted(() => {
store.commit(`${space}/${MUTATION_TYPES.CHANGE_HEADING}`, true)
store.commit(`${space}/${MUTATION_TYPES.ARCHIVE_TIMELINE}`)
store.commit(`${space}/${MUTATION_TYPES.CLEAR_TIMELINE}`)
const el = document.getElementById('scroller')
if (el !== undefined && el !== null) {
el.removeEventListener('scroll', onScroll)
el.scrollTop = 0
}
}
},
beforeUnmount() {
this.$store.dispatch('TimelineSpace/Contents/Lists/Show/stopStreaming')
this.observer.disconnect()
},
unmounted() {
this.$store.commit('TimelineSpace/Contents/Lists/Show/changeHeading', true)
this.$store.commit('TimelineSpace/Contents/Lists/Show/archiveTimeline')
this.$store.commit('TimelineSpace/Contents/Lists/Show/clearTimeline')
if (document.getElementById('scroller') !== undefined && document.getElementById('scroller') !== null) {
document.getElementById('scroller').removeEventListener('scroll', this.onScroll)
document.getElementById('scroller').scrollTop = 0
}
},
methods: {
async load() {
await this.$store.dispatch('TimelineSpace/Contents/Lists/Show/stopStreaming')
})
const load = async () => {
await store.dispatch(`${space}/${ACTION_TYPES.STOP_STREAMING}`)
try {
await this.$store.dispatch('TimelineSpace/Contents/Lists/Show/fetchTimeline', this.list_id)
await store.dispatch(`${space}/${ACTION_TYPES.FETCH_TIMELINE}`, list_id.value)
} catch (err) {
this.$message({
message: this.$t('message.timeline_fetch_error'),
ElMessage({
message: i18n.t('message.timeline_fetch_error'),
type: 'error'
})
}
this.$store.dispatch('TimelineSpace/Contents/Lists/Show/startStreaming', this.list_id).catch(() => {
this.$message({
message: this.$t('message.start_streaming_error'),
store.dispatch(`${space}/${ACTION_TYPES.START_STREAMING}`, list_id.value).catch(() => {
ElMessage({
message: i18n.t('message.start_streaming_error'),
type: 'error'
})
})
return 'started'
},
updateToot(message) {
this.$store.commit('TimelineSpace/Contents/Lists/Show/updateToot', message)
},
deleteToot(message) {
this.$store.commit('TimelineSpace/Contents/Lists/Show/deleteToot', message.id)
},
onScroll(event) {
if (moment().diff(this.resizeTime) < 500) {
}
const onScroll = (event: Event) => {
if (moment().diff(resizeTime.value) < 500) {
return
}
this.scrollTime = moment()
if (!this.scrolling) {
this.$store.commit('TimelineSpace/Contents/Lists/Show/changeScrolling', true)
scrollTime.value = moment()
if (!scrolling.value) {
store.commit(`${space}/${MUTATION_TYPES.CHANGE_SCROLLING}`, true)
}
if (
event.target.clientHeight + event.target.scrollTop >= document.getElementById('scroller').scrollHeight - 10 &&
!this.lazyloading
(event.target as HTMLElement)!.clientHeight + (event.target as HTMLElement)!.scrollTop >=
document.getElementById('scroller')!.scrollHeight - 10 &&
!lazyLoading
) {
this.$store
.dispatch('TimelineSpace/Contents/Lists/Show/lazyFetchTimeline', {
list_id: this.list_id,
status: this.timeline[this.timeline.length - 1]
store
.dispatch(`${space}/${ACTION_TYPES.LAZY_FETCH_TIMELINE}`, {
list_id: list_id.value,
status: timeline.value[timeline.value.length - 1]
})
.then(statuses => {
if (statuses === null) {
return
}
if (statuses.length > 0) {
this.$store.commit('TimelineSpace/Contents/Lists/Show/changeScrolling', true)
store.commit(`${space}/${MUTATION_TYPES.CHANGE_SCROLLING}`, true)
setTimeout(() => {
this.$store.commit('TimelineSpace/Contents/Lists/Show/changeScrolling', false)
store.commit(`${space}/${MUTATION_TYPES.CHANGE_SCROLLING}`, false)
}, 500)
}
})
.catch(() => {
this.$message({
message: this.$t('message.timeline_fetch_error'),
ElMessage({
message: i18n.t('message.timeline_fetch_error'),
type: 'error'
})
})
}
if (event.target.scrollTop > 10 && this.heading) {
this.$store.commit('TimelineSpace/Contents/Lists/Show/changeHeading', false)
} else if (event.target.scrollTop <= 10 && !this.heading) {
this.$store.commit('TimelineSpace/Contents/Lists/Show/changeHeading', true)
if ((event.target as HTMLElement)!.scrollTop > 10 && heading.value) {
store.commit(`${space}/${MUTATION_TYPES.CHANGE_HEADING}`, false)
} else if ((event.target as HTMLElement)!.scrollTop <= 10 && !heading.value) {
store.commit(`${space}/${MUTATION_TYPES.CHANGE_HEADING}`, true)
}
setTimeout(() => {
const now = moment()
if (now.diff(this.scrollTime) >= 150) {
this.scrollTime = null
this.$store.commit('TimelineSpace/Contents/Lists/Show/changeScrolling', false)
if (now.diff(scrollTime.value) >= 150) {
scrollTime.value = null
store.commit(`${space}/${MUTATION_TYPES.CHANGE_SCROLLING}`, false)
}
}, 150)
},
async reload() {
this.$store.commit('TimelineSpace/changeLoading', true)
}
const reload = async () => {
store.commit(`TimelineSpace/${TIMELINE_MUTATION.CHANGE_LOADING}`, true)
try {
await this.$store.dispatch('TimelineSpace/Contents/Lists/Show/stopStreaming')
await this.$store.dispatch('TimelineSpace/Contents/Lists/Show/fetchTimeline', this.list_id).catch(() => {
this.$message({
message: this.$t('message.timeline_fetch_error'),
await store.dispatch(`${space}/${ACTION_TYPES.STOP_STREAMING}`)
await store.dispatch(`${space}/${ACTION_TYPES.FETCH_TIMELINE}`, list_id.value).catch(() => {
ElMessage({
message: i18n.t('message.timeline_fetch_error'),
type: 'error'
})
})
this.$store.dispatch('TimelineSpace/Contents/Lists/Show/startStreaming', this.list_id).catch(() => {
this.$message({
message: this.$t('message.start_streaming_error'),
store.dispatch(`${space}/${ACTION_TYPES.START_STREAMING}`, list_id.value).catch(() => {
ElMessage({
message: i18n.t('message.start_streaming_error'),
type: 'error'
})
})
} finally {
this.$store.commit('TimelineSpace/changeLoading', false)
store.commit(`TimelineSpace/${TIMELINE_MUTATION.CHANGE_LOADING}`, false)
}
},
upper() {
this.$refs.scroller.scrollToItem(0)
this.focusedId = null
},
focusNext() {
const currentIndex = this.timeline.findIndex(toot => this.focusedId === toot.uri + toot.id)
if (currentIndex === -1) {
this.focusedId = this.timeline[0].uri + this.timeline[0].id
} else if (currentIndex < this.timeline.length) {
this.focusedId = this.timeline[currentIndex + 1].uri + this.timeline[currentIndex + 1].id
}
const updateToot = (message: Entity.Status) => {
store.commit(`${space}/${MUTATION_TYPES.UPDATE_TOOT}`, message)
}
const deleteToot = (message: Entity.Status) => {
store.commit(`${space}/${MUTATION_TYPES.DELETE_TOOT}`, message.id)
}
const upper = () => {
scroller.value.scrollToItem(0)
focusedId.value = null
}
const focusNext = () => {
if (currentFocusedIndex.value === -1) {
focusedId.value = timeline.value[0].uri + timeline.value[0].id
} else if (currentFocusedIndex.value < timeline.value.length) {
focusedId.value = timeline.value[currentFocusedIndex.value + 1].uri + timeline.value[currentFocusedIndex.value + 1].id
}
},
focusPrev() {
const currentIndex = this.timeline.findIndex(toot => this.focusedId === toot.uri + toot.id)
if (currentIndex === 0) {
this.focusedId = null
} else if (currentIndex > 0) {
this.focusedId = this.timeline[currentIndex - 1].uri + this.timeline[currentIndex - 1].id
}
const focusPrev = () => {
if (currentFocusedIndex.value === 0) {
focusedId.value = null
} else if (currentFocusedIndex.value > 0) {
focusedId.value = timeline.value[currentFocusedIndex.value - 1].uri + timeline.value[currentFocusedIndex.value - 1].id
}
},
focusToot(message) {
this.focusedId = message.uri + message.id
},
focusSidebar() {
}
const focusToot = (message: Entity.Status) => {
focusedId.value = message.uri + message.id
}
const focusSidebar = () => {
EventEmitter.emit('focus-sidebar')
},
handleKey(event) {
switch (event.srcKey) {
case 'next':
this.focusedId = this.timeline[0].uri + this.timeline[0].id
break
}
},
sizeChanged() {
this.$store.commit('TimelineSpace/Contents/Lists/Show/changeScrolling', true)
}
const sizeChanged = () => {
store.commit(`${space}/${MUTATION_TYPES.CHANGE_SCROLLING}`, true)
setTimeout(() => {
this.$store.commit('TimelineSpace/Contents/Lists/Show/changeScrolling', false)
store.commit(`${space}/${MUTATION_TYPES.CHANGE_SCROLLING}`, false)
}, 500)
}
return {
scroller,
timeline,
focusedId,
modalOpened,
updateToot,
deleteToot,
focusNext,
focusPrev,
focusSidebar,
focusToot,
sizeChanged,
openSideBar,
heading,
upper
}
}
}
})
</script>
<style lang="scss" scoped>

View File

@ -20,8 +20,14 @@ const mutations: MutationTree<IndexState> = {
}
}
export const ACTION_TYPES = {
FETCH_LISTS: 'fetchLists',
CREATE_LIST: 'createList',
DELETE_LIST: 'deleteList'
}
const actions: ActionTree<IndexState, RootState> = {
fetchLists: async ({ commit, rootState }): Promise<Array<Entity.List>> => {
[ACTION_TYPES.FETCH_LISTS]: async ({ commit, rootState }): Promise<Array<Entity.List>> => {
const client = generator(
rootState.TimelineSpace.sns,
rootState.TimelineSpace.account.baseURL,
@ -32,7 +38,7 @@ const actions: ActionTree<IndexState, RootState> = {
commit(MUTATION_TYPES.CHANGE_LISTS, res.data)
return res.data
},
createList: async ({ rootState }, title: string): Promise<Entity.List> => {
[ACTION_TYPES.CREATE_LIST]: async ({ rootState }, title: string): Promise<Entity.List> => {
const client = generator(
rootState.TimelineSpace.sns,
rootState.TimelineSpace.account.baseURL,
@ -42,7 +48,7 @@ const actions: ActionTree<IndexState, RootState> = {
const res = await client.createList(title)
return res.data
},
deleteList: async ({ dispatch, rootState }, list: Entity.List) => {
[ACTION_TYPES.DELETE_LIST]: async ({ dispatch, rootState }, list: Entity.List) => {
const client = generator(
rootState.TimelineSpace.sns,
rootState.TimelineSpace.account.baseURL,
@ -50,7 +56,7 @@ const actions: ActionTree<IndexState, RootState> = {
rootState.App.userAgent
)
const res = await client.deleteList(list.id)
dispatch('fetchLists')
dispatch(ACTION_TYPES.FETCH_LISTS)
return res.data
}
}

View File

@ -88,8 +88,15 @@ const mutations: MutationTree<ShowState> = {
}
}
export const ACTION_TYPES = {
FETCH_TIMELINE: 'fetchTimeline',
START_STREAMING: 'startStreaming',
STOP_STREAMING: 'stopStreaming',
LAZY_FETCH_TIMELINE: 'lazyFetchTimeline'
}
const actions: ActionTree<ShowState, RootState> = {
fetchTimeline: async ({ commit, rootState }, listID: string): Promise<Array<Entity.Status>> => {
[ACTION_TYPES.FETCH_TIMELINE]: async ({ commit, rootState }, listID: string): Promise<Array<Entity.Status>> => {
const client = generator(
rootState.TimelineSpace.sns,
rootState.TimelineSpace.account.baseURL,
@ -100,7 +107,7 @@ const actions: ActionTree<ShowState, RootState> = {
commit(MUTATION_TYPES.UPDATE_TIMELINE, res.data)
return res.data
},
startStreaming: ({ state, commit, rootState }, listID: string) => {
[ACTION_TYPES.START_STREAMING]: ({ state, commit, rootState }, listID: string) => {
win.ipcRenderer.on('update-start-list-streaming', (_, update: Entity.Status) => {
commit(MUTATION_TYPES.APPEND_TIMELINE, update)
if (state.heading && Math.random() > 0.8) {
@ -122,7 +129,7 @@ const actions: ActionTree<ShowState, RootState> = {
})
})
},
stopStreaming: () => {
[ACTION_TYPES.STOP_STREAMING]: () => {
return new Promise(resolve => {
win.ipcRenderer.removeAllListeners('error-start-list-streaming')
win.ipcRenderer.removeAllListeners('update-start-list-streaming')
@ -131,7 +138,10 @@ const actions: ActionTree<ShowState, RootState> = {
resolve(null)
})
},
lazyFetchTimeline: async ({ state, commit, rootState }, loadPosition: LoadPositionWithList): Promise<Array<Entity.Status> | null> => {
[ACTION_TYPES.LAZY_FETCH_TIMELINE]: async (
{ state, commit, rootState },
loadPosition: LoadPositionWithList
): Promise<Array<Entity.Status> | null> => {
if (state.lazyLoading) {
return Promise.resolve(null)
}