-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4468 from traPtitech/feat/qall_message_viewer
メッセージビューワーの実装
- Loading branch information
Showing
4 changed files
with
164 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
src/components/Main/MainView/QallView/QallMessageView.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
<template> | ||
<div :class="$style.container"> | ||
<scroll-loading-bar | ||
:class="$style.loadingBar" | ||
:show="isLoading && isMessageShow" | ||
/> | ||
<transition name="fade-bottom" mode="out-in"> | ||
<messages-scroller | ||
v-show="isMessageShow" | ||
ref="scrollerEle" | ||
:message-ids="messageIds" | ||
:is-reached-end="isReachedEnd" | ||
:is-reached-latest="isReachedLatest" | ||
:is-loading="isLoading" | ||
:last-loading-direction="lastLoadingDirection" | ||
@request-load-former="onLoadFormerMessagesRequest" | ||
@request-load-latter="onLoadLatterMessagesRequest" | ||
@scroll-passive="handleScroll" | ||
@reset-is-reached-latest="resetIsReachedLatest" | ||
> | ||
<template | ||
#default="{ messageId, onChangeHeight, onEntryMessageLoaded }" | ||
> | ||
<message-element | ||
:class="$style.element" | ||
:message-id="messageId" | ||
:is-archived="isArchived" | ||
@change-height="onChangeHeight" | ||
@entry-message-loaded="onEntryMessageLoaded" | ||
/> | ||
</template> | ||
</messages-scroller> | ||
</transition> | ||
<FormButton | ||
label="メッセージを表示" | ||
@click=" | ||
() => { | ||
if (isMessageShow) { | ||
isMessageShow = false | ||
toNewMessage('smooth') | ||
} else { | ||
isMessageShow = true | ||
nextTick(() => toNewMessage()) | ||
} | ||
} | ||
" | ||
/> | ||
<message-input | ||
:channel-id="channelId" | ||
:typing-users="typingUsers" | ||
:show-to-new-message-button="showToNewMessageButton" | ||
@click-to-new-message-button="toNewMessage" | ||
/> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import MessagesScroller from '/@/components/Main/MainView/MessagesScroller/MessagesScroller.vue' | ||
import MessageInput from '/@/components/Main/MainView/MessageInput/MessageInput.vue' | ||
import ScrollLoadingBar from '/@/components/Main/MainView/ScrollLoadingBar.vue' | ||
import { computed, nextTick, ref, shallowRef } from 'vue' | ||
import type { ChannelId, UserId } from '/@/types/entity-ids' | ||
import useChannelMessageFetcher from '../ChannelView/ChannelViewContent/composables/useChannelMessageFetcher' | ||
import { useChannelsStore } from '/@/store/entities/channels' | ||
import MessageElement from '/@/components/Main/MainView/MessageElement/MessageElement.vue' | ||
import { useSubscriptionStore } from '/@/store/domain/subscription' | ||
import FormButton from '/@/components/UI/FormButton.vue' | ||
const props = defineProps<{ | ||
channelId: ChannelId | ||
typingUsers: UserId[] | ||
}>() | ||
const isMessageShow = ref(false) | ||
const scrollerEle = shallowRef<{ $el: HTMLDivElement } | undefined>() | ||
const { | ||
messageIds, | ||
isReachedEnd, | ||
isReachedLatest, | ||
isLoading, | ||
lastLoadingDirection, | ||
onLoadFormerMessagesRequest, | ||
onLoadLatterMessagesRequest | ||
} = useChannelMessageFetcher(scrollerEle, props) | ||
const { channelsMap } = useChannelsStore() | ||
const isArchived = computed( | ||
() => channelsMap.value.get(props.channelId)?.archived ?? false | ||
) | ||
const { unreadChannelsMap } = useSubscriptionStore() | ||
const resetIsReachedLatest = () => { | ||
if (!unreadChannelsMap.value.get(props.channelId)) return | ||
isReachedLatest.value = false | ||
} | ||
const showToNewMessageButton = ref(false) | ||
const toNewMessage = (behavior?: ScrollBehavior) => { | ||
if (!scrollerEle.value) return | ||
showToNewMessageButton.value = false | ||
scrollerEle.value.$el.scrollTo({ | ||
top: scrollerEle.value.$el.scrollHeight, | ||
behavior: behavior | ||
}) | ||
} | ||
const handleScroll = () => { | ||
if (scrollerEle.value === undefined || isLoading.value) return | ||
const { scrollTop, scrollHeight, clientHeight } = scrollerEle.value.$el | ||
showToNewMessageButton.value = scrollHeight - 2 * clientHeight > scrollTop | ||
if (!isReachedLatest.value) { | ||
showToNewMessageButton.value = true | ||
} | ||
} | ||
</script> | ||
|
||
<style lang="scss" module> | ||
.container { | ||
display: flex; | ||
flex: 1 1; | ||
flex-direction: column; | ||
justify-content: end; | ||
position: relative; | ||
height: 100%; | ||
width: 100%; | ||
} | ||
.loadingBar { | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
right: 0; | ||
height: 12px; | ||
z-index: $z-index-message-loading; | ||
} | ||
.unreadSeparator { | ||
color: $theme-accent-notification-default; | ||
} | ||
.dateSeparator { | ||
@include color-ui-secondary; | ||
} | ||
.element { | ||
margin: 4px 0; | ||
contain: content; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters