2018-03-09 07:21:25 +01:00
|
|
|
<template>
|
2022-04-19 17:57:25 +02:00
|
|
|
<div id="local">
|
|
|
|
<div></div>
|
2022-04-19 14:05:32 +02:00
|
|
|
<DynamicScroller :items="timeline" :min-item-size="86" id="scroller" class="scroller" ref="scroller">
|
2020-10-15 17:06:26 +02:00
|
|
|
<template v-slot="{ item, index, active }">
|
2022-04-19 14:05:32 +02:00
|
|
|
<DynamicScrollerItem :item="item" :active="active" :size-dependencies="[item.uri]" :data-index="index" :watchData="true">
|
2020-10-15 17:06:26 +02:00
|
|
|
<toot
|
|
|
|
:message="item"
|
|
|
|
:focused="item.uri + item.id === focusedId"
|
|
|
|
:overlaid="modalOpened"
|
2021-07-23 14:54:52 +02:00
|
|
|
:filters="[]"
|
2020-10-15 17:06:26 +02:00
|
|
|
v-on:update="updateToot"
|
|
|
|
v-on:delete="deleteToot"
|
|
|
|
@focusRight="focusSidebar"
|
|
|
|
@selectToot="focusToot(item)"
|
2021-10-23 15:02:11 +02:00
|
|
|
@sizeChanged="sizeChanged"
|
2020-10-15 17:06:26 +02:00
|
|
|
>
|
|
|
|
</toot>
|
|
|
|
</DynamicScrollerItem>
|
|
|
|
</template>
|
|
|
|
</DynamicScroller>
|
2022-04-19 14:05:32 +02:00
|
|
|
<div :class="openSideBar ? 'upper-with-side-bar' : 'upper'" v-show="!heading">
|
|
|
|
<el-button type="primary" @click="upper" circle>
|
2022-04-22 17:13:04 +02:00
|
|
|
<font-awesome-icon icon="angle-up" class="upper-icon" />
|
2022-04-18 15:41:52 +02:00
|
|
|
</el-button>
|
2018-03-27 15:16:23 +02:00
|
|
|
</div>
|
2018-07-19 14:51:54 +02:00
|
|
|
</div>
|
2018-03-09 07:21:25 +01:00
|
|
|
</template>
|
|
|
|
|
2022-06-08 14:48:43 +02:00
|
|
|
<script lang="ts">
|
|
|
|
import { computed, defineComponent, onBeforeUnmount, onBeforeUpdate, onMounted, onUnmounted, ref, watch } from 'vue'
|
2022-08-12 14:46:45 +02:00
|
|
|
import { useMagicKeys, whenever, and } from '@vueuse/core'
|
2021-08-28 17:41:07 +02:00
|
|
|
import moment from 'moment'
|
2022-06-08 14:48:43 +02:00
|
|
|
import { ElMessage } from 'element-plus'
|
|
|
|
import { Entity } from 'megalodon'
|
|
|
|
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 { ACTION_TYPES, MUTATION_TYPES } from '@/store/TimelineSpace/Contents/Local'
|
|
|
|
import { MUTATION_TYPES as SIDE_MENU_MUTATION } from '@/store/TimelineSpace/SideMenu'
|
|
|
|
import { MUTATION_TYPES as TIMELINE_MUTATION, ACTION_TYPES as TIMELINE_ACTION } from '@/store/TimelineSpace'
|
|
|
|
import { MUTATION_TYPES as HEADER_MUTATION } from '@/store/TimelineSpace/HeaderMenu'
|
|
|
|
import { MUTATION_TYPES as CONTENTS_MUTATION } from '@/store/TimelineSpace/Contents'
|
2018-03-14 04:24:54 +01:00
|
|
|
|
2022-06-08 14:48:43 +02:00
|
|
|
export default defineComponent({
|
2022-04-18 15:41:52 +02:00
|
|
|
name: 'local',
|
|
|
|
components: { Toot },
|
2022-06-08 14:48:43 +02:00
|
|
|
setup() {
|
|
|
|
const space = 'TimelineSpace/Contents/Local'
|
|
|
|
const store = useStore()
|
|
|
|
const route = useRoute()
|
|
|
|
const i18n = useI18next()
|
|
|
|
const { reloadable } = useReloadable(store, route, i18n)
|
2022-08-12 15:45:05 +02:00
|
|
|
const { j, k, r } = useMagicKeys()
|
2018-11-28 14:55:11 +01:00
|
|
|
|
2022-06-08 14:48:43 +02:00
|
|
|
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)
|
2021-08-26 15:22:52 +02:00
|
|
|
|
2022-06-08 14:48:43 +02:00
|
|
|
const timeline = computed(() => store.state.TimelineSpace.Contents.Local.timeline)
|
|
|
|
const lazyLoading = computed(() => store.state.TimelineSpace.Contents.Local.lazyLoading)
|
|
|
|
const heading = computed(() => store.state.TimelineSpace.Contents.Local.heading)
|
|
|
|
const scrolling = computed(() => store.state.TimelineSpace.Contents.Local.scrolling)
|
|
|
|
const openSideBar = computed(() => store.state.TimelineSpace.Contents.SideBar.openSideBar)
|
|
|
|
const startReload = computed(() => store.state.TimelineSpace.HeaderMenu.reload)
|
|
|
|
const unreadNotification = computed(() => store.state.TimelineSpace.timelineSetting.unreadNotification)
|
2022-08-12 14:46:45 +02:00
|
|
|
const modalOpened = computed<boolean>(() => store.getters[`TimelineSpace/Modals/modalOpened`])
|
2022-06-08 14:48:43 +02:00
|
|
|
const currentFocusedIndex = computed(() => timeline.value.findIndex(toot => focusedId.value === toot.uri + toot.id))
|
2022-08-12 14:46:45 +02:00
|
|
|
const shortcutEnabled = computed(() => !modalOpened.value)
|
2022-06-08 14:48:43 +02:00
|
|
|
|
|
|
|
onMounted(async () => {
|
|
|
|
store.commit(`TimelineSpace/SideMenu/${SIDE_MENU_MUTATION.CHANGE_UNREAD_LOCAL_TIMELINE}`, false)
|
|
|
|
document.getElementById('scroller')?.addEventListener('scroll', onScroll)
|
|
|
|
if (!unreadNotification.value.local) {
|
|
|
|
store.commit(`TimelineSpace/Contents/${CONTENTS_MUTATION.CHANGE_LOADING}`, true)
|
|
|
|
await initialize().finally(() => {
|
|
|
|
store.commit(`TimelineSpace/Contents/${CONTENTS_MUTATION.CHANGE_LOADING}`, false)
|
|
|
|
})
|
2021-08-26 15:22:52 +02:00
|
|
|
}
|
|
|
|
|
2022-06-08 14:48:43 +02:00
|
|
|
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()
|
|
|
|
}
|
2019-05-16 16:43:32 +02:00
|
|
|
})
|
2022-06-08 14:48:43 +02:00
|
|
|
|
|
|
|
const scrollWrapper = el.getElementsByClassName('vue-recycle-scroller__item-wrapper')[0]
|
|
|
|
observer.value.observe(scrollWrapper)
|
2018-06-27 14:10:40 +02:00
|
|
|
}
|
2022-06-08 14:48:43 +02:00
|
|
|
})
|
|
|
|
onBeforeUpdate(() => {
|
|
|
|
if (store.state.TimelineSpace.SideMenu.unreadLocalTimeline && heading.value) {
|
|
|
|
store.commit(`TimelineSpace/SideMenu/${SIDE_MENU_MUTATION.CHANGE_UNREAD_LOCAL_TIMELINE}`, false)
|
2018-08-21 16:20:44 +02:00
|
|
|
}
|
2022-06-08 14:48:43 +02:00
|
|
|
if (scrollPosition.value) {
|
|
|
|
scrollPosition.value.prepare()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
onBeforeUnmount(() => {
|
|
|
|
if (!unreadNotification.value.local) {
|
|
|
|
store.dispatch(`TimelineSpace/${TIMELINE_ACTION.STOP_LOCAL_STREAMING}`)
|
|
|
|
store.dispatch(`TimelineSpace/${TIMELINE_ACTION.UNBIND_LOCAL_STREAMING}`)
|
|
|
|
}
|
|
|
|
EventEmitter.off('focus-timeline')
|
|
|
|
observer.value?.disconnect()
|
|
|
|
})
|
|
|
|
onUnmounted(() => {
|
|
|
|
store.commit(`${space}/${MUTATION_TYPES.CHANGE_HEADING}`, true)
|
|
|
|
store.commit(`${space}/${MUTATION_TYPES.ARCHIVE_TIMELINE}`)
|
|
|
|
if (!unreadNotification.value.local) {
|
|
|
|
store.commit(`${space}/${MUTATION_TYPES.CLEAR_TIMELINE}`)
|
|
|
|
}
|
|
|
|
const el = document.getElementById('scroller')
|
|
|
|
if (el) {
|
|
|
|
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)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-08-12 14:46:45 +02:00
|
|
|
watch(focusedId, (newVal, _oldVal) => {
|
|
|
|
if (newVal && heading.value) {
|
|
|
|
store.commit(`${space}/${MUTATION_TYPES.CHANGE_HEADING}`, false)
|
|
|
|
} else if (newVal === null && !heading.value) {
|
|
|
|
store.commit(`${space}/${MUTATION_TYPES.CHANGE_HEADING}`, true)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
whenever(and(j, shortcutEnabled), () => {
|
|
|
|
if (focusedId.value === null) {
|
|
|
|
focusedId.value = timeline.value[0].uri + timeline.value[0].id
|
|
|
|
} else {
|
|
|
|
focusNext()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
whenever(and(k, shortcutEnabled), () => {
|
|
|
|
focusPrev()
|
|
|
|
})
|
2022-08-12 15:45:05 +02:00
|
|
|
whenever(and(r, shortcutEnabled), () => {
|
|
|
|
reload()
|
|
|
|
})
|
2022-08-12 14:46:45 +02:00
|
|
|
|
2022-06-08 14:48:43 +02:00
|
|
|
const initialize = async () => {
|
|
|
|
await store.dispatch(`${space}/${ACTION_TYPES.FETCH_LOCAL_TIMELINE}`).catch(_ => {
|
|
|
|
ElMessage({
|
|
|
|
message: i18n.t('message.timeline_fetch_error'),
|
2022-04-19 14:05:32 +02:00
|
|
|
type: 'error'
|
2018-11-08 00:12:51 +01:00
|
|
|
})
|
2022-04-19 14:05:32 +02:00
|
|
|
})
|
2022-06-08 14:48:43 +02:00
|
|
|
await store.dispatch(`TimelineSpace/${TIMELINE_ACTION.BIND_LOCAL_STREAMING}`)
|
|
|
|
store.dispatch(`TimelineSpace/${TIMELINE_ACTION.START_LOCAL_STREAMING}`)
|
|
|
|
}
|
|
|
|
const onScroll = (event: Event) => {
|
|
|
|
if (moment().diff(resizeTime.value) < 500) {
|
2021-08-28 17:41:07 +02:00
|
|
|
return
|
|
|
|
}
|
2022-06-08 14:48:43 +02:00
|
|
|
scrollTime.value = moment()
|
|
|
|
if (!scrolling.value) {
|
|
|
|
store.commit(`${space}/${MUTATION_TYPES.CHANGE_SCROLLING}`, true)
|
2021-08-28 17:41:07 +02:00
|
|
|
}
|
|
|
|
|
2021-07-23 14:54:52 +02:00
|
|
|
if (
|
2022-06-08 14:48:43 +02:00
|
|
|
(event.target as HTMLElement)!.clientHeight + (event.target as HTMLElement)!.scrollTop >=
|
|
|
|
document.getElementById('scroller')!.scrollHeight - 10 &&
|
|
|
|
!lazyLoading.value
|
2021-07-23 14:54:52 +02:00
|
|
|
) {
|
2022-06-08 14:48:43 +02:00
|
|
|
store
|
|
|
|
.dispatch(`${space}/${ACTION_TYPES.LAZY_FETCH_TIMELINE}`, timeline.value[timeline.value.length - 1])
|
2022-04-19 14:05:32 +02:00
|
|
|
.then(statuses => {
|
2021-09-13 19:02:51 +02:00
|
|
|
if (statuses === null) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (statuses.length > 0) {
|
2022-06-08 14:48:43 +02:00
|
|
|
store.commit(`${space}/${MUTATION_TYPES.CHANGE_SCROLLING}`, true)
|
2021-09-13 19:02:51 +02:00
|
|
|
setTimeout(() => {
|
2022-06-08 14:48:43 +02:00
|
|
|
store.commit(`${space}/${MUTATION_TYPES.CHANGE_SCROLLING}`, false)
|
2021-09-13 19:02:51 +02:00
|
|
|
}, 500)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(() => {
|
2022-06-08 14:48:43 +02:00
|
|
|
ElMessage({
|
|
|
|
message: i18n.t('message.timeline_fetch_error'),
|
2022-04-19 14:05:32 +02:00
|
|
|
type: 'error'
|
2021-09-13 19:02:51 +02:00
|
|
|
})
|
2018-04-14 14:58:53 +02:00
|
|
|
})
|
2018-03-27 15:16:23 +02:00
|
|
|
}
|
2022-06-08 14:48:43 +02:00
|
|
|
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)
|
2018-04-21 07:15:43 +02:00
|
|
|
}
|
2021-08-28 17:41:07 +02:00
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
const now = moment()
|
2022-06-08 14:48:43 +02:00
|
|
|
if (now.diff(scrollTime.value) >= 150) {
|
|
|
|
scrollTime.value = null
|
|
|
|
store.commit(`${space}/${MUTATION_TYPES.CHANGE_SCROLLING}`, false)
|
2021-08-28 17:41:07 +02:00
|
|
|
}
|
|
|
|
}, 150)
|
2022-06-08 14:48:43 +02:00
|
|
|
}
|
|
|
|
const reload = async () => {
|
|
|
|
store.commit(`TimelineSpace/${TIMELINE_MUTATION.CHANGE_LOADING}`, true)
|
2018-07-02 14:53:09 +02:00
|
|
|
try {
|
2022-06-08 14:48:43 +02:00
|
|
|
await reloadable()
|
2018-07-02 14:53:09 +02:00
|
|
|
} finally {
|
2022-06-08 14:48:43 +02:00
|
|
|
store.commit(`TimelineSpace/${TIMELINE_MUTATION.CHANGE_LOADING}`, false)
|
2018-07-02 14:53:09 +02:00
|
|
|
}
|
2022-06-08 14:48:43 +02:00
|
|
|
}
|
|
|
|
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
|
2018-08-21 16:20:44 +02:00
|
|
|
}
|
2022-06-08 14:48:43 +02:00
|
|
|
}
|
|
|
|
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
|
2018-08-21 16:20:44 +02:00
|
|
|
}
|
2022-06-08 14:48:43 +02:00
|
|
|
}
|
|
|
|
const focusToot = (message: Entity.Status) => {
|
|
|
|
focusedId.value = message.uri + message.id
|
|
|
|
}
|
|
|
|
const focusSidebar = () => {
|
2022-04-25 17:04:49 +02:00
|
|
|
EventEmitter.emit('focus-sidebar')
|
2022-06-08 14:48:43 +02:00
|
|
|
}
|
|
|
|
const sizeChanged = () => {
|
|
|
|
store.commit(`${space}/${MUTATION_TYPES.CHANGE_SCROLLING}`, true)
|
2021-10-23 15:02:11 +02:00
|
|
|
setTimeout(() => {
|
2022-06-08 14:48:43 +02:00
|
|
|
store.commit(`${space}/${MUTATION_TYPES.CHANGE_SCROLLING}`, false)
|
2021-10-23 15:02:11 +02:00
|
|
|
}, 500)
|
2022-04-19 14:05:32 +02:00
|
|
|
}
|
2022-06-08 14:48:43 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
scroller,
|
|
|
|
timeline,
|
|
|
|
focusedId,
|
|
|
|
modalOpened,
|
|
|
|
updateToot,
|
|
|
|
deleteToot,
|
|
|
|
focusSidebar,
|
|
|
|
focusToot,
|
|
|
|
sizeChanged,
|
|
|
|
openSideBar,
|
|
|
|
heading,
|
|
|
|
upper
|
|
|
|
}
|
2022-04-19 14:05:32 +02:00
|
|
|
}
|
2022-06-08 14:48:43 +02:00
|
|
|
})
|
2018-03-09 07:21:25 +01:00
|
|
|
</script>
|
2018-03-27 15:16:23 +02:00
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2018-04-21 07:15:43 +02:00
|
|
|
#local {
|
2021-07-23 14:54:52 +02:00
|
|
|
height: 100%;
|
|
|
|
overflow: auto;
|
|
|
|
scroll-behavior: auto;
|
|
|
|
|
|
|
|
.scroller {
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
|
2018-04-21 07:15:43 +02:00
|
|
|
.loading-card {
|
|
|
|
height: 60px;
|
|
|
|
}
|
2018-03-27 15:16:23 +02:00
|
|
|
|
2018-04-21 07:15:43 +02:00
|
|
|
.loading-card:empty {
|
|
|
|
height: 0;
|
|
|
|
}
|
2018-07-19 14:51:54 +02:00
|
|
|
|
|
|
|
.upper {
|
|
|
|
position: fixed;
|
|
|
|
bottom: 20px;
|
|
|
|
right: 20px;
|
|
|
|
}
|
2018-10-31 15:11:11 +01:00
|
|
|
|
|
|
|
.upper-with-side-bar {
|
|
|
|
position: fixed;
|
|
|
|
bottom: 20px;
|
2019-09-29 07:47:47 +02:00
|
|
|
right: calc(20px + var(--current-sidebar-width));
|
|
|
|
transition: all 0.5s;
|
2018-10-31 15:11:11 +01:00
|
|
|
}
|
2022-04-22 17:13:04 +02:00
|
|
|
|
|
|
|
.upper-icon {
|
|
|
|
padding: 3px;
|
|
|
|
}
|
2018-03-27 15:16:23 +02:00
|
|
|
}
|
|
|
|
</style>
|
2022-04-18 15:41:52 +02:00
|
|
|
|
2020-08-20 15:38:30 +02:00
|
|
|
<style lang="scss" src="@/assets/timeline-transition.scss"></style>
|