Skip to content

Commit

Permalink
メッセージ入力欄を下に
Browse files Browse the repository at this point in the history
  • Loading branch information
nokhnaton committed Jan 26, 2025
1 parent 135e163 commit 0820539
Show file tree
Hide file tree
Showing 5 changed files with 277 additions and 191 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { computed, ref, type ShallowRef } from 'vue'

Check warning on line 1 in src/components/Main/MainView/ChannelView/ChannelViewContent/composables/useChannelView.ts

View check run for this annotation

Codecov / codecov/patch

src/components/Main/MainView/ChannelView/ChannelViewContent/composables/useChannelView.ts#L1

Added line #L1 was not covered by tests
import useChannelMessageFetcher from './useChannelMessageFetcher'
import { useChannelsStore } from '/@/store/entities/channels'
import { useSubscriptionStore } from '/@/store/domain/subscription'
export const useChannelView = ({
channelId,
entryMessageId,
scrollerEle
}: {

Check warning on line 9 in src/components/Main/MainView/ChannelView/ChannelViewContent/composables/useChannelView.ts

View check run for this annotation

Codecov / codecov/patch

src/components/Main/MainView/ChannelView/ChannelViewContent/composables/useChannelView.ts#L5-L9

Added lines #L5 - L9 were not covered by tests
channelId: string
entryMessageId?: string
scrollerEle: ShallowRef<{ $el: HTMLDivElement } | undefined>
}) => {
const isMessageShow = ref(false)

Check warning on line 14 in src/components/Main/MainView/ChannelView/ChannelViewContent/composables/useChannelView.ts

View check run for this annotation

Codecov / codecov/patch

src/components/Main/MainView/ChannelView/ChannelViewContent/composables/useChannelView.ts#L13-L14

Added lines #L13 - L14 were not covered by tests

const {
messageIds,
isReachedEnd,
isReachedLatest,
isLoading,
lastLoadingDirection,
onLoadFormerMessagesRequest,
onLoadLatterMessagesRequest
} = useChannelMessageFetcher(scrollerEle, { channelId, entryMessageId })

Check warning on line 24 in src/components/Main/MainView/ChannelView/ChannelViewContent/composables/useChannelView.ts

View check run for this annotation

Codecov / codecov/patch

src/components/Main/MainView/ChannelView/ChannelViewContent/composables/useChannelView.ts#L16-L24

Added lines #L16 - L24 were not covered by tests

const { channelsMap } = useChannelsStore()
const isArchived = computed(
() => channelsMap.value.get(channelId)?.archived ?? false
)

Check warning on line 29 in src/components/Main/MainView/ChannelView/ChannelViewContent/composables/useChannelView.ts

View check run for this annotation

Codecov / codecov/patch

src/components/Main/MainView/ChannelView/ChannelViewContent/composables/useChannelView.ts#L26-L29

Added lines #L26 - L29 were not covered by tests

const { unreadChannelsMap } = useSubscriptionStore()
const resetIsReachedLatest = () => {
if (!unreadChannelsMap.value.get(channelId)) return
isReachedLatest.value = false
}

Check warning on line 35 in src/components/Main/MainView/ChannelView/ChannelViewContent/composables/useChannelView.ts

View check run for this annotation

Codecov / codecov/patch

src/components/Main/MainView/ChannelView/ChannelViewContent/composables/useChannelView.ts#L31-L35

Added lines #L31 - L35 were not covered by tests

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
})
}

Check warning on line 45 in src/components/Main/MainView/ChannelView/ChannelViewContent/composables/useChannelView.ts

View check run for this annotation

Codecov / codecov/patch

src/components/Main/MainView/ChannelView/ChannelViewContent/composables/useChannelView.ts#L37-L45

Added lines #L37 - L45 were not covered by tests

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
}
}

Check warning on line 54 in src/components/Main/MainView/ChannelView/ChannelViewContent/composables/useChannelView.ts

View check run for this annotation

Codecov / codecov/patch

src/components/Main/MainView/ChannelView/ChannelViewContent/composables/useChannelView.ts#L47-L54

Added lines #L47 - L54 were not covered by tests

return {
isMessageShow,
messageIds,
isReachedEnd,
isReachedLatest,
isLoading,
lastLoadingDirection,
onLoadFormerMessagesRequest,
onLoadLatterMessagesRequest,
isArchived,
resetIsReachedLatest,
showToNewMessageButton,
toNewMessage,
handleScroll
}
}

Check warning on line 71 in src/components/Main/MainView/ChannelView/ChannelViewContent/composables/useChannelView.ts

View check run for this annotation

Codecov / codecov/patch

src/components/Main/MainView/ChannelView/ChannelViewContent/composables/useChannelView.ts#L56-L71

Added lines #L56 - L71 were not covered by tests
7 changes: 5 additions & 2 deletions src/components/Main/MainView/MessageInput/MessageInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div
ref="containerEle"
:class="$style.container"
:data-is-mobile="$boolAttr(isMobile)"
:data-is-mobile="$boolAttr(forceMobileStyle || isMobile)"

Check warning on line 5 in src/components/Main/MainView/MessageInput/MessageInput.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Main/MainView/MessageInput/MessageInput.vue#L5

Added line #L5 was not covered by tests
>
<button
v-if="showToNewMessageButton"
Expand Down Expand Up @@ -36,7 +36,9 @@
v-model="state.text"
:channel-id="channelId"
:is-posting="isPosting"
:shrink-to-one-line="isMobile && isLeftControlsExpanded"
:shrink-to-one-line="

Check warning on line 39 in src/components/Main/MainView/MessageInput/MessageInput.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Main/MainView/MessageInput/MessageInput.vue#L39

Added line #L39 was not covered by tests
(forceMobileStyle || isMobile) && isLeftControlsExpanded
"
@focus="onFocus"
@blur="onBlur"
@add-attachments="onAddAttachments"
Expand Down Expand Up @@ -85,6 +87,7 @@ const props = defineProps<{
channelId: ChannelId | DMChannelId
typingUsers: UserId[]
showToNewMessageButton: boolean
forceMobileStyle?: boolean
}>()
const emit = defineEmits<{
(e: 'clickToNewMessageButton'): void
Expand Down
149 changes: 85 additions & 64 deletions src/components/Main/MainView/QallView/QallMessageView.vue
Original file line number Diff line number Diff line change
@@ -1,64 +1,3 @@
<template>
<div
:class="$style.container"
:data-is-not-messages-show="$boolAttr(!isMessageShow)"
>
<scroll-loading-bar
:class="$style.loadingBar"
:show="isLoading && isMessageShow"
/>
<transition name="fade-bottom" mode="out-in">
<messages-scroller
v-if="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>
<div :class="$style.uiElement">
<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>
</div>
</template>

<script lang="ts" setup>
import MessagesScroller from '/@/components/Main/MainView/MessagesScroller/MessagesScroller.vue'
import MessageInput from '/@/components/Main/MainView/MessageInput/MessageInput.vue'
Expand Down Expand Up @@ -120,15 +59,97 @@ const handleScroll = () => {
}
</script>

<template>
<div
:class="$style.container"
:data-is-not-messages-show="$boolAttr(!isMessageShow)"

Check warning on line 65 in src/components/Main/MainView/QallView/QallMessageView.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Main/MainView/QallView/QallMessageView.vue#L63-L65

Added lines #L63 - L65 were not covered by tests
>
<div :class="$style.mainViewConteiner">
<div :class="$style.messageContainer">
<scroll-loading-bar
:class="$style.loadingBar"
:show="isLoading && isMessageShow"
/>
<transition name="fade-bottom" mode="out-in">
<messages-scroller
v-if="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"

Check warning on line 85 in src/components/Main/MainView/QallView/QallMessageView.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Main/MainView/QallView/QallMessageView.vue#L67-L85

Added lines #L67 - L85 were not covered by tests
>
<template
#default="{ messageId, onChangeHeight, onEntryMessageLoaded }"

Check warning on line 88 in src/components/Main/MainView/QallView/QallMessageView.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Main/MainView/QallView/QallMessageView.vue#L88

Added line #L88 was not covered by tests
>
<message-element
:class="$style.element"
:message-id="messageId"
:is-archived="isArchived"
@change-height="onChangeHeight"
@entry-message-loaded="onEntryMessageLoaded"
/>

Check warning on line 96 in src/components/Main/MainView/QallView/QallMessageView.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Main/MainView/QallView/QallMessageView.vue#L90-L96

Added lines #L90 - L96 were not covered by tests
</template>
</messages-scroller>
</transition>
<div :class="$style.uiElement">
<FormButton
label="メッセージを表示"
@click="

Check warning on line 103 in src/components/Main/MainView/QallView/QallMessageView.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Main/MainView/QallView/QallMessageView.vue#L98-L103

Added lines #L98 - L103 were not covered by tests
() => {
if (isMessageShow) {
isMessageShow = false
toNewMessage('smooth')
} else {
isMessageShow = true
nextTick(() => toNewMessage())
}
}
"
/>
</div>
</div>
<slot name="default"></slot>
</div>
<message-input
:channel-id="channelId"
:typing-users="typingUsers"
:show-to-new-message-button="showToNewMessageButton"
force-mobile-style
@click-to-new-message-button="toNewMessage"
/>
</div>

Check warning on line 126 in src/components/Main/MainView/QallView/QallMessageView.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Main/MainView/QallView/QallMessageView.vue#L114-L126

Added lines #L114 - L126 were not covered by tests
</template>

<style lang="scss" module>
.container {
display: flex;
flex: 1 1;
height: 100%;
width: 100%;
flex-direction: column;
justify-content: end;
}
.mainViewConteiner {
flex-grow: 1;
position: relative;
width: 100%;
}
.messageContainer {
position: absolute;
bottom: 0;
right: 0;
width: 30%;
height: 100%;
display: flex;
flex: 1 1;
flex-direction: column;
justify-content: end;
&[data-is-not-messages-show] {
pointer-events: none;
}
Expand Down
Loading

0 comments on commit 0820539

Please sign in to comment.