-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OV-42: Add Chat Component #82
Merged
Merged
Changes from 59 commits
Commits
Show all changes
81 commits
Select commit
Hold shift + click to select a range
3c6293f
OV-42: + files structures for a chat box component
lfelix3011 4047a6b
Merge branch 'next' of https://github.com/BinaryStudioAcademy/bsa-202…
lfelix3011 7ffad94
OV-42: + files structures for a chat box component
lfelix3011 dff5b3b
OV-42: * files structures for a chat box component
lfelix3011 6780ebb
OV-42: - files structures for a chat box component
lfelix3011 9e2d1e4
OV-42: + files types, enums and validations in bundle
lfelix3011 e2e0ee7
OV-42: * files types, enums and validations in bundle front
lfelix3011 8f4afac
OV-42: * chat structure to send message to ai
lfelix3011 3dbd725
Merge branch 'next' of https://github.com/BinaryStudioAcademy/bsa-202…
lfelix3011 36f2c02
OV-42: * chat structure to send message to ai to manage state with redux
lfelix3011 252fe70
OV-42: * Improvement in chat strcuture and funcionality
lfelix3011 2c36868
OV-42: * adjust to send message and store values using redux
lfelix3011 ba0591b
OV-42: * adjust to uses the same name that the pr of the backend has …
lfelix3011 2713f1b
OV-42: * adjust to uses all general component form Componets forlder
lfelix3011 1890a4b
Merge branch 'next' of https://github.com/BinaryStudioAcademy/bsa-202…
lfelix3011 0d615a8
OV-42: * adjust to put as it was originally
lfelix3011 f861789
OV-42: * Use Box as="img" to avoid using html tags
lfelix3011 8d79ee3
OV-42: * Use Image Component of ChakraUI
lfelix3011 43948aa
Merge branch 'next' of https://github.com/BinaryStudioAcademy/bsa-202…
lfelix3011 8b1dc7d
OV-42: - chat deleteed request as backend dosent need it
lfelix3011 9251d98
OV-42: - onchange on input as formik manage that change
lfelix3011 0f3870c
OV-42: - aditional path as it just necessary to use ROOT and HTTP Met…
lfelix3011 65b554e
Merge branch 'next' of https://github.com/BinaryStudioAcademy/bsa-202…
lfelix3011 4d7144d
OV-42: - remove chat form and just leave chat footer
lfelix3011 a94a016
OV-42: * use of generic component user avatar
lfelix3011 385a7e4
OV-42: * Use of custom variant for headers
lfelix3011 1ae5406
OV-42: * Unified logic to manage messages respond and request to show…
lfelix3011 45186cc
OV-42: * property name from message to generatedText
lfelix3011 52edee7
OV-42: * use of httpMehtods insted of plain string
lfelix3011 dc6316f
OV-42: * use of relative path for imports
lfelix3011 6df9209
OV-42: * use of relative path for imports and useMemo to group Messages
lfelix3011 7cefade
OV-42: + custom hook to clean up chat
lfelix3011 b44e8df
OV-42: * use of relative path for imports
lfelix3011 e39565a
OV-42: + keepAlaive and credentials for request, to use in chat app
lfelix3011 2911244
OV-42: * message box lenght and space
lfelix3011 1c36f42
OV-42: * use of prettier
lfelix3011 4eb0965
Merge branch 'next' of https://github.com/BinaryStudioAcademy/bsa-202…
lfelix3011 1fd6e86
Merge branch 'next' of https://github.com/BinaryStudioAcademy/bsa-202…
lfelix3011 6d11703
OV-144: + initial helper to transofrm payload to text to AI
lfelix3011 1eecedd
Merge branch 'next' of https://github.com/BinaryStudioAcademy/bsa-202…
lfelix3011 62d62ce
Merge branch 'next' of https://github.com/BinaryStudioAcademy/bsa-202…
lfelix3011 087b3ac
Merge branch 'task/OV-42-add-chat-component' of https://github.com/Bi…
lfelix3011 82d80b9
OV-144: + generate text with AI using chat component
lfelix3011 0aa2b36
OV-166: + add mock icon
JKaypa 45eeef3
Merge remote-tracking branch 'origin/task/OV-42-add-chat-component' i…
JKaypa 2e5906d
Merge branch 'next' of https://github.com/BinaryStudioAcademy/bsa-202…
lfelix3011 c95d555
Merge branch 'next' of https://github.com/BinaryStudioAcademy/bsa-202…
lfelix3011 35b598e
OV-144: * reponse to be an object of title and description insted of …
lfelix3011 e932afe
OV-166: * merge
JKaypa ad4a90c
OV-166: + integreate chat modal
JKaypa b11249e
Merge branch 'task/OV-42-add-chat-component' of https://github.com/Bi…
lfelix3011 2257349
Merge branch 'next' of https://github.com/BinaryStudioAcademy/bsa-202…
lfelix3011 61eddae
OV-42: * styles adjustments to not use sx
lfelix3011 297ad8e
OV-42: * use of prettier
lfelix3011 6c7ac8b
Merge remote-tracking branch 'origin/task/OV-42-add-chat-component' i…
JKaypa 1a3ee35
Merge branch 'task/OV-42-add-chat-component' of github.com:BinaryStud…
JKaypa 59ac100
OV-166: + add open ai icon
JKaypa 2f9ff34
Merge branch 'next' of https://github.com/BinaryStudioAcademy/bsa-202…
lfelix3011 043bfc1
OV-144: * genearete text with corresponding animation and visual
lfelix3011 ea8967b
OV-42: - unsued params
lfelix3011 eb48f1f
Merge branch 'task/OV-42-add-chat-component' of https://github.com/Bi…
lfelix3011 c79bbad
OV-166: * make sugested changes
JKaypa 94875b9
OV-42: * use general loader when waiting respond
lfelix3011 d0f9ceb
Merge branch 'next' of https://github.com/BinaryStudioAcademy/bsa-202…
lfelix3011 2d9f332
OV-42: * adjust in styles format and use of general loader
lfelix3011 ca317b6
Merge branch 'task/OV-42-add-chat-component' of https://github.com/Bi…
lfelix3011 0d490c0
Merge pull request #225 from BinaryStudioAcademy/task/OV-166-add-ai-i…
nikita-remeslov 44d1e65
Merge branch 'next' of https://github.com/BinaryStudioAcademy/bsa-202…
lfelix3011 427079c
OV-144: * suggestion, to make code simplier, and tone not required
lfelix3011 62aa93b
Merge branch 'next' of https://github.com/BinaryStudioAcademy/bsa-202…
lfelix3011 3176164
OV-144: * styles that were remove on last merge
lfelix3011 71eab4a
Merge branch 'next' of https://github.com/BinaryStudioAcademy/bsa-202…
lfelix3011 809d2d8
Merge branch 'task/OV-42-add-chat-component' of https://github.com/Bi…
lfelix3011 4911635
Merge branch 'next' of https://github.com/BinaryStudioAcademy/bsa-202…
lfelix3011 b2299a0
OV-42: * use correct loader and avatars
lfelix3011 9a43874
Merge branch 'task/OV-42-add-chat-component' of https://github.com/Bi…
lfelix3011 c94df94
OV-42: * simplify styles for input and button
lfelix3011 e5413b8
Merge branch 'task/OV-42-add-chat-component' of https://github.com/Bi…
lfelix3011 8677bcf
OV-144: * use route form bundle insted of relative import, and chain …
lfelix3011 ab60c04
Merge pull request #228 from BinaryStudioAcademy/task/OV-144-add-scri…
nikita-remeslov 9e9ba40
OV-42: + merge
sergiy4 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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,2 +1,2 @@ | ||
export { OpenAIRole } from './open-ai-role.enum.js'; | ||
export { ChatPath } from 'shared'; | ||
export { ChatApiPath } from 'shared'; |
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { ApiPath, ContentType } from '~/bundles/common/enums/enums.js'; | ||
import { type Http, HTTPMethod } from '~/framework/http/http.js'; | ||
import { BaseHttpApi } from '~/framework/http-api/http-api.js'; | ||
import { type Storage } from '~/framework/storage/storage.js'; | ||
|
||
import { ChatApiPath } from './enums/enums.js'; | ||
import { | ||
type DeleteChatResponseDto, | ||
type GenerateTextRequestDto, | ||
type GenerateTextResponseDto, | ||
} from './types/types.js'; | ||
|
||
type Constructor = { | ||
baseUrl: string; | ||
http: Http; | ||
storage: Storage; | ||
}; | ||
|
||
class ChatApi extends BaseHttpApi { | ||
public constructor({ baseUrl, http, storage }: Constructor) { | ||
super({ path: ApiPath.CHAT, baseUrl, http, storage }); | ||
} | ||
|
||
public async sendMessage( | ||
payload: GenerateTextRequestDto, | ||
): Promise<GenerateTextResponseDto> { | ||
const response = await this.load( | ||
this.getFullEndpoint(ChatApiPath.ROOT, {}), | ||
{ | ||
method: HTTPMethod.POST, | ||
contentType: ContentType.JSON, | ||
payload: JSON.stringify(payload), | ||
credentials: 'include', | ||
hasAuth: true, | ||
}, | ||
); | ||
|
||
return await response.json<GenerateTextResponseDto>(); | ||
} | ||
|
||
public async deleteChat(): Promise<DeleteChatResponseDto> { | ||
const response = await this.load( | ||
this.getFullEndpoint(ChatApiPath.ROOT, {}), | ||
{ | ||
method: HTTPMethod.DELETE, | ||
contentType: ContentType.JSON, | ||
payload: JSON.stringify({}), | ||
o-nedashkivska marked this conversation as resolved.
Show resolved
Hide resolved
|
||
credentials: 'include', | ||
keepAlive: true, | ||
hasAuth: true, | ||
}, | ||
); | ||
|
||
return await response.json<DeleteChatResponseDto>(); | ||
} | ||
} | ||
|
||
export { ChatApi }; |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { config } from '~/framework/config/config.js'; | ||
import { http } from '~/framework/http/http.js'; | ||
import { storage } from '~/framework/storage/storage.js'; | ||
|
||
import { ChatApi } from './chat-api.js'; | ||
|
||
const chatApi = new ChatApi({ | ||
baseUrl: config.ENV.API.ORIGIN_URL, | ||
storage, | ||
http, | ||
}); | ||
|
||
export { chatApi }; | ||
export { type GenerateTextRequestDto } from './types/types.js'; | ||
export { textGenerationValidationSchema } from './validation-schemas/validation-schemas.js'; |
27 changes: 27 additions & 0 deletions
27
frontend/src/bundles/chat/components/chat-body/chat-body.tsx
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { MessageList } from '~/bundles/chat/components/message-list/message-list.js'; | ||
import { type Message } from '~/bundles/chat/types/types.js'; | ||
import { Box, Loader } from '~/bundles/common/components/components.js'; | ||
import { DataStatus } from '~/bundles/common/enums/enums.js'; | ||
import { useAppSelector } from '~/bundles/common/hooks/hooks.js'; | ||
|
||
type Properties = { | ||
messages: Message[]; | ||
}; | ||
|
||
const ChatBody: React.FC<Properties> = ({ messages }) => { | ||
const { dataStatus } = useAppSelector(({ chat }) => ({ | ||
dataStatus: chat.dataStatus, | ||
})); | ||
|
||
return ( | ||
<Box minHeight="400px" maxHeight="400px" overflowY="auto" mb="2"> | ||
{dataStatus === DataStatus.PENDING ? ( | ||
<Loader /> | ||
) : ( | ||
<MessageList messages={messages} /> | ||
)} | ||
</Box> | ||
); | ||
}; | ||
|
||
export { ChatBody }; |
56 changes: 56 additions & 0 deletions
56
frontend/src/bundles/chat/components/chat-footer/chat-footer.tsx
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { | ||
type GenerateTextRequestDto, | ||
textGenerationValidationSchema, | ||
} from '~/bundles/chat/chat.js'; | ||
import { | ||
Button, | ||
Flex, | ||
FormProvider, | ||
Input, | ||
} from '~/bundles/common/components/components.js'; | ||
import { useAppForm } from '~/bundles/common/hooks/hooks.js'; | ||
|
||
import { DEFAULT_CHAT_FORM_PAYLOAD } from './constants/constants.js'; | ||
|
||
type Properties = { | ||
onSendMessage: (payload: GenerateTextRequestDto) => void; | ||
}; | ||
|
||
const ChatFooter: React.FC<Properties> = ({ onSendMessage }) => { | ||
const form = useAppForm<GenerateTextRequestDto>({ | ||
initialValues: DEFAULT_CHAT_FORM_PAYLOAD, | ||
validationSchema: textGenerationValidationSchema, | ||
onSubmit: (data: GenerateTextRequestDto, { resetForm }) => { | ||
onSendMessage(data); | ||
resetForm(); | ||
}, | ||
}); | ||
|
||
const { handleSubmit, values } = form; | ||
|
||
return ( | ||
<FormProvider value={form}> | ||
<form onSubmit={handleSubmit}> | ||
<Flex alignItems={'flex-start'} w={'100%'} gap={5}> | ||
<Input | ||
type="text" | ||
label="" | ||
placeholder="Send a message" | ||
name="message" | ||
value={values.message} | ||
width="100%" | ||
/> | ||
<Button | ||
type="submit" | ||
label="Send" | ||
size="md" | ||
isDisabled={values.message.trim().length === 0} | ||
width="100px" | ||
/> | ||
</Flex> | ||
</form> | ||
</FormProvider> | ||
); | ||
}; | ||
|
||
export { ChatFooter }; |
7 changes: 7 additions & 0 deletions
7
frontend/src/bundles/chat/components/chat-footer/constants/constants.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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { type GenerateTextRequestDto } from '~/bundles/chat/types/types.js'; | ||
|
||
const DEFAULT_CHAT_FORM_PAYLOAD: GenerateTextRequestDto = { | ||
message: '', | ||
}; | ||
|
||
export { DEFAULT_CHAT_FORM_PAYLOAD }; |
25 changes: 25 additions & 0 deletions
25
frontend/src/bundles/chat/components/chat-header/chat-header.tsx
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Box, Heading, Text } from '~/bundles/common/components/components.js'; | ||
|
||
type Properties = { | ||
title: string; | ||
comment: string; | ||
}; | ||
|
||
const ChatHeader: React.FC<Properties> = ({ title, comment }) => { | ||
return ( | ||
<Box | ||
bg="background.600" | ||
p="20px" | ||
color="white" | ||
borderTopLeftRadius="xl" | ||
borderTopRightRadius="xl" | ||
> | ||
<Heading variant="H2" mb={2}> | ||
{title} | ||
</Heading> | ||
<Text variant="bodySmall">{comment}</Text> | ||
</Box> | ||
); | ||
}; | ||
|
||
export { ChatHeader }; |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { ChatBody } from '~/bundles/chat/components/chat-body/chat-body.js'; | ||
import { ChatFooter } from '~/bundles/chat/components/chat-footer/chat-footer.js'; | ||
import { ChatHeader } from '~/bundles/chat/components/chat-header/chat-header.js'; | ||
import { | ||
type GenerateTextRequestDto, | ||
type Message, | ||
} from '~/bundles/chat/types/types.js'; | ||
import { Box } from '~/bundles/common/components/components.js'; | ||
|
||
type Properties = { | ||
messages: Message[]; | ||
onSendMessage: (payload: GenerateTextRequestDto) => void; | ||
headerTitle: string; | ||
headerComment: string; | ||
}; | ||
|
||
const Chat: React.FC<Properties> = ({ | ||
messages, | ||
onSendMessage, | ||
headerTitle, | ||
headerComment, | ||
}) => { | ||
return ( | ||
<Box> | ||
<ChatHeader title={headerTitle} comment={headerComment} /> | ||
<Box p="10"> | ||
<ChatBody messages={messages} /> | ||
<ChatFooter onSendMessage={onSendMessage} /> | ||
</Box> | ||
</Box> | ||
); | ||
}; | ||
|
||
export { Chat }; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export { Chat } from './chat/chat.js'; |
29 changes: 29 additions & 0 deletions
29
frontend/src/bundles/chat/components/message-box/message-box.tsx
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { MessageSender } from '~/bundles/chat/enums/enums.js'; | ||
import { type Message } from '~/bundles/chat/types/types.js'; | ||
import { Box, Flex, Text } from '~/bundles/common/components/components.js'; | ||
|
||
import styles from './styles.module.css'; | ||
|
||
type Properties = { | ||
message: Message; | ||
}; | ||
|
||
const MessageBox: React.FC<Properties> = ({ message }) => { | ||
const { sender, text } = message; | ||
|
||
return ( | ||
<Box | ||
className={`${styles['message-box__container']} ${styles[sender === MessageSender.USER ? 'message-box__container--user' : 'message-box__container--ai']}`} | ||
> | ||
<Flex | ||
className={`${styles['message-box']} ${styles[sender === MessageSender.USER ? 'message-box--user' : 'message-box--ai']}`} | ||
> | ||
<Text color="black" bg="background.50" p={3} borderRadius="md"> | ||
{text} | ||
</Text> | ||
</Flex> | ||
</Box> | ||
); | ||
}; | ||
|
||
export { MessageBox }; |
22 changes: 22 additions & 0 deletions
22
frontend/src/bundles/chat/components/message-box/styles.module.css
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
.message-box__container { | ||
width: 100%; | ||
} | ||
.message-box__container--user { | ||
align-self: flex-start; | ||
} | ||
.message-box__container--ai { | ||
align-self: flex-end; | ||
} | ||
.message-box { | ||
flex-direction: column; | ||
} | ||
.message-box--user { | ||
align-items: flex-end; | ||
margin-left: 50px; | ||
margin-right: 10px; | ||
} | ||
.message-box--ai { | ||
align-items: flex-start; | ||
margin-left: 10px; | ||
margin-right: 50px; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sofiia-trokhymchuk It was suggested by @sergiy4 who implemented backend part, #82 (comment)
@sergiy4 Please your comments here