Skip to content

Commit

Permalink
fix(chat): create new conversation on logo click (Issue #2369) (#2725)
Browse files Browse the repository at this point in the history
Co-authored-by: Magomed-Elbi Dzhukalaev <[email protected]>
Co-authored-by: Ilya Bondar <[email protected]>
  • Loading branch information
3 people authored Dec 4, 2024
1 parent 9c409da commit 02786fc
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions apps/chat/src/components/Header/Logo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,29 @@ import { useRouter } from 'next/router';

import { ApiUtils } from '@/src/utils/server/api';

import { useAppSelector } from '@/src/store/hooks';
import {
ConversationsActions,
ConversationsSelectors,
} from '@/src/store/conversations/conversations.reducers';
import { useAppDispatch, useAppSelector } from '@/src/store/hooks';
import { SettingsSelectors } from '@/src/store/settings/settings.reducers';
import { UISelectors } from '@/src/store/ui/ui.reducers';

import { DEFAULT_CONVERSATION_NAME } from '@/src/constants/default-ui-settings';

import { Feature } from '@epam/ai-dial-shared';
import cssEscape from 'css.escape';

export const Logo = () => {
const router = useRouter();
const dispatch = useAppDispatch();

const areConversationsLoaded = useAppSelector(
ConversationsSelectors.areConversationsUploaded,
);
const isActiveNewConversationRequest = useAppSelector(
ConversationsSelectors.selectIsActiveNewConversationRequest,
);
const customLogo = useAppSelector(UISelectors.selectCustomLogo);
const isCustomLogoFeatureEnabled = useAppSelector((state) =>
SettingsSelectors.isFeatureEnabled(state, Feature.CustomLogo),
Expand All @@ -22,8 +35,21 @@ export const Logo = () => {
customLogo &&
`/api/${ApiUtils.encodeApiUrl(customLogo)}`;

const createNewConversation = () => {
if (!areConversationsLoaded || isActiveNewConversationRequest) return;
dispatch(
ConversationsActions.createNewConversations({
names: [DEFAULT_CONVERSATION_NAME],
}),
);
dispatch(ConversationsActions.resetSearch());
};

const handleLogoClick = () => {
router.push('/');
if (router.route === '/') createNewConversation();
else {
router.push('/').then(createNewConversation);
}
};

return (
Expand Down

0 comments on commit 02786fc

Please sign in to comment.