-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
Feat/qall UI
- Loading branch information
There are no files selected for viewing
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 Codecov / codecov/patchsrc/components/Main/MainView/ChannelView/ChannelViewContent/composables/useChannelView.ts#L1
|
||
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 Codecov / codecov/patchsrc/components/Main/MainView/ChannelView/ChannelViewContent/composables/useChannelView.ts#L5-L9
|
||
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 Codecov / codecov/patchsrc/components/Main/MainView/ChannelView/ChannelViewContent/composables/useChannelView.ts#L13-L14
|
||
|
||
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 Codecov / codecov/patchsrc/components/Main/MainView/ChannelView/ChannelViewContent/composables/useChannelView.ts#L16-L24
|
||
|
||
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 Codecov / codecov/patchsrc/components/Main/MainView/ChannelView/ChannelViewContent/composables/useChannelView.ts#L26-L29
|
||
|
||
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 Codecov / codecov/patchsrc/components/Main/MainView/ChannelView/ChannelViewContent/composables/useChannelView.ts#L31-L35
|
||
|
||
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 Codecov / codecov/patchsrc/components/Main/MainView/ChannelView/ChannelViewContent/composables/useChannelView.ts#L37-L45
|
||
|
||
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 Codecov / codecov/patchsrc/components/Main/MainView/ChannelView/ChannelViewContent/composables/useChannelView.ts#L47-L54
|
||
|
||
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 Codecov / codecov/patchsrc/components/Main/MainView/ChannelView/ChannelViewContent/composables/useChannelView.ts#L56-L71
|