refs #3301 Rewrite TimelineSpace/Contents/Hashtag with composition API
This commit is contained in:
parent
0e28d5c41e
commit
f6aa14d54e
|
@ -3,7 +3,7 @@
|
||||||
<div class="search-header" v-loading="false">
|
<div class="search-header" v-loading="false">
|
||||||
<el-form>
|
<el-form>
|
||||||
<div class="form-wrapper">
|
<div class="form-wrapper">
|
||||||
<div class="form-item" v-show="tagPage()">
|
<div class="form-item" v-show="tagPage">
|
||||||
<el-button type="text" @click="back">
|
<el-button type="text" @click="back">
|
||||||
<font-awesome-icon icon="chevron-left" />
|
<font-awesome-icon icon="chevron-left" />
|
||||||
</el-button>
|
</el-button>
|
||||||
|
@ -11,7 +11,7 @@
|
||||||
<div class="form-item input">
|
<div class="form-item input">
|
||||||
<input v-model="tag" :placeholder="$t('hashtag.tag_name')" class="search-keyword" v-on:keyup.enter="search" autofocus />
|
<input v-model="tag" :placeholder="$t('hashtag.tag_name')" class="search-keyword" v-on:keyup.enter="search" autofocus />
|
||||||
</div>
|
</div>
|
||||||
<div class="form-item" v-show="tagPage()">
|
<div class="form-item" v-show="tagPage">
|
||||||
<el-button type="text" @click="save" :title="$t('hashtag.save_tag')">
|
<el-button type="text" @click="save" :title="$t('hashtag.save_tag')">
|
||||||
<font-awesome-icon icon="thumbtack" />
|
<font-awesome-icon icon="thumbtack" />
|
||||||
</el-button>
|
</el-button>
|
||||||
|
@ -23,44 +23,55 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script lang="ts">
|
||||||
export default {
|
import { computed, defineComponent, onMounted, ref, watch } from 'vue'
|
||||||
|
import { useRoute, useRouter } from 'vue-router'
|
||||||
|
import { useStore } from '@/store'
|
||||||
|
|
||||||
|
export default defineComponent({
|
||||||
name: 'hashtag',
|
name: 'hashtag',
|
||||||
data() {
|
setup() {
|
||||||
return {
|
const route = useRoute()
|
||||||
tag: ''
|
const router = useRouter()
|
||||||
}
|
const store = useStore()
|
||||||
},
|
|
||||||
mounted() {
|
const tag = ref<string>('')
|
||||||
if (this.$route.name === 'tag') {
|
const id = computed(() => route.params.id)
|
||||||
this.tag = this.$route.params.tag
|
const tagPage = computed(() => route.name === 'tag')
|
||||||
}
|
|
||||||
},
|
onMounted(() => {
|
||||||
watch: {
|
|
||||||
$route: function (route) {
|
|
||||||
if (route.name === 'tag') {
|
if (route.name === 'tag') {
|
||||||
this.tag = route.params.tag
|
tag.value = route.params.tag as string
|
||||||
|
}
|
||||||
|
})
|
||||||
|
watch(
|
||||||
|
() => route.params.tag,
|
||||||
|
() => {
|
||||||
|
if (route.name === 'tag') {
|
||||||
|
tag.value = route.params.tag as string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
)
|
||||||
methods: {
|
const search = () => {
|
||||||
id() {
|
router.push({ path: `/${id.value}/hashtag/${tag.value}` })
|
||||||
return this.$route.params.id
|
|
||||||
},
|
|
||||||
search() {
|
|
||||||
this.$router.push({ path: `/${this.id()}/hashtag/${this.tag}` })
|
|
||||||
},
|
|
||||||
tagPage() {
|
|
||||||
return this.$route.name === 'tag'
|
|
||||||
},
|
|
||||||
back() {
|
|
||||||
this.$router.push({ path: `/${this.id()}/hashtag` })
|
|
||||||
},
|
|
||||||
save() {
|
|
||||||
this.$store.dispatch('TimelineSpace/Contents/Hashtag/saveTag', this.tag)
|
|
||||||
}
|
}
|
||||||
|
const back = () => {
|
||||||
|
router.push({ path: `/${id.value}/hashtag` })
|
||||||
}
|
}
|
||||||
|
const save = () => {
|
||||||
|
store.dispatch('TimelineSpace/Contents/Hashtag/saveTag', tag.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
tagPage,
|
||||||
|
tag,
|
||||||
|
back,
|
||||||
|
search,
|
||||||
|
save
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {}
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|
|
@ -17,30 +17,41 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script lang="ts">
|
||||||
import { mapState } from 'vuex'
|
import { defineComponent, computed, onMounted } from 'vue'
|
||||||
|
import { useRouter, useRoute } from 'vue-router'
|
||||||
|
import { useStore } from '@/store'
|
||||||
|
import { ACTION_TYPES } from '@/store/TimelineSpace/Contents/Hashtag/List'
|
||||||
|
import { LocalTag } from '~/src/types/localTag'
|
||||||
|
|
||||||
export default {
|
export default defineComponent({
|
||||||
name: 'list',
|
name: 'list',
|
||||||
computed: {
|
setup() {
|
||||||
...mapState({
|
const space = 'TimelineSpace/Contents/Hashtag/List'
|
||||||
tags: state => state.TimelineSpace.Contents.Hashtag.List.tags
|
const store = useStore()
|
||||||
|
const route = useRoute()
|
||||||
|
const router = useRouter()
|
||||||
|
const tags = computed(() => store.state.TimelineSpace.Contents.Hashtag.List.tags)
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
store.dispatch(`${space}/${ACTION_TYPES.LIST_TAGS}`)
|
||||||
})
|
})
|
||||||
},
|
const openTimeline = (tagName: string) => {
|
||||||
created() {
|
router.push({
|
||||||
this.$store.dispatch('TimelineSpace/Contents/Hashtag/List/listTags')
|
path: `/${route.params.id}/hashtag/${tagName}`
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
openTimeline(tagName) {
|
|
||||||
this.$router.push({
|
|
||||||
path: `/${this.$route.params.id}/hashtag/${tagName}`
|
|
||||||
})
|
})
|
||||||
},
|
}
|
||||||
deleteTag(tag) {
|
const deleteTag = (tag: LocalTag) => {
|
||||||
this.$store.dispatch('TimelineSpace/Contents/Hashtag/List/removeTag', tag)
|
store.dispatch(`${space}/${ACTION_TYPES.REMOVE_TAG}`, tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
tags,
|
||||||
|
openTimeline,
|
||||||
|
deleteTag
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|
|
@ -29,256 +29,253 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script lang="ts">
|
||||||
import { mapState, mapGetters } from 'vuex'
|
import { computed, defineComponent, onBeforeUnmount, onBeforeUpdate, onMounted, ref, toRefs, watch } from 'vue'
|
||||||
import moment from 'moment'
|
import moment from 'moment'
|
||||||
import Toot from '~/src/renderer/components/organisms/Toot'
|
import { ElMessage } from 'element-plus'
|
||||||
import { EventEmitter } from '~/src/renderer/components/event'
|
import { Entity } from 'megalodon'
|
||||||
import { ScrollPosition } from '~/src/renderer/components/utils/scroll'
|
import { useI18next } from 'vue3-i18next'
|
||||||
|
import { useRoute } from 'vue-router'
|
||||||
|
import { useStore } from '@/store'
|
||||||
|
import Toot from '@/components/organisms/Toot.vue'
|
||||||
|
import { EventEmitter } from '@/components/event'
|
||||||
|
import { ScrollPosition } from '@/components/utils/scroll'
|
||||||
|
import useReloadable from '@/components/utils/reloadable'
|
||||||
|
import { MUTATION_TYPES as TIMELINE_MUTATION } from '@/store/TimelineSpace'
|
||||||
|
import { MUTATION_TYPES as HEADER_MUTATION } from '@/store/TimelineSpace/HeaderMenu'
|
||||||
|
import { MUTATION_TYPES as CONTENTS_MUTATION } from '@/store/TimelineSpace/Contents'
|
||||||
|
import { ACTION_TYPES, MUTATION_TYPES } from '@/store/TimelineSpace/Contents/Hashtag/Tag'
|
||||||
|
|
||||||
export default {
|
export default defineComponent({
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
focusedId: null,
|
|
||||||
scrollPosition: null,
|
|
||||||
observer: null,
|
|
||||||
scrollTime: null,
|
|
||||||
resizeTime: null
|
|
||||||
}
|
|
||||||
},
|
|
||||||
name: 'tag',
|
name: 'tag',
|
||||||
components: { Toot },
|
components: { Toot },
|
||||||
props: ['tag'],
|
props: ['tag'],
|
||||||
computed: {
|
setup(props) {
|
||||||
...mapState({
|
const space = 'TimelineSpace/Contents/Hashtag/Tag'
|
||||||
openSideBar: state => state.TimelineSpace.Contents.SideBar.openSideBar,
|
const store = useStore()
|
||||||
backgroundColor: state => state.App.theme.background_color,
|
const route = useRoute()
|
||||||
startReload: state => state.TimelineSpace.HeaderMenu.reload,
|
const i18n = useI18next()
|
||||||
timeline: state => state.TimelineSpace.Contents.Hashtag.Tag.timeline,
|
const { reloadable } = useReloadable(store, route, i18n)
|
||||||
lazyLoading: state => state.TimelineSpace.Contents.Hashtag.Tag.lazyLoading,
|
|
||||||
heading: state => state.TimelineSpace.Contents.Hashtag.Tag.heading,
|
|
||||||
scrolling: state => state.TimelineSpace.Contents.Hashtag.Tag.scrolling
|
|
||||||
}),
|
|
||||||
...mapGetters('TimelineSpace/Modals', ['modalOpened']),
|
|
||||||
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.timeline.findIndex(toot => this.focusedId === toot.uri + toot.id)
|
|
||||||
return currentIndex === -1
|
|
||||||
}
|
|
||||||
},
|
|
||||||
mounted() {
|
|
||||||
this.$store.commit('TimelineSpace/Contents/changeLoading', true)
|
|
||||||
this.load(this.tag).finally(() => {
|
|
||||||
this.$store.commit('TimelineSpace/Contents/changeLoading', false)
|
|
||||||
})
|
|
||||||
document.getElementById('scroller').addEventListener('scroll', this.onScroll)
|
|
||||||
|
|
||||||
EventEmitter.on('focus-timeline', () => {
|
const { tag } = toRefs(props)
|
||||||
// If focusedId does not change, we have to refresh focusedId because Toot component watch change events.
|
const focusedId = ref<string | null>(null)
|
||||||
const previousFocusedId = this.focusedId
|
const scrollPosition = ref<ScrollPosition | null>(null)
|
||||||
this.focusedId = 0
|
const observer = ref<ResizeObserver | null>(null)
|
||||||
this.$nextTick(function () {
|
const scrollTime = ref<moment.Moment | null>(null)
|
||||||
this.focusedId = previousFocusedId
|
const resizeTime = ref<moment.Moment | null>(null)
|
||||||
})
|
const scroller = ref<any>(null)
|
||||||
|
|
||||||
|
const timeline = computed(() => store.state.TimelineSpace.Contents.Hashtag.Tag.timeline)
|
||||||
|
const lazyLoading = computed(() => store.state.TimelineSpace.Contents.Hashtag.Tag.lazyLoading)
|
||||||
|
const heading = computed(() => store.state.TimelineSpace.Contents.Hashtag.Tag.heading)
|
||||||
|
const scrolling = computed(() => store.state.TimelineSpace.Contents.Hashtag.Tag.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(() => {
|
||||||
|
store.commit(`TimelineSpace/Contents/${CONTENTS_MUTATION.CHANGE_LOADING}`, true)
|
||||||
|
load(tag.value).finally(() => {
|
||||||
|
store.commit(`TimelineSpace/Contents/${CONTENTS_MUTATION.CHANGE_LOADING}`, false)
|
||||||
})
|
})
|
||||||
|
document.getElementById('scroller')?.addEventListener('scroll', onScroll)
|
||||||
|
|
||||||
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.scrollPosition && !this.heading && !this.lazyLoading && !this.scrolling) {
|
if (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.scrollPosition) {
|
|
||||||
this.scrollPosition.prepare()
|
|
||||||
}
|
}
|
||||||
},
|
|
||||||
watch: {
|
|
||||||
tag: function (newTag, _oldTag) {
|
|
||||||
this.$store.commit('TimelineSpace/Contents/changeLoading', true)
|
|
||||||
this.reset()
|
|
||||||
this.load(newTag).finally(() => {
|
|
||||||
this.$store.commit('TimelineSpace/Contents/changeLoading', false)
|
|
||||||
})
|
})
|
||||||
},
|
onBeforeUpdate(() => {
|
||||||
startReload: function (newState, oldState) {
|
if (scrollPosition.value) {
|
||||||
if (!oldState && newState) {
|
scrollPosition.value?.prepare()
|
||||||
this.reload().finally(() => {
|
}
|
||||||
this.$store.commit('TimelineSpace/HeaderMenu/changeReload', false)
|
})
|
||||||
|
watch(tag, (newTag, _oldTag) => {
|
||||||
|
store.commit(`TimelineSpace/Contents/${CONTENTS_MUTATION.CHANGE_LOADING}`, true)
|
||||||
|
reset()
|
||||||
|
load(newTag).finally(() => {
|
||||||
|
store.commit(`TimelineSpace/Contents/${CONTENTS_MUTATION.CHANGE_LOADING}`, false)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
watch(startReload, (newVal, oldVal) => {
|
||||||
|
if (!oldVal && newVal) {
|
||||||
|
reload().finally(() => {
|
||||||
|
store.commit(`TimelineSpace/HeaderMenu/${HEADER_MUTATION.CHANGE_RELOAD}`, false)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
})
|
||||||
focusedId: function (newState, _oldState) {
|
onBeforeUnmount(() => {
|
||||||
if (newState && this.heading) {
|
store.dispatch(`${space}/${ACTION_TYPES.STOP_STREAMING}`)
|
||||||
this.$store.commit('TimelineSpace/Contents/Hashtag/Tag/changeHeading', false)
|
reset()
|
||||||
} else if (newState === null && !this.heading) {
|
|
||||||
this.$store.commit('TimelineSpace/Contents/Hashtag/Tag/changeHeading', true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
beforeUnmount() {
|
|
||||||
this.$store.dispatch('TimelineSpace/Contents/Hashtag/Tag/stopStreaming')
|
|
||||||
this.reset()
|
|
||||||
EventEmitter.off('focus-timeline')
|
EventEmitter.off('focus-timeline')
|
||||||
this.observer.disconnect()
|
observer.value?.disconnect()
|
||||||
},
|
})
|
||||||
methods: {
|
|
||||||
async load(tag) {
|
const load = async (tag: string) => {
|
||||||
await this.$store.dispatch('TimelineSpace/Contents/Hashtag/Tag/fetch', tag).catch(() => {
|
await store.dispatch(`${space}/${ACTION_TYPES.FETCH}`, tag).catch(() => {
|
||||||
this.$message({
|
ElMessage({
|
||||||
message: this.$t('message.timeline_fetch_error'),
|
message: i18n.t('message.timeline_fetch_error'),
|
||||||
type: 'error'
|
type: 'error'
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
this.$store.dispatch('TimelineSpace/Contents/Hashtag/Tag/startStreaming', tag).catch(() => {
|
store.dispatch(`${space}/${ACTION_TYPES.START_STREAMING}`, tag).catch(() => {
|
||||||
this.$message({
|
ElMessage({
|
||||||
message: this.$t('message.start_streaming_error'),
|
message: i18n.t('message.start_streaming_error'),
|
||||||
type: 'error'
|
type: 'error'
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
return true
|
return true
|
||||||
},
|
|
||||||
reset() {
|
|
||||||
this.$store.commit('TimelineSpace/Contents/Hashtag/Tag/changeHeading', true)
|
|
||||||
this.$store.commit('TimelineSpace/Contents/Hashtag/Tag/archiveTimeline')
|
|
||||||
this.$store.commit('TimelineSpace/Contents/Hashtag/Tag/clearTimeline')
|
|
||||||
if (document.getElementById('scroller') !== undefined && document.getElementById('scroller') !== null) {
|
|
||||||
document.getElementById('scroller').removeEventListener('scroll', this.onScroll)
|
|
||||||
document.getElementById('scroller').scrollTop = 0
|
|
||||||
}
|
}
|
||||||
},
|
const reset = () => {
|
||||||
updateToot(toot) {
|
store.commit(`${space}/${MUTATION_TYPES.CHANGE_HEADING}`, true)
|
||||||
this.$store.commit('TimelineSpace/Contents/Hashtag/Tag/updateToot', toot)
|
store.commit(`${space}/${MUTATION_TYPES.ARCHIVE_TIMELINE}`)
|
||||||
},
|
store.commit(`${space}/${MUTATION_TYPES.CLEAR_TIMELINE}`)
|
||||||
deleteToot(toot) {
|
const el = document.getElementById('scroller')
|
||||||
this.$store.commit('TimelineSpace/Contents/Hashtag/Tag/deleteToot', toot.id)
|
if (el !== undefined && el !== null) {
|
||||||
},
|
el.removeEventListener('scroll', onScroll)
|
||||||
onScroll(event) {
|
el.scrollTop = 0
|
||||||
if (moment().diff(this.resizeTime) < 500) {
|
}
|
||||||
|
}
|
||||||
|
const onScroll = (event: Event) => {
|
||||||
|
if (moment().diff(resizeTime.value) < 500) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.scrollTime = moment()
|
scrollTime.value = moment()
|
||||||
if (!this.scrolling) {
|
if (!scrolling.value) {
|
||||||
this.$store.commit('TimelineSpace/Contents/Hashtag/Tag/changeScrolling', true)
|
store.commit(`${space}/${MUTATION_TYPES.CHANGE_SCROLLING}`, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
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/Hashtag/Tag/lazyFetchTimeline', {
|
.dispatch(`${space}/${ACTION_TYPES.LAZY_FETCH_TIMELINE}`, {
|
||||||
tag: this.tag,
|
tag: tag.value,
|
||||||
status: this.timeline[this.timeline.length - 1]
|
status: timeline.value[timeline.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/Hashtag/Tag/changeScrolling', true)
|
store.commit(`${space}/${MUTATION_TYPES.CHANGE_SCROLLING}`, true)
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.$store.commit('TimelineSpace/Contents/Hashtag/Tag/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/Hashtag/Tag/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/Hashtag/Tag/changeHeading', true)
|
store.commit(`${space}/${MUTATION_TYPES.CHANGE_HEADING}`, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
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/Hashtag/Tag/changeScrolling', false)
|
store.commit(`${space}/${MUTATION_TYPES.CHANGE_SCROLLING}`, false)
|
||||||
}
|
}
|
||||||
}, 150)
|
}, 150)
|
||||||
},
|
}
|
||||||
async reload() {
|
const updateToot = (toot: Entity.Status) => {
|
||||||
const tag = this.tag
|
store.commit(`${space}/${MUTATION_TYPES.UPDATE_TOOT}`, toot)
|
||||||
this.$store.commit('TimelineSpace/changeLoading', true)
|
}
|
||||||
|
const deleteToot = (toot: Entity.Status) => {
|
||||||
|
store.commit(`${space}/${MUTATION_TYPES.DELETE_TOOT}`, toot.id)
|
||||||
|
}
|
||||||
|
const reload = async () => {
|
||||||
|
store.commit(`TimelineSpace/${TIMELINE_MUTATION.CHANGE_LOADING}`, true)
|
||||||
try {
|
try {
|
||||||
await this.$store.dispatch('TimelineSpace/Contents/Hashtag/Tag/stopStreaming')
|
await reloadable()
|
||||||
await this.$store.dispatch('TimelineSpace/Contents/Hashtag/Tag/fetch', tag).catch(() => {
|
await store.dispatch(`${space}/${ACTION_TYPES.STOP_STREAMING}`)
|
||||||
this.$message({
|
await store.dispatch(`${space}/${ACTION_TYPES.FETCH}`, tag.value).catch(() => {
|
||||||
message: this.$t('message.timeline_fetch_error'),
|
ElMessage({
|
||||||
|
message: i18n.t('message.timeline_fetch_error'),
|
||||||
type: 'error'
|
type: 'error'
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
this.$store.dispatch('TimelineSpace/Contents/Hashtag/Tag/startStreaming', tag).catch(() => {
|
store.dispatch(`${space}/${ACTION_TYPES.START_STREAMING}`, tag.value).catch(() => {
|
||||||
this.$message({
|
ElMessage({
|
||||||
message: this.$t('message.start_streaming_error'),
|
message: i18n.t('message.start_streaming_error'),
|
||||||
type: 'error'
|
type: 'error'
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
} finally {
|
} 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 upper = () => {
|
||||||
focusPrev() {
|
scroller.value.scrollToItem(0)
|
||||||
const currentIndex = this.timeline.findIndex(toot => this.focusedId === toot.uri + toot.id)
|
focusedId.value = null
|
||||||
if (currentIndex === 0) {
|
|
||||||
this.focusedId = null
|
|
||||||
} else if (currentIndex > 0) {
|
|
||||||
this.focusedId = this.timeline[currentIndex - 1].uri + this.timeline[currentIndex - 1].id
|
|
||||||
}
|
}
|
||||||
},
|
const focusNext = () => {
|
||||||
focusToot(message) {
|
if (currentFocusedIndex.value === -1) {
|
||||||
this.focusedId = message.uri + message.id
|
focusedId.value = timeline.value[0].uri + timeline.value[0].id
|
||||||
},
|
} else if (currentFocusedIndex.value < timeline.value.length) {
|
||||||
focusSidebar() {
|
focusedId.value = timeline.value[currentFocusedIndex.value + 1].uri + timeline.value[currentFocusedIndex.value + 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const focusToot = (message: Entity.Status) => {
|
||||||
|
focusedId.value = message.uri + message.id
|
||||||
|
}
|
||||||
|
const focusSidebar = () => {
|
||||||
EventEmitter.emit('focus-sidebar')
|
EventEmitter.emit('focus-sidebar')
|
||||||
},
|
|
||||||
handleKey(event) {
|
|
||||||
switch (event.srcKey) {
|
|
||||||
case 'next':
|
|
||||||
this.focusedId = this.timeline[0].uri + this.timeline[0].id
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
},
|
const sizeChanged = () => {
|
||||||
sizeChanged() {
|
store.commit(`${space}/${MUTATION_TYPES.CHANGE_SCROLLING}`, true)
|
||||||
this.$store.commit('TimelineSpace/Contents/Hashtag/Tag/changeScrolling', true)
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.$store.commit('TimelineSpace/Contents/Hashtag/Tag/changeScrolling', false)
|
store.commit(`${space}/${MUTATION_TYPES.CHANGE_SCROLLING}`, false)
|
||||||
}, 500)
|
}, 500)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
timeline,
|
||||||
|
scroller,
|
||||||
|
focusedId,
|
||||||
|
modalOpened,
|
||||||
|
updateToot,
|
||||||
|
deleteToot,
|
||||||
|
focusNext,
|
||||||
|
focusPrev,
|
||||||
|
focusSidebar,
|
||||||
|
focusToot,
|
||||||
|
sizeChanged,
|
||||||
|
openSideBar,
|
||||||
|
heading,
|
||||||
|
upper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { Module, MutationTree, ActionTree } from 'vuex'
|
||||||
import { RootState } from '@/store'
|
import { RootState } from '@/store'
|
||||||
import { MyWindow } from '~/src/types/global'
|
import { MyWindow } from '~/src/types/global'
|
||||||
|
|
||||||
const win = (window as any) as MyWindow
|
const win = window as any as MyWindow
|
||||||
|
|
||||||
export type ListState = {
|
export type ListState = {
|
||||||
tags: Array<LocalTag>
|
tags: Array<LocalTag>
|
||||||
|
@ -23,13 +23,18 @@ const mutations: MutationTree<ListState> = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const ACTION_TYPES = {
|
||||||
|
LIST_TAGS: 'listTags',
|
||||||
|
REMOVE_TAG: 'removeTag'
|
||||||
|
}
|
||||||
|
|
||||||
const actions: ActionTree<ListState, RootState> = {
|
const actions: ActionTree<ListState, RootState> = {
|
||||||
listTags: async ({ commit }) => {
|
[ACTION_TYPES.LIST_TAGS]: async ({ commit }) => {
|
||||||
const tags: Array<LocalTag> = await win.ipcRenderer.invoke('list-hashtags')
|
const tags: Array<LocalTag> = await win.ipcRenderer.invoke('list-hashtags')
|
||||||
commit(MUTATION_TYPES.UPDATE_TAGS, tags)
|
commit(MUTATION_TYPES.UPDATE_TAGS, tags)
|
||||||
return tags
|
return tags
|
||||||
},
|
},
|
||||||
removeTag: async ({ dispatch }, tag: LocalTag) => {
|
[ACTION_TYPES.REMOVE_TAG]: async ({ dispatch }, tag: LocalTag) => {
|
||||||
await win.ipcRenderer.invoke('remove-hashtag', tag)
|
await win.ipcRenderer.invoke('remove-hashtag', tag)
|
||||||
dispatch('listTags')
|
dispatch('listTags')
|
||||||
dispatch('TimelineSpace/SideMenu/listTags', {}, { root: true })
|
dispatch('TimelineSpace/SideMenu/listTags', {}, { root: true })
|
||||||
|
|
|
@ -88,8 +88,15 @@ const mutations: MutationTree<TagState> = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const ACTION_TYPES = {
|
||||||
|
FETCH: 'fetch',
|
||||||
|
START_STREAMING: 'startStreaming',
|
||||||
|
STOP_STREAMING: 'stopStreaming',
|
||||||
|
LAZY_FETCH_TIMELINE: 'lazyFetchTimeline'
|
||||||
|
}
|
||||||
|
|
||||||
const actions: ActionTree<TagState, RootState> = {
|
const actions: ActionTree<TagState, RootState> = {
|
||||||
fetch: async ({ commit, rootState }, tag: string): Promise<Array<Entity.Status>> => {
|
[ACTION_TYPES.FETCH]: async ({ commit, rootState }, tag: string): Promise<Array<Entity.Status>> => {
|
||||||
const client = generator(
|
const client = generator(
|
||||||
rootState.TimelineSpace.sns,
|
rootState.TimelineSpace.sns,
|
||||||
rootState.TimelineSpace.account.baseURL,
|
rootState.TimelineSpace.account.baseURL,
|
||||||
|
@ -100,7 +107,7 @@ const actions: ActionTree<TagState, RootState> = {
|
||||||
commit(MUTATION_TYPES.UPDATE_TIMELINE, res.data)
|
commit(MUTATION_TYPES.UPDATE_TIMELINE, res.data)
|
||||||
return res.data
|
return res.data
|
||||||
},
|
},
|
||||||
startStreaming: ({ state, commit, rootState }, tag: string) => {
|
[ACTION_TYPES.START_STREAMING]: ({ state, commit, rootState }, tag: string) => {
|
||||||
win.ipcRenderer.on('update-start-tag-streaming', (_, update: Entity.Status) => {
|
win.ipcRenderer.on('update-start-tag-streaming', (_, update: Entity.Status) => {
|
||||||
commit(MUTATION_TYPES.APPEND_TIMELINE, update)
|
commit(MUTATION_TYPES.APPEND_TIMELINE, update)
|
||||||
if (state.heading && Math.random() > 0.8) {
|
if (state.heading && Math.random() > 0.8) {
|
||||||
|
@ -122,7 +129,7 @@ const actions: ActionTree<TagState, RootState> = {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
stopStreaming: () => {
|
[ACTION_TYPES.STOP_STREAMING]: () => {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
win.ipcRenderer.removeAllListeners('error-start-tag-streaming')
|
win.ipcRenderer.removeAllListeners('error-start-tag-streaming')
|
||||||
win.ipcRenderer.removeAllListeners('update-start-tag-streaming')
|
win.ipcRenderer.removeAllListeners('update-start-tag-streaming')
|
||||||
|
@ -131,7 +138,10 @@ const actions: ActionTree<TagState, RootState> = {
|
||||||
resolve(null)
|
resolve(null)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
lazyFetchTimeline: async ({ state, commit, rootState }, loadPosition: LoadPositionWithTag): Promise<Array<Entity.Status> | null> => {
|
[ACTION_TYPES.LAZY_FETCH_TIMELINE]: async (
|
||||||
|
{ state, commit, rootState },
|
||||||
|
loadPosition: LoadPositionWithTag
|
||||||
|
): Promise<Array<Entity.Status> | null> => {
|
||||||
if (state.lazyLoading) {
|
if (state.lazyLoading) {
|
||||||
return Promise.resolve(null)
|
return Promise.resolve(null)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue