Skip to content

Commit

Permalink
chore: lint & format
Browse files Browse the repository at this point in the history
  • Loading branch information
sergesha committed Aug 27, 2024
1 parent 985b8b0 commit 0f1ad97
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 101 deletions.
2 changes: 1 addition & 1 deletion apps/chat/src/components/Chat/ChatView/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import { ModelsActions } from '@/src/store/models/models.reducers';
import { ChatCompareRotate } from './components/ChatCompareRotate';
import { ErrorMessageDiv } from './components/ErrorMessageDiv';
import { NotAllowedModel } from './components/NotAllowedModel';
import { ChatMessages } from './ChatMessages/ChatMessages';

import { ChatCompareSection } from './ChatCompareSection';
import { ChatControlsSection } from './ChatControlsSection';
import { ChatHeaderSection } from './ChatHeaderSection';
import { ChatMessages } from './ChatMessages/ChatMessages';
import { ChatSettingsEmptySection } from './ChatSettingsEmptySection';
import { ChatSettingsSection } from './ChatSettingsSection';

Expand Down
203 changes: 103 additions & 100 deletions apps/chat/src/components/Chat/ChatView/hooks/useChatViewEnablers.ts
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,
};
};

0 comments on commit 0f1ad97

Please sign in to comment.