-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
104 additions
and
101 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
203 changes: 103 additions & 100 deletions
203
apps/chat/src/components/Chat/ChatView/hooks/useChatViewEnablers.ts
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 |
---|---|---|
@@ -1,113 +1,116 @@ | ||
import { isSmallScreen } from '@/src/utils/app/mobile'; | ||
import { useMemo } from 'react'; | ||
import { Feature } from '@epam/ai-dial-shared'; | ||
|
||
import { isSmallScreen } from '@/src/utils/app/mobile'; | ||
|
||
import { Conversation } from '@/src/types/chat'; | ||
import { EntityType } from '@/src/types/common'; | ||
import { ErrorMessage } from '@/src/types/error'; | ||
|
||
import { Feature } from '@epam/ai-dial-shared'; | ||
|
||
interface UseChatViewEnablersProps { | ||
enabledFeatures: Set<Feature>; | ||
isAnyMenuOpen: boolean; | ||
isCompareMode: boolean; | ||
isExternal: boolean; | ||
isIsolatedView: boolean; | ||
isLastMessageError: boolean; | ||
isMessageStreaming: boolean; | ||
isPlayback: boolean; | ||
isReplay: boolean; | ||
modelError: ErrorMessage | undefined; | ||
notAllowedType: EntityType | null; | ||
selectedConversations: Conversation[]; | ||
enabledFeatures: Set<Feature>; | ||
isAnyMenuOpen: boolean; | ||
isCompareMode: boolean; | ||
isExternal: boolean; | ||
isIsolatedView: boolean; | ||
isLastMessageError: boolean; | ||
isMessageStreaming: boolean; | ||
isPlayback: boolean; | ||
isReplay: boolean; | ||
modelError: ErrorMessage | undefined; | ||
notAllowedType: EntityType | null; | ||
selectedConversations: Conversation[]; | ||
} | ||
|
||
export const useChatViewEnablers = ({ | ||
enabledFeatures, | ||
isAnyMenuOpen, | ||
isCompareMode, | ||
isExternal, | ||
isIsolatedView, | ||
isPlayback, | ||
isReplay, | ||
isMessageStreaming, | ||
modelError, | ||
notAllowedType, | ||
selectedConversations, | ||
isLastMessageError, | ||
enabledFeatures, | ||
isAnyMenuOpen, | ||
isCompareMode, | ||
isExternal, | ||
isIsolatedView, | ||
isPlayback, | ||
isReplay, | ||
isMessageStreaming, | ||
modelError, | ||
notAllowedType, | ||
selectedConversations, | ||
isLastMessageError, | ||
}: UseChatViewEnablersProps) => { | ||
const showFloatingOverlay = | ||
isSmallScreen() && isAnyMenuOpen && !isIsolatedView; | ||
const showChatSection = !modelError; | ||
const showErrorMessage = modelError; | ||
const showFloatingOverlay = | ||
isSmallScreen() && isAnyMenuOpen && !isIsolatedView; | ||
const showChatSection = !modelError; | ||
const showErrorMessage = modelError; | ||
|
||
const isLikesEnabled = useMemo( | ||
() => enabledFeatures.has(Feature.Likes), | ||
[enabledFeatures], | ||
); | ||
const showPlaybackControls = useMemo(() => isPlayback, [isPlayback]); | ||
const showTopChatInfo = useMemo( | ||
() => enabledFeatures.has(Feature.TopChatInfo), | ||
[enabledFeatures], | ||
); | ||
const showEmptyChatSettings = useMemo( | ||
() => enabledFeatures.has(Feature.EmptyChatSettings), | ||
[enabledFeatures], | ||
); | ||
const showTopSettings = useMemo( | ||
() => enabledFeatures.has(Feature.TopSettings), | ||
[enabledFeatures], | ||
); | ||
const showChatControls = useMemo( | ||
() => isPlayback || !notAllowedType, | ||
[isPlayback, notAllowedType], | ||
); | ||
const showLastMessageRegenerate = useMemo( | ||
() => | ||
!isReplay && | ||
!isPlayback && | ||
!isExternal && | ||
!isMessageStreaming && | ||
!isLastMessageError, | ||
[isReplay, isPlayback, isExternal, isMessageStreaming, isLastMessageError], | ||
); | ||
const showNotAllowedModel = useMemo( | ||
() => !isPlayback && notAllowedType, | ||
[isPlayback, notAllowedType], | ||
); | ||
const showModelSelect = useMemo( | ||
() => | ||
enabledFeatures.has(Feature.TopChatModelSettings) && | ||
!isPlayback && | ||
!isExternal, | ||
[enabledFeatures, isPlayback, isExternal], | ||
); | ||
const showClearConversations = useMemo( | ||
() => | ||
enabledFeatures.has(Feature.TopClearConversation) && | ||
!isPlayback && | ||
!isReplay && | ||
!isMessageStreaming && | ||
!isExternal, | ||
[enabledFeatures, isExternal, isPlayback, isReplay, isMessageStreaming], | ||
); | ||
const showCompareChatSection = useMemo( | ||
() => isCompareMode && selectedConversations.length < 2, | ||
[isCompareMode, selectedConversations.length], | ||
); | ||
const isLikesEnabled = useMemo( | ||
() => enabledFeatures.has(Feature.Likes), | ||
[enabledFeatures], | ||
); | ||
const showPlaybackControls = useMemo(() => isPlayback, [isPlayback]); | ||
const showTopChatInfo = useMemo( | ||
() => enabledFeatures.has(Feature.TopChatInfo), | ||
[enabledFeatures], | ||
); | ||
const showEmptyChatSettings = useMemo( | ||
() => enabledFeatures.has(Feature.EmptyChatSettings), | ||
[enabledFeatures], | ||
); | ||
const showTopSettings = useMemo( | ||
() => enabledFeatures.has(Feature.TopSettings), | ||
[enabledFeatures], | ||
); | ||
const showChatControls = useMemo( | ||
() => isPlayback || !notAllowedType, | ||
[isPlayback, notAllowedType], | ||
); | ||
const showLastMessageRegenerate = useMemo( | ||
() => | ||
!isReplay && | ||
!isPlayback && | ||
!isExternal && | ||
!isMessageStreaming && | ||
!isLastMessageError, | ||
[isReplay, isPlayback, isExternal, isMessageStreaming, isLastMessageError], | ||
); | ||
const showNotAllowedModel = useMemo( | ||
() => !isPlayback && notAllowedType, | ||
[isPlayback, notAllowedType], | ||
); | ||
const showModelSelect = useMemo( | ||
() => | ||
enabledFeatures.has(Feature.TopChatModelSettings) && | ||
!isPlayback && | ||
!isExternal, | ||
[enabledFeatures, isPlayback, isExternal], | ||
); | ||
const showClearConversations = useMemo( | ||
() => | ||
enabledFeatures.has(Feature.TopClearConversation) && | ||
!isPlayback && | ||
!isReplay && | ||
!isMessageStreaming && | ||
!isExternal, | ||
[enabledFeatures, isExternal, isPlayback, isReplay, isMessageStreaming], | ||
); | ||
const showCompareChatSection = useMemo( | ||
() => isCompareMode && selectedConversations.length < 2, | ||
[isCompareMode, selectedConversations.length], | ||
); | ||
|
||
return { | ||
isLikesEnabled, | ||
showChatControls, | ||
showChatSection, | ||
showClearConversations, | ||
showCompareChatSection, | ||
showEmptyChatSettings, | ||
showErrorMessage, | ||
showFloatingOverlay, | ||
showLastMessageRegenerate, | ||
showModelSelect, | ||
showNotAllowedModel, | ||
showPlaybackControls, | ||
showTopChatInfo, | ||
showTopSettings, | ||
}; | ||
return { | ||
isLikesEnabled, | ||
showChatControls, | ||
showChatSection, | ||
showClearConversations, | ||
showCompareChatSection, | ||
showEmptyChatSettings, | ||
showErrorMessage, | ||
showFloatingOverlay, | ||
showLastMessageRegenerate, | ||
showModelSelect, | ||
showNotAllowedModel, | ||
showPlaybackControls, | ||
showTopChatInfo, | ||
showTopSettings, | ||
}; | ||
}; |