Skip to content

Commit

Permalink
frontend gets the wonLevelMessage and uses it to determine if the use…
Browse files Browse the repository at this point in the history
…r has won the level
  • Loading branch information
pmarsh-scottlogic committed Mar 21, 2024
1 parent 6258a79 commit 8a92131
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 22 deletions.
30 changes: 8 additions & 22 deletions frontend/src/components/ChatBox/ChatBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ChatMessage, ChatResponse } from '@src/models/chat';
import { EmailInfo } from '@src/models/email';
import { LEVEL_NAMES } from '@src/models/level';
import { chatService } from '@src/service';
import { makeChatMessageFromDTO } from '@src/service/chatService';

import ChatBoxFeed from './ChatBoxFeed';
import ChatBoxInput from './ChatBoxInput';
Expand Down Expand Up @@ -61,20 +62,9 @@ function ChatBox({
setChatInput(recalledMessage);
}, [recalledMessageReverseIndex]);

function getSuccessMessage() {
return currentLevel < LEVEL_NAMES.LEVEL_3
? `Congratulations! You have completed this level. Please click on the next level to continue.`
: `Congratulations, you have completed the final level of your assignment!`;
}

function isLevelComplete() {
return messages.some((message) => message.type === 'LEVEL_COMPLETE');
}

function processChatResponse(response: ChatResponse) {
const transformedMessageInfo = response.transformedMessageInfo;
const transformedMessage = response.transformedMessage;
// add transformation info message to the chat box
if (transformedMessageInfo) {
addChatMessage({
message: transformedMessageInfo,
Expand Down Expand Up @@ -151,19 +141,15 @@ function ChatBox({
// update emails
addSentEmails(response.sentEmails);

if (response.wonLevel && !isLevelComplete()) {
// surely the presence of the message is enough to know if the level is complete
// We can scrap wonLevel and rename resultingChatMessage to levelCompleteMessage
if (response.wonLevelMessage) {
updateNumCompletedLevels(currentLevel);
const successMessage = getSuccessMessage();
addChatMessage({
type: 'LEVEL_COMPLETE',
message: successMessage,
});
// asynchronously add the message to the chat history
void chatService.addInfoMessageToChatHistory(
successMessage,
'LEVEL_COMPLETE',
currentLevel
const levelCompleteMessage = makeChatMessageFromDTO(
response.wonLevelMessage
);
addChatMessage(levelCompleteMessage);

// if this is the last level, show the level complete overlay
if (currentLevel === LEVEL_NAMES.LEVEL_3) {
openLevelsCompleteOverlay();
Expand Down
1 change: 1 addition & 0 deletions frontend/src/models/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ interface ChatResponse {
isError: boolean;
sentEmails: EmailInfo[];
transformedMessageInfo?: string;
wonLevelMessage?: ChatMessageDTO;
}

interface ChatCompletionRequestMessage {
Expand Down

0 comments on commit 8a92131

Please sign in to comment.