refs #3301 Rewrite TimelineSpace/Contents/Mentions with composition API
This commit is contained in:
parent
a285f7009e
commit
ade7d4e25e
|
@ -82,7 +82,7 @@ export default defineComponent({
|
||||||
const openSideBar = computed(() => store.state.TimelineSpace.Contents.SideBar.openSideBar)
|
const openSideBar = computed(() => store.state.TimelineSpace.Contents.SideBar.openSideBar)
|
||||||
const startReload = computed(() => store.state.TimelineSpace.HeaderMenu.reload)
|
const startReload = computed(() => store.state.TimelineSpace.HeaderMenu.reload)
|
||||||
const modalOpened = computed(() => store.getters[`TimelineSpace/Modals/modalOpened`])
|
const modalOpened = computed(() => store.getters[`TimelineSpace/Modals/modalOpened`])
|
||||||
const filters = computed(() => store.getters[`${space}/filters}`])
|
const filters = computed(() => store.getters[`${space}/filters`])
|
||||||
const currentFocusedIndex = computed(() => timeline.value.findIndex(toot => focusedId.value === toot.uri + toot.id))
|
const currentFocusedIndex = computed(() => timeline.value.findIndex(toot => focusedId.value === toot.uri + toot.id))
|
||||||
// const shortcutEnabled = computed(() => {
|
// const shortcutEnabled = computed(() => {
|
||||||
// if (modalOpened.value) {
|
// if (modalOpened.value) {
|
||||||
|
@ -158,6 +158,15 @@ export default defineComponent({
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
watch(
|
||||||
|
timeline,
|
||||||
|
(newState, _oldState) => {
|
||||||
|
if (heading.value && newState.length > 0) {
|
||||||
|
store.dispatch(`${space}/${ACTION_TYPES.SAVE_MARKER}`)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ deep: true }
|
||||||
|
)
|
||||||
|
|
||||||
const onScroll = (event: Event) => {
|
const onScroll = (event: Event) => {
|
||||||
if (moment().diff(resizeTime.value) < 500) {
|
if (moment().diff(resizeTime.value) < 500) {
|
||||||
|
|
|
@ -35,239 +35,239 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script lang="ts">
|
||||||
import { mapState, mapGetters } from 'vuex'
|
import { computed, defineComponent, onBeforeUnmount, onBeforeUpdate, onMounted, onUnmounted, ref, watch } from 'vue'
|
||||||
import moment from 'moment'
|
import moment from 'moment'
|
||||||
import Notification from '~/src/renderer/components/organisms/Notification'
|
import { useI18next } from 'vue3-i18next'
|
||||||
import StatusLoading from '~/src/renderer/components/organisms/StatusLoading'
|
import { useRoute } from 'vue-router'
|
||||||
import { EventEmitter } from '~/src/renderer/components/event'
|
import { Entity } from 'megalodon'
|
||||||
import { ScrollPosition } from '~/src/renderer/components/utils/scroll'
|
import { ElMessage } from 'element-plus'
|
||||||
|
import { useStore } from '@/store'
|
||||||
|
import Notification from '@/components/organisms/Notification.vue'
|
||||||
|
import StatusLoading from '@/components/organisms/StatusLoading.vue'
|
||||||
|
import { EventEmitter } from '@/components/event'
|
||||||
|
import { ScrollPosition } from '@/components/utils/scroll'
|
||||||
|
import useReloadable from '@/components/utils/reloadable'
|
||||||
|
import { LoadingCard } from '@/types/loading-card'
|
||||||
|
import { ACTION_TYPES, MUTATION_TYPES } from '@/store/TimelineSpace/Contents/Mentions'
|
||||||
|
import { MUTATION_TYPES as SIDE_MENU_MUTATION } from '@/store/TimelineSpace/SideMenu'
|
||||||
|
import { MUTATION_TYPES as TIMELINE_MUTATION } from '@/store/TimelineSpace'
|
||||||
|
import { MUTATION_TYPES as HEADER_MUTATION } from '@/store/TimelineSpace/HeaderMenu'
|
||||||
|
|
||||||
export default {
|
export default defineComponent({
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
focusedId: null,
|
|
||||||
scrollPosition: null,
|
|
||||||
observer: null,
|
|
||||||
scrollTime: null,
|
|
||||||
resizeTime: null,
|
|
||||||
loadingMore: false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
name: 'mentions',
|
name: 'mentions',
|
||||||
components: { Notification, StatusLoading },
|
components: { Notification, StatusLoading },
|
||||||
computed: {
|
setup() {
|
||||||
...mapState('App', {
|
const space = 'TimelineSpace/Contents/Mentions'
|
||||||
backgroundColor: state => state.theme.background_color
|
const store = useStore()
|
||||||
}),
|
const route = useRoute()
|
||||||
...mapState('TimelineSpace/HeaderMenu', {
|
const i18n = useI18next()
|
||||||
startReload: state => state.reload
|
const { reloadable } = useReloadable(store, route, i18n)
|
||||||
}),
|
|
||||||
...mapState('TimelineSpace/Contents/SideBar', {
|
|
||||||
openSideBar: state => state.openSideBar
|
|
||||||
}),
|
|
||||||
...mapState('TimelineSpace/Contents/Mentions', {
|
|
||||||
lazyLoading: state => state.lazyLoading,
|
|
||||||
heading: state => state.heading,
|
|
||||||
scrolling: state => state.scrolling
|
|
||||||
}),
|
|
||||||
...mapGetters('TimelineSpace/Modals', ['modalOpened']),
|
|
||||||
...mapGetters('TimelineSpace/Contents/Mentions', ['mentions']),
|
|
||||||
shortcutEnabled: function () {
|
|
||||||
if (this.modalOpened) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if (!this.focusedId) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
// Sometimes toots are deleted, so perhaps focused toot don't exist.
|
|
||||||
const currentIndex = this.mentions.findIndex(toot => this.focusedId === toot.id)
|
|
||||||
return currentIndex === -1
|
|
||||||
}
|
|
||||||
},
|
|
||||||
mounted() {
|
|
||||||
this.$store.commit('TimelineSpace/SideMenu/changeUnreadMentions', false)
|
|
||||||
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
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
if (this.heading && this.mentions.length > 0) {
|
const focusedId = ref<string | null>(null)
|
||||||
this.$store.dispatch('TimelineSpace/Contents/Mentions/saveMarker')
|
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 loadingMore = ref(false)
|
||||||
|
const scroller = ref<any>()
|
||||||
|
|
||||||
|
const mentions = computed<Array<Entity.Notification | LoadingCard>>(() => store.getters[`${space}/mentions`])
|
||||||
|
const lazyLoading = computed(() => store.state.TimelineSpace.Contents.Mentions.lazyLoading)
|
||||||
|
const heading = computed(() => store.state.TimelineSpace.Contents.Mentions.heading)
|
||||||
|
const scrolling = computed(() => store.state.TimelineSpace.Contents.Mentions.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(() => mentions.value.findIndex(notification => focusedId.value === notification.id))
|
||||||
|
// const shortcutEnabled = computed(() => {
|
||||||
|
// if (modalOpened.value) {
|
||||||
|
// return false
|
||||||
|
// }
|
||||||
|
// if (!focusedId.value) {
|
||||||
|
// return true
|
||||||
|
// }
|
||||||
|
// // Sometimes toots are deleted, so perhaps focused toot don't exist.
|
||||||
|
// return currentFocusedIndex.value === -1
|
||||||
|
// })
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
store.commit(`TimelineSpace/SideMenu/${SIDE_MENU_MUTATION.CHANGE_UNREAD_HOME_TIMELINE}`, false)
|
||||||
|
document.getElementById('scroller')?.addEventListener('scroll', onScroll)
|
||||||
|
|
||||||
|
if (heading.value && mentions.value.length > 0) {
|
||||||
|
store.dispatch(`${space}/${ACTION_TYPES.SAVE_MARKER}`)
|
||||||
}
|
}
|
||||||
const el = document.getElementById('scroller')
|
const el = document.getElementById('scroller')
|
||||||
this.scrollPosition = new ScrollPosition(el)
|
if (el) {
|
||||||
this.scrollPosition.prepare()
|
scrollPosition.value = new ScrollPosition(el)
|
||||||
|
scrollPosition.value.prepare()
|
||||||
this.observer = new ResizeObserver(() => {
|
observer.value = new ResizeObserver(() => {
|
||||||
if (this.loadingMore || (this.scrollPosition && !this.heading && !this.lazyLoading && !this.scrolling)) {
|
if (loadingMore.value || (scrollPosition.value && !heading.value && !lazyLoading.value && !scrolling.value)) {
|
||||||
this.resizeTime = moment()
|
resizeTime.value = moment()
|
||||||
this.scrollPosition.restore()
|
scrollPosition.value?.restore()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const scrollWrapper = el.getElementsByClassName('vue-recycle-scroller__item-wrapper')[0]
|
const scrollWrapper = el.getElementsByClassName('vue-recycle-scroller__item-wrapper')[0]
|
||||||
this.observer.observe(scrollWrapper)
|
observer.value.observe(scrollWrapper)
|
||||||
},
|
|
||||||
beforeUpdate() {
|
|
||||||
if (this.$store.state.TimelineSpace.SideMenu.unreadMentions && this.heading) {
|
|
||||||
this.$store.commit('TimelineSpace/SideMenu/changeUnreadMentions', false)
|
|
||||||
}
|
}
|
||||||
if (this.scrollPosition) {
|
})
|
||||||
this.scrollPosition.prepare()
|
onBeforeUpdate(() => {
|
||||||
|
if (store.state.TimelineSpace.SideMenu.unreadMentions && heading.value) {
|
||||||
|
store.commit(`TimelineSpace/SideMenu/${SIDE_MENU_MUTATION.CHANGE_UNREAD_MENTIONS}`, false)
|
||||||
}
|
}
|
||||||
},
|
if (scrollPosition.value) {
|
||||||
beforeUnmount() {
|
scrollPosition.value.prepare()
|
||||||
EventEmitter.off('focus-timeline')
|
|
||||||
this.observer.disconnect()
|
|
||||||
},
|
|
||||||
unounted() {
|
|
||||||
this.$store.commit('TimelineSpace/Contents/Mentions/changeHeading', true)
|
|
||||||
this.$store.commit('TimelineSpace/Contents/Mentions/archiveMentions')
|
|
||||||
if (document.getElementById('scroller') !== undefined && document.getElementById('scroller') !== null) {
|
|
||||||
document.getElementById('scroller').removeEventListener('scroll', this.onScroll)
|
|
||||||
document.getElementById('scroller').scrollTop = 0
|
|
||||||
}
|
}
|
||||||
},
|
})
|
||||||
watch: {
|
onBeforeUnmount(() => {
|
||||||
startReload: function (newState, oldState) {
|
observer.value?.disconnect()
|
||||||
if (!oldState && newState) {
|
})
|
||||||
this.reload().finally(() => {
|
onUnmounted(() => {
|
||||||
this.$store.commit('TimelineSpace/HeaderMenu/changeReload', false)
|
store.commit(`${space}/${MUTATION_TYPES.CHANGE_HEADING}`, true)
|
||||||
|
store.commit(`${space}/${MUTATION_TYPES.ARCHIVE_MENTIONS}`)
|
||||||
|
const el = document.getElementById('scroller')
|
||||||
|
if (el !== undefined && el !== null) {
|
||||||
|
el.removeEventListener('scroll', onScroll)
|
||||||
|
el.scrollTop = 0
|
||||||
|
}
|
||||||
|
})
|
||||||
|
watch(startReload, (newVal, oldVal) => {
|
||||||
|
if (!oldVal && newVal) {
|
||||||
|
reload().finally(() => {
|
||||||
|
store.commit(`TimelineSpace/HeaderMenu/${HEADER_MUTATION.CHANGE_RELOAD}`, false)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
})
|
||||||
focusedId: function (newState, _oldState) {
|
watch(
|
||||||
if (newState && this.heading) {
|
mentions,
|
||||||
this.$store.commit('TimelineSpace/Contents/Mentions/changeHeading', false)
|
(newVal, _oldVal) => {
|
||||||
} else if (newState === null && !this.heading) {
|
if (heading.value && newVal.length > 0) {
|
||||||
this.$store.commit('TimelineSpace/Contents/Mentions/changeHeading', true)
|
store.dispatch(`${space}/${ACTION_TYPES.SAVE_MARKER}`)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mentions: {
|
{ deep: true }
|
||||||
handler(newState, _oldState) {
|
)
|
||||||
if (this.heading && newState.length > 0) {
|
|
||||||
this.$store.dispatch('TimelineSpace/Contents/Mentions/saveMarker')
|
const onScroll = (event: Event) => {
|
||||||
}
|
if (moment().diff(resizeTime.value) < 500) {
|
||||||
},
|
|
||||||
deep: true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
onScroll(event) {
|
|
||||||
if (moment().diff(this.resizeTime) < 500) {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.scrollTime = moment()
|
scrollTime.value = moment()
|
||||||
if (!this.scrolling) {
|
if (!scrolling.value) {
|
||||||
this.$store.commit('TimelineSpace/Contents/Mentions/changeScrolling', true)
|
store.commit(`${space}/${MUTATION_TYPES.CHANGE_SCROLLING}`, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// for lazyLoading
|
// for lazyLoading
|
||||||
if (
|
if (
|
||||||
event.target.clientHeight + event.target.scrollTop >= document.getElementById('scroller').scrollHeight - 10 &&
|
(event.target as HTMLElement)!.clientHeight + (event.target as HTMLElement)!.scrollTop >=
|
||||||
!this.lazyloading
|
document.getElementById('scroller')!.scrollHeight - 10 &&
|
||||||
|
!lazyLoading.value
|
||||||
) {
|
) {
|
||||||
this.$store
|
store
|
||||||
.dispatch('TimelineSpace/Contents/Mentions/lazyFetchMentions', this.mentions[this.mentions.length - 1])
|
.dispatch(`${space}/${ACTION_TYPES.LAZY_FETCH_MENTIONS}`, mentions.value[mentions.value.length - 1])
|
||||||
.then(statuses => {
|
.then(statuses => {
|
||||||
if (statuses === null) {
|
if (statuses === null) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (statuses.length > 0) {
|
if (statuses.length > 0) {
|
||||||
this.$store.commit('TimelineSpace/Contents/Mentions/changeScrolling', true)
|
store.commit(`${space}/${MUTATION_TYPES.CHANGE_SCROLLING}`, true)
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.$store.commit('TimelineSpace/Contents/Mentions/changeScrolling', false)
|
store.commit(`${space}/${MUTATION_TYPES.CHANGE_SCROLLING}`, false)
|
||||||
}, 500)
|
}, 500)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
this.$message({
|
ElMessage({
|
||||||
message: this.$t('message.timeline_fetch_error'),
|
message: i18n.t('message.timeline_fetch_error'),
|
||||||
type: 'error'
|
type: 'error'
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.target.scrollTop > 10 && this.heading) {
|
if ((event.target as HTMLElement)!.scrollTop > 10 && heading.value) {
|
||||||
this.$store.commit('TimelineSpace/Contents/Mentions/changeHeading', false)
|
store.commit(`${space}/${MUTATION_TYPES.CHANGE_HEADING}`, false)
|
||||||
} else if (event.target.scrollTop <= 10 && !this.heading) {
|
} else if ((event.target as HTMLElement)!.scrollTop <= 10 && !heading.value) {
|
||||||
this.$store.commit('TimelineSpace/Contents/Mentions/changeHeading', true)
|
store.commit(`${space}/${MUTATION_TYPES.CHANGE_HEADING}`, true)
|
||||||
this.$store.dispatch('TimelineSpace/Contents/Mentions/saveMarker')
|
store.dispatch(`${space}/${ACTION_TYPES.SAVE_MARKER}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const now = moment()
|
const now = moment()
|
||||||
if (now.diff(this.scrollTime) >= 150) {
|
if (now.diff(scrollTime.value) >= 150) {
|
||||||
this.scrollTime = null
|
scrollTime.value = null
|
||||||
this.$store.commit('TimelineSpace/Contents/Mentions/changeScrolling', false)
|
store.commit(`${space}/${MUTATION_TYPES.CHANGE_SCROLLING}`, false)
|
||||||
}
|
}
|
||||||
}, 150)
|
}, 150)
|
||||||
},
|
}
|
||||||
fetchMentionsSince(since_id) {
|
const updateToot = (message: Entity.Status) => {
|
||||||
this.loadingMore = true
|
store.commit(`${space}/${MUTATION_TYPES.UPDATE_TOOT}`, message)
|
||||||
this.$store.dispatch('TimelineSpace/Contents/Mentions/fetchMentionsSince', since_id).finally(() => {
|
}
|
||||||
|
const fetchMentionsSince = (since_id: string) => {
|
||||||
|
loadingMore.value = true
|
||||||
|
store.dispatch(`${space}/${ACTION_TYPES.FETCH_MENTIONS_SINCE}`, since_id).finally(() => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.loadingMore = false
|
loadingMore.value = false
|
||||||
}, 500)
|
}, 500)
|
||||||
})
|
})
|
||||||
},
|
}
|
||||||
async reload() {
|
const reload = async () => {
|
||||||
this.$store.commit('TimelineSpace/changeLoading', true)
|
store.commit(`TimelineSpace/${TIMELINE_MUTATION.CHANGE_LOADING}`, true)
|
||||||
try {
|
try {
|
||||||
|
reloadable()
|
||||||
} finally {
|
} finally {
|
||||||
this.$store.commit('TimelineSpace/changeLoading', false)
|
store.commit(`TimelineSpace/${TIMELINE_MUTATION.CHANGE_LOADING}`, false)
|
||||||
}
|
}
|
||||||
},
|
|
||||||
updateToot(message) {
|
|
||||||
this.$store.commit('TimelineSpace/Contents/Mentions/updateToot', message)
|
|
||||||
},
|
|
||||||
upper() {
|
|
||||||
this.$refs.scroller.scrollToItem(0)
|
|
||||||
this.focusedId = null
|
|
||||||
},
|
|
||||||
focusNext() {
|
|
||||||
const currentIndex = this.mentions.findIndex(toot => this.focusedId === toot.id)
|
|
||||||
if (currentIndex === -1) {
|
|
||||||
this.focusedId = this.mentions[0].id
|
|
||||||
} else if (currentIndex < this.mentions.length) {
|
|
||||||
this.focusedId = this.mentions[currentIndex + 1].id
|
|
||||||
}
|
}
|
||||||
},
|
const upper = () => {
|
||||||
focusPrev() {
|
scroller.value.scrollToItem(0)
|
||||||
const currentIndex = this.mentions.findIndex(toot => this.focusedId === toot.id)
|
focusedId.value = null
|
||||||
if (currentIndex === 0) {
|
|
||||||
this.focusedId = null
|
|
||||||
} else if (currentIndex > 0) {
|
|
||||||
this.focusedId = this.mentions[currentIndex - 1].id
|
|
||||||
}
|
}
|
||||||
},
|
const focusNext = () => {
|
||||||
focusNotification(message) {
|
if (currentFocusedIndex.value === -1) {
|
||||||
this.focusedId = message.id
|
focusedId.value = mentions.value[0].id
|
||||||
},
|
} else if (currentFocusedIndex.value < mentions.value.length) {
|
||||||
focusSidebar() {
|
focusedId.value = mentions.value[currentFocusedIndex.value + 1].id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const focusPrev = () => {
|
||||||
|
if (currentFocusedIndex.value === 0) {
|
||||||
|
focusedId.value = null
|
||||||
|
} else if (currentFocusedIndex.value > 0) {
|
||||||
|
focusedId.value = mentions.value[currentFocusedIndex.value - 1].id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const focusNotification = (message: Entity.Notification) => {
|
||||||
|
focusedId.value = message.id
|
||||||
|
}
|
||||||
|
const focusSidebar = () => {
|
||||||
EventEmitter.emit('focus-sidebar')
|
EventEmitter.emit('focus-sidebar')
|
||||||
},
|
|
||||||
handleKey(event) {
|
|
||||||
switch (event.srcKey) {
|
|
||||||
case 'next':
|
|
||||||
this.focusedId = this.mentions[0].id
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
},
|
const sizeChanged = () => {
|
||||||
sizeChanged() {
|
store.commit(`${space}/${MUTATION_TYPES.CHANGE_SCROLLING}`, true)
|
||||||
this.$store.commit('TimelineSpace/Contents/Mentions/changeScrolling', true)
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.$store.commit('TimelineSpace/Contents/Mentions/changeScrolling', false)
|
store.commit(`${space}/${MUTATION_TYPES.CHANGE_SCROLLING}`, false)
|
||||||
}, 500)
|
}, 500)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
mentions,
|
||||||
|
loadingMore,
|
||||||
|
fetchMentionsSince,
|
||||||
|
focusedId,
|
||||||
|
modalOpened,
|
||||||
|
updateToot,
|
||||||
|
focusNext,
|
||||||
|
focusPrev,
|
||||||
|
focusSidebar,
|
||||||
|
focusNotification,
|
||||||
|
sizeChanged,
|
||||||
|
openSideBar,
|
||||||
|
heading,
|
||||||
|
upper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|
|
@ -114,8 +114,16 @@ const mutations: MutationTree<MentionsState> = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const ACTION_TYPES = {
|
||||||
|
FETCH_MENTIONS: 'fetchMentions',
|
||||||
|
LAZY_FETCH_MENTIONS: 'lazyFetchMentions',
|
||||||
|
FETCH_MENTIONS_SINCE: 'fetchMentionsSince',
|
||||||
|
GET_MARKER: 'getMarker',
|
||||||
|
SAVE_MARKER: 'saveMarker'
|
||||||
|
}
|
||||||
|
|
||||||
const actions: ActionTree<MentionsState, RootState> = {
|
const actions: ActionTree<MentionsState, RootState> = {
|
||||||
fetchMentions: async ({ dispatch, commit, rootState }): Promise<Array<Entity.Notification>> => {
|
[ACTION_TYPES.FETCH_MENTIONS]: async ({ dispatch, commit, rootState }): Promise<Array<Entity.Notification>> => {
|
||||||
const client = generator(
|
const client = generator(
|
||||||
rootState.TimelineSpace.sns,
|
rootState.TimelineSpace.sns,
|
||||||
rootState.TimelineSpace.account.baseURL,
|
rootState.TimelineSpace.account.baseURL,
|
||||||
|
@ -157,7 +165,10 @@ const actions: ActionTree<MentionsState, RootState> = {
|
||||||
commit(MUTATION_TYPES.UPDATE_MENTIONS, res.data)
|
commit(MUTATION_TYPES.UPDATE_MENTIONS, res.data)
|
||||||
return res.data
|
return res.data
|
||||||
},
|
},
|
||||||
lazyFetchMentions: async ({ state, commit, rootState }, lastMention: Entity.Notification): Promise<Array<Entity.Notification> | null> => {
|
[ACTION_TYPES.LAZY_FETCH_MENTIONS]: async (
|
||||||
|
{ state, commit, rootState },
|
||||||
|
lastMention: Entity.Notification
|
||||||
|
): Promise<Array<Entity.Notification> | null> => {
|
||||||
if (state.lazyLoading) {
|
if (state.lazyLoading) {
|
||||||
return Promise.resolve(null)
|
return Promise.resolve(null)
|
||||||
}
|
}
|
||||||
|
@ -182,7 +193,10 @@ const actions: ActionTree<MentionsState, RootState> = {
|
||||||
commit(MUTATION_TYPES.CHANGE_LAZY_LOADING, false)
|
commit(MUTATION_TYPES.CHANGE_LAZY_LOADING, false)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
fetchMentionsSince: async ({ state, rootState, commit }, since_id: string): Promise<Array<Entity.Notification> | null> => {
|
[ACTION_TYPES.FETCH_MENTIONS_SINCE]: async (
|
||||||
|
{ state, rootState, commit },
|
||||||
|
since_id: string
|
||||||
|
): Promise<Array<Entity.Notification> | null> => {
|
||||||
const client = generator(
|
const client = generator(
|
||||||
rootState.TimelineSpace.sns,
|
rootState.TimelineSpace.sns,
|
||||||
rootState.TimelineSpace.account.baseURL,
|
rootState.TimelineSpace.account.baseURL,
|
||||||
|
@ -223,14 +237,14 @@ const actions: ActionTree<MentionsState, RootState> = {
|
||||||
}
|
}
|
||||||
return res.data
|
return res.data
|
||||||
},
|
},
|
||||||
getMarker: async ({ rootState }): Promise<LocalMarker | null> => {
|
[ACTION_TYPES.GET_MARKER]: async ({ rootState }): Promise<LocalMarker | null> => {
|
||||||
if (!rootState.TimelineSpace.timelineSetting.useMarker.mentions) {
|
if (!rootState.TimelineSpace.timelineSetting.useMarker.mentions) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
const localMarker: LocalMarker | null = await win.ipcRenderer.invoke('get-mentions-marker', rootState.TimelineSpace.account._id)
|
const localMarker: LocalMarker | null = await win.ipcRenderer.invoke('get-mentions-marker', rootState.TimelineSpace.account._id)
|
||||||
return localMarker
|
return localMarker
|
||||||
},
|
},
|
||||||
saveMarker: async ({ state, rootState }) => {
|
[ACTION_TYPES.SAVE_MARKER]: async ({ state, rootState }) => {
|
||||||
const mentions = state.mentions
|
const mentions = state.mentions
|
||||||
if (mentions.length === 0 || mentions[0].id === 'loading-card') {
|
if (mentions.length === 0 || mentions[0].id === 'loading-card') {
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue