2018-04-09 01:43:11 +02:00
|
|
|
<template>
|
2022-04-19 17:57:25 +02:00
|
|
|
<div name="list" class="list-timeline">
|
2022-12-13 13:50:48 +01:00
|
|
|
<div class="unread">{{ unreads.length > 0 ? unreads.length : '' }}</div>
|
2022-04-19 14:05:32 +02:00
|
|
|
<DynamicScroller :items="timeline" :min-item-size="86" id="scroller" class="scroller" ref="scroller">
|
2020-10-19 18:04:23 +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-19 18:04:23 +02:00
|
|
|
<toot
|
|
|
|
:message="item"
|
|
|
|
:focused="item.uri + item.id === focusedId"
|
|
|
|
:overlaid="modalOpened"
|
2021-07-23 15:16:27 +02:00
|
|
|
:filters="[]"
|
2020-10-19 18:04:23 +02:00
|
|
|
v-on:update="updateToot"
|
|
|
|
v-on:delete="deleteToot"
|
|
|
|
@focusRight="focusSidebar"
|
|
|
|
@selectToot="focusToot(item)"
|
|
|
|
>
|
|
|
|
</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-04-23 12:03:47 +02:00
|
|
|
</div>
|
2018-07-19 15:05:21 +02:00
|
|
|
</div>
|
2018-04-09 01:43:11 +02:00
|
|
|
</template>
|
|
|
|
|
2022-06-15 16:24:25 +02:00
|
|
|
<script lang="ts">
|
2022-12-13 13:50:48 +01:00
|
|
|
import { defineComponent, toRefs, ref, computed, onMounted, watch, onBeforeUnmount, onUnmounted } from 'vue'
|
2022-08-12 15:00:27 +02:00
|
|
|
import { useMagicKeys, whenever, and } from '@vueuse/core'
|
2022-06-15 16:24:25 +02:00
|
|
|
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 { 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'
|
2018-04-09 14:10:25 +02:00
|
|
|
|
2022-06-15 16:24:25 +02:00
|
|
|
export default defineComponent({
|
2022-04-18 15:41:52 +02:00
|
|
|
name: 'list',
|
|
|
|
props: ['list_id'],
|
|
|
|
components: { Toot },
|
2022-06-15 16:24:25 +02:00
|
|
|
setup(props) {
|
|
|
|
const space = 'TimelineSpace/Contents/Lists/Show'
|
|
|
|
const store = useStore()
|
|
|
|
const i18n = useI18next()
|
2022-09-04 15:48:47 +02:00
|
|
|
const { j, k, Ctrl_r } = useMagicKeys()
|
2022-06-15 16:24:25 +02:00
|
|
|
|
|
|
|
const { list_id } = toRefs(props)
|
|
|
|
const focusedId = ref<string | null>(null)
|
|
|
|
const scroller = ref<any>(null)
|
|
|
|
|
|
|
|
const timeline = computed(() => store.state.TimelineSpace.Contents.Lists.Show.timeline)
|
2022-12-13 13:50:48 +01:00
|
|
|
const unreads = computed(() => store.state.TimelineSpace.Contents.Lists.Show.unreads)
|
2022-06-15 16:24:25 +02:00
|
|
|
const lazyLoading = computed(() => store.state.TimelineSpace.Contents.Lists.Show.lazyLoading)
|
|
|
|
const heading = computed(() => store.state.TimelineSpace.Contents.Lists.Show.heading)
|
|
|
|
const openSideBar = computed(() => store.state.TimelineSpace.Contents.SideBar.openSideBar)
|
|
|
|
const startReload = computed(() => store.state.TimelineSpace.HeaderMenu.reload)
|
2022-08-12 15:00:27 +02:00
|
|
|
const modalOpened = computed<boolean>(() => store.getters[`TimelineSpace/Modals/modalOpened`])
|
2022-06-15 16:24:25 +02:00
|
|
|
const currentFocusedIndex = computed(() => timeline.value.findIndex(toot => focusedId.value === toot.uri + toot.id))
|
2022-08-12 15:00:27 +02:00
|
|
|
const shortcutEnabled = computed(() => !modalOpened.value)
|
2022-06-15 16:24:25 +02:00
|
|
|
|
|
|
|
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)
|
2018-11-28 15:03:07 +01:00
|
|
|
})
|
2022-06-15 16:24:25 +02:00
|
|
|
})
|
|
|
|
watch(list_id, () => {
|
|
|
|
store.commit(`TimelineSpace/Contents/${CONTENTS_MUTATION.CHANGE_LOADING}`, true)
|
|
|
|
load().finally(() => {
|
|
|
|
store.commit(`TimelineSpace/Contents/${CONTENTS_MUTATION.CHANGE_LOADING}`, false)
|
2019-05-16 16:43:32 +02:00
|
|
|
})
|
2022-06-15 16:24:25 +02:00
|
|
|
})
|
|
|
|
watch(startReload, (newVal, oldVal) => {
|
|
|
|
if (!oldVal && newVal) {
|
|
|
|
reload().finally(() => {
|
|
|
|
store.commit(`TimelineSpace/HeaderMenu/${HEADER_MUTATION.CHANGE_RELOAD}`, false)
|
2019-05-16 16:43:32 +02:00
|
|
|
})
|
2018-06-27 15:27:46 +02:00
|
|
|
}
|
2022-06-15 16:24:25 +02:00
|
|
|
})
|
2022-08-12 15:00:27 +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-09-04 15:48:47 +02:00
|
|
|
whenever(and(Ctrl_r, shortcutEnabled), () => {
|
2022-08-12 15:45:05 +02:00
|
|
|
reload()
|
|
|
|
})
|
2022-08-12 15:00:27 +02:00
|
|
|
|
2022-06-15 16:24:25 +02:00
|
|
|
onBeforeUnmount(() => {
|
|
|
|
store.dispatch(`${space}/${ACTION_TYPES.STOP_STREAMING}`)
|
|
|
|
})
|
|
|
|
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
|
2018-08-21 16:52:00 +02:00
|
|
|
}
|
2022-06-15 16:24:25 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
const load = async () => {
|
|
|
|
await store.dispatch(`${space}/${ACTION_TYPES.STOP_STREAMING}`)
|
2018-04-09 16:43:36 +02:00
|
|
|
try {
|
2022-06-15 16:24:25 +02:00
|
|
|
await store.dispatch(`${space}/${ACTION_TYPES.FETCH_TIMELINE}`, list_id.value)
|
2018-04-09 16:43:36 +02:00
|
|
|
} catch (err) {
|
2022-06-15 16:24:25 +02:00
|
|
|
ElMessage({
|
|
|
|
message: i18n.t('message.timeline_fetch_error'),
|
2022-04-19 14:05:32 +02:00
|
|
|
type: 'error'
|
2018-04-09 14:10:25 +02:00
|
|
|
})
|
2018-04-09 16:43:36 +02:00
|
|
|
}
|
2022-06-15 16:24:25 +02:00
|
|
|
store.dispatch(`${space}/${ACTION_TYPES.START_STREAMING}`, list_id.value).catch(() => {
|
|
|
|
ElMessage({
|
|
|
|
message: i18n.t('message.start_streaming_error'),
|
2022-04-19 14:05:32 +02:00
|
|
|
type: 'error'
|
2018-04-09 14:10:25 +02:00
|
|
|
})
|
2022-04-19 14:05:32 +02:00
|
|
|
})
|
2018-04-09 16:43:36 +02:00
|
|
|
return 'started'
|
2022-06-15 16:24:25 +02:00
|
|
|
}
|
|
|
|
const onScroll = (event: Event) => {
|
2019-05-16 16:43:32 +02:00
|
|
|
if (
|
2022-06-15 16:24:25 +02:00
|
|
|
(event.target as HTMLElement)!.clientHeight + (event.target as HTMLElement)!.scrollTop >=
|
|
|
|
document.getElementById('scroller')!.scrollHeight - 10 &&
|
|
|
|
!lazyLoading
|
2019-05-16 16:43:32 +02:00
|
|
|
) {
|
2022-06-15 16:24:25 +02:00
|
|
|
store
|
|
|
|
.dispatch(`${space}/${ACTION_TYPES.LAZY_FETCH_TIMELINE}`, {
|
|
|
|
list_id: list_id.value,
|
|
|
|
status: timeline.value[timeline.value.length - 1]
|
2021-09-13 19:02:51 +02:00
|
|
|
})
|
|
|
|
.catch(() => {
|
2022-06-15 16:24:25 +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-09 16:08:52 +02:00
|
|
|
}
|
2021-07-25 16:31:32 +02:00
|
|
|
|
2022-06-15 16:24:25 +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)
|
2022-12-13 13:50:48 +01:00
|
|
|
store.commit(`${space}/${MUTATION_TYPES.MERGE_UNREADS}`)
|
2018-04-21 08:53:06 +02:00
|
|
|
}
|
2022-06-15 16:24:25 +02:00
|
|
|
}
|
|
|
|
const reload = async () => {
|
|
|
|
store.commit(`TimelineSpace/${TIMELINE_MUTATION.CHANGE_LOADING}`, true)
|
2018-07-02 14:53:09 +02:00
|
|
|
try {
|
2022-06-15 16:24:25 +02:00
|
|
|
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'),
|
2022-04-19 14:05:32 +02:00
|
|
|
type: 'error'
|
2018-06-10 08:00:33 +02:00
|
|
|
})
|
2022-04-19 14:05:32 +02:00
|
|
|
})
|
2022-06-15 16:24:25 +02:00
|
|
|
store.dispatch(`${space}/${ACTION_TYPES.START_STREAMING}`, list_id.value).catch(() => {
|
|
|
|
ElMessage({
|
|
|
|
message: i18n.t('message.start_streaming_error'),
|
2022-04-19 14:05:32 +02:00
|
|
|
type: 'error'
|
2018-07-02 14:53:09 +02:00
|
|
|
})
|
2022-04-19 14:05:32 +02:00
|
|
|
})
|
2018-07-02 14:53:09 +02:00
|
|
|
} finally {
|
2022-06-15 16:24:25 +02:00
|
|
|
store.commit(`TimelineSpace/${TIMELINE_MUTATION.CHANGE_LOADING}`, false)
|
2018-07-02 14:53:09 +02:00
|
|
|
}
|
2022-06-15 16:24:25 +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:52:00 +02:00
|
|
|
}
|
2022-06-15 16:24:25 +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:52:00 +02:00
|
|
|
}
|
2022-06-15 16:24:25 +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-15 16:24:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
scroller,
|
|
|
|
timeline,
|
|
|
|
focusedId,
|
|
|
|
modalOpened,
|
|
|
|
updateToot,
|
|
|
|
deleteToot,
|
|
|
|
focusSidebar,
|
|
|
|
focusToot,
|
|
|
|
openSideBar,
|
|
|
|
heading,
|
2022-12-13 13:50:48 +01:00
|
|
|
upper,
|
|
|
|
unreads
|
2022-06-15 16:24:25 +02:00
|
|
|
}
|
2022-04-19 14:05:32 +02:00
|
|
|
}
|
2022-06-15 16:24:25 +02:00
|
|
|
})
|
2018-04-09 01:43:11 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2021-07-23 15:16:27 +02:00
|
|
|
.list-timeline {
|
|
|
|
height: 100%;
|
|
|
|
overflow: auto;
|
|
|
|
scroll-behavior: auto;
|
2018-04-21 08:53:06 +02:00
|
|
|
|
2021-07-23 15:16:27 +02:00
|
|
|
.scroller {
|
|
|
|
height: 100%;
|
2018-04-21 08:53:06 +02:00
|
|
|
}
|
|
|
|
|
2021-07-23 15:16:27 +02:00
|
|
|
.upper {
|
|
|
|
position: fixed;
|
|
|
|
bottom: 20px;
|
|
|
|
right: 20px;
|
|
|
|
}
|
2018-10-31 15:11:11 +01:00
|
|
|
|
2021-07-23 15:16:27 +02:00
|
|
|
.upper-with-side-bar {
|
|
|
|
position: fixed;
|
|
|
|
bottom: 20px;
|
|
|
|
right: calc(20px + var(--current-sidebar-width));
|
|
|
|
transition: all 0.5s;
|
|
|
|
}
|
2022-04-22 17:13:04 +02:00
|
|
|
|
|
|
|
.upper-icon {
|
|
|
|
padding: 3px;
|
|
|
|
}
|
2022-12-13 13:50:48 +01:00
|
|
|
|
|
|
|
.unread {
|
|
|
|
position: fixed;
|
|
|
|
right: 24px;
|
|
|
|
top: 52px;
|
|
|
|
background-color: rgba(0, 0, 0, 0.6);
|
|
|
|
color: #ffffff;
|
|
|
|
padding: 4px 8px;
|
|
|
|
border-radius: 0 0 2px 2px;
|
|
|
|
z-index: 1;
|
|
|
|
|
|
|
|
&:empty {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
2018-10-31 15:11:11 +01:00
|
|
|
}
|
2018-04-09 01:43:11 +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>
|