Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

画面上部に常にメッセージの日付を表示 #3747

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<template>
<div :class="$style.container">
<div ref="containerRef" :class="$style.container">
<scroll-loading-bar :class="$style.loadingBar" :show="isLoading" />
<shown-message-date
v-if="shownMessageDateValue"
:shown-message-date="shownMessageDateValue"
:channel-id="channelId"
/>
<messages-scroller
ref="scrollerEle"
:message-ids="messageIds"
Expand All @@ -9,10 +14,12 @@
:is-loading="isLoading"
:entry-message-id="entryMessageId"
:last-loading-direction="lastLoadingDirection"
:container-ref="containerRef"
@request-load-former="onLoadFormerMessagesRequest"
@request-load-latter="onLoadLatterMessagesRequest"
@scroll.passive="handleScroll"
@reset-is-reached-latest="resetIsReachedLatest"
@end-separator-intersected="onEndSeparatorIntersected"
>
<template #default="{ messageId, onChangeHeight, onEntryMessageLoaded }">
<messages-scroller-separator
Expand All @@ -31,8 +38,10 @@
:is-archived="isArchived"
:is-entry-message="messageId === entryMessageId"
:pinned-user-id="messagePinnedUserMap.get(messageId)"
:container-ref="containerRef"
@change-height="onChangeHeight"
@entry-message-loaded="onEntryMessageLoaded"
@intersected="onMessageIntersected"
/>
</template>
</messages-scroller>
Expand Down Expand Up @@ -63,6 +72,7 @@ import { useRouter } from 'vue-router'
import { constructChannelPath } from '/@/router'
import useChannelPath from '/@/composables/useChannelPath'
import { useSubscriptionStore } from '/@/store/domain/subscription'
import ShownMessageDate from './ShownMessageDate.vue'

const props = defineProps<{
channelId: ChannelId
Expand Down Expand Up @@ -141,6 +151,15 @@ const handleScroll = () => {
showToNewMessageButton.value = true
}
}

const containerRef = ref<HTMLDivElement | null>(null)
const shownMessageDateValue = ref<string | undefined>()
const onMessageIntersected = (createdAt: string) => {
shownMessageDateValue.value = getFullDayString(new Date(createdAt))
}
const onEndSeparatorIntersected = () => {
shownMessageDateValue.value = undefined
}
</script>

<style lang="scss" module>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<template>
<div :class="$style.container">
<div :class="$style.innerContainer">
{{ shownMessageDate }}
</div>
</div>
</template>

<script lang="ts" setup>
import type { ChannelId } from '/@/types/entity-ids'

defineProps<{
channelId: ChannelId
shownMessageDate: string
}>()
</script>

<style lang="scss" module>
.container {
position: absolute;
inset: 12px 0 auto;
margin: 0 auto;
width: 140px;
z-index: $z-index-shown-message-date;
}
.innerContainer {
background-color: $theme-background-primary-default;
border-radius: 24px;
padding: 4px 16px;
text-align: center;
font-weight: bold;
border: 1px solid $theme-ui-tertiary-default;
}
</style>
24 changes: 23 additions & 1 deletion src/components/Main/MainView/MessageElement/MessageElement.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import MessageStampList from './MessageStampList.vue'
import MessagePinned from './MessagePinned.vue'
import MessageContents from './MessageContents.vue'
import MessageTools from '/@/components/Main/MainView/MessageElement/MessageTools.vue'
import { computed, shallowRef, toRef } from 'vue'
import { computed, onMounted, onUnmounted, shallowRef, toRef } from 'vue'
import type { MessageId, UserId } from '/@/types/entity-ids'
import { useResponsiveStore } from '/@/store/ui/responsive'
import type { ChangeHeightData } from './composables/useElementRenderObserver'
Expand All @@ -52,6 +52,7 @@ const props = withDefaults(
pinnedUserId?: UserId
isEntryMessage?: boolean
isArchived?: boolean
containerRef?: HTMLDivElement | null
}>(),
{
isEntryMessage: false,
Expand All @@ -62,6 +63,7 @@ const props = withDefaults(
const emit = defineEmits<{
(e: 'entryMessageLoaded', _relativePos: number): void
(e: 'changeHeight', _data: ChangeHeightData): void
(e: 'intersected', _createdAt: string): void
}>()

const bodyRef = shallowRef<HTMLDivElement | null>(null)
Expand All @@ -83,6 +85,26 @@ useElementRenderObserver(
)

const { isHovered, onMouseEnter, onMouseLeave } = useHover()

const observer = new IntersectionObserver(
entries => {
if (entries[0]?.isIntersecting) {
if (message.value === undefined) return
emit('intersected', message.value.createdAt)
}
},
{
root: props.containerRef,
rootMargin: '0px 0px -100%'
}
)
onMounted(() => {
if (bodyRef.value === null || props.containerRef === undefined) return
observer.observe(bodyRef.value)
})
onUnmounted(() => {
observer.disconnect()
})
</script>

<style lang="scss" module>
Expand Down
26 changes: 26 additions & 0 deletions src/components/Main/MainView/MessagesScroller/MessagesScroller.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
>
<messages-scroller-separator
v-if="isReachedEnd"
ref="endSeparatorEle"
title="これ以上メッセージはありません"
:class="$style.noMoreSeparator"
/>
Expand Down Expand Up @@ -136,6 +137,7 @@ const props = withDefaults(
isLoading?: boolean
entryMessageId?: MessageId
lastLoadingDirection: LoadingDirection
containerRef?: HTMLDivElement | null
}>(),
{
isLoading: false
Expand All @@ -146,6 +148,7 @@ const emit = defineEmits<{
(e: 'requestLoadFormer'): void
(e: 'requestLoadLatter'): void
(e: 'resetIsReachedLatest'): void
(e: 'endSeparatorIntersected'): void
}>()

const { lastScrollPosition } = useMainViewStore()
Expand Down Expand Up @@ -254,6 +257,29 @@ onUnmounted(() => {

const { onClick } = useMarkdownInternalHandler()
useScrollRestoration(rootRef, state)

const endSeparatorEle = shallowRef<{ $el: HTMLDivElement } | undefined>()
const observer = new IntersectionObserver(
entries => {
if (entries[0]?.isIntersecting) {
emit('endSeparatorIntersected')
}
},
{
root: props.containerRef
}
)
watch(
() => props.isReachedEnd,
async () => {
await nextTick()
if (!endSeparatorEle.value || !props.containerRef) return
observer.observe(endSeparatorEle.value.$el)
}
)
onUnmounted(() => {
observer.disconnect()
})
</script>

<style lang="scss" module>
Expand Down
1 change: 1 addition & 0 deletions src/styles/_z-index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ $z-index-message-attachment-video-overlay: 1;
$z-index-message-input-file-close-button: 1;

$z-index-message-loading: 2;
$z-index-shown-message-date: 2;

$z-index-message-element-tools: 3;
$z-index-message-element-tools-menu: 5;
Expand Down