-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from gsproston-scottlogic/dev
Pre defensive measures
- Loading branch information
Showing
19 changed files
with
299 additions
and
86 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
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,15 +1,27 @@ | ||
import "./App.css"; | ||
import ChatBox from "./components/ChatBox"; | ||
import ChatBox from "./components/ChatBox/ChatBox"; | ||
import EmailBox from "./components/EmailBox/EmailBox"; | ||
import Header from "./components/Header"; | ||
import { useState } from "react"; | ||
|
||
function App() { | ||
const [emails, setEmails] = useState([]); | ||
|
||
return ( | ||
<div id="main-area"> | ||
<Header /> | ||
<ChatBox /> | ||
</div> | ||
<span id="main-area"> | ||
<div class="side-bar"> | ||
<div class="side-bar-header">defence mechanisms</div> | ||
</div> | ||
<div id="centre-area"> | ||
<Header /> | ||
<ChatBox setEmails={setEmails} /> | ||
</div> | ||
<div class="side-bar"> | ||
<div class="side-bar-header">sent emails</div> | ||
<EmailBox emails={emails} /> | ||
</div> | ||
</span> | ||
); | ||
} | ||
|
||
export default App; | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,49 @@ | ||
#chat-box { | ||
display: flex; | ||
flex-direction: column; | ||
flex-grow: 1; | ||
} | ||
|
||
#chat-box-footer { | ||
align-items: center; | ||
display: flex; | ||
padding: 0 32px; | ||
} | ||
|
||
#chat-box-input { | ||
align-self: flex-end; | ||
display: flex; | ||
justify-content: center; | ||
width: 100%; | ||
padding: 40px 0px; | ||
} | ||
|
||
#chat-box-input input { | ||
width: 100%; | ||
height: 40px; | ||
border: 1px solid #ccc; | ||
border-radius: 5px; | ||
padding: 0 12px; | ||
font-size: 16px; | ||
box-sizing: border-box; | ||
} | ||
|
||
#chat-box-button { | ||
padding-left: 20px; | ||
} | ||
|
||
#chat-box-button button { | ||
width: 100%; | ||
height: 40px; | ||
border: 1px solid #ccc; | ||
border-radius: 5px; | ||
padding: 0 12px; | ||
font-size: 16px; | ||
box-sizing: border-box; | ||
color: #666; | ||
} | ||
|
||
#chat-box-button button:hover { | ||
background-color: #ccc; | ||
color: #fff; | ||
} |
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,77 @@ | ||
import React, { useEffect, useState } from "react"; | ||
|
||
import "./ChatBox.css"; | ||
import ChatBoxFeed from "./ChatBoxFeed"; | ||
import { | ||
clearOpenAiChat, | ||
openAiSendMessage, | ||
} from "../../service/openaiService"; | ||
import { getSentEmails } from "../../service/emailService"; | ||
|
||
function ChatBox(props) { | ||
const [messages, setMessages] = useState([]); | ||
|
||
// called on mount | ||
useEffect(() => { | ||
// clear remote messages | ||
clearOpenAiChat(); | ||
// get sent emails | ||
getSentEmails().then((sentEmails) => { | ||
props.setEmails(sentEmails); | ||
}); | ||
}, []); | ||
|
||
const clearClicked = () => { | ||
// clear local messages | ||
setMessages([]); | ||
// clear remote messages | ||
clearOpenAiChat(); | ||
}; | ||
|
||
const sendChatMessage = async (event) => { | ||
if (event.key === "Enter") { | ||
// get the message | ||
const message = event.target.value; | ||
// add it to the list of messages | ||
setMessages((messages) => [ | ||
...messages, | ||
{ message: message, isUser: true }, | ||
]); | ||
// clear the input | ||
event.target.value = ""; | ||
|
||
const reply = await openAiSendMessage(message); | ||
// add it to the list of messages | ||
setMessages((messages) => [ | ||
...messages, | ||
{ message: reply, isUser: false }, | ||
]); | ||
|
||
// get sent emails | ||
const sentEmails = await getSentEmails(); | ||
// update emails | ||
props.setEmails(sentEmails); | ||
} | ||
}; | ||
|
||
return ( | ||
<div id="chat-box"> | ||
<ChatBoxFeed messages={messages} /> | ||
<div id="chat-box-footer"> | ||
<div id="chat-box-input"> | ||
<input | ||
type="text" | ||
placeholder="chat to chatgpt..." | ||
autoFocus | ||
onKeyUp={sendChatMessage.bind(this)} | ||
/> | ||
</div> | ||
<div id="chat-box-button" onClick={clearClicked.bind(this)}> | ||
<button>clear</button> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default ChatBox; |
2 changes: 1 addition & 1 deletion
2
frontend/src/components/ChatBoxFeed.css → ...nd/src/components/ChatBox/ChatBoxFeed.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
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 @@ | ||
#email-box { | ||
flex-grow: 1; | ||
display: flex; | ||
flex-direction: column; | ||
height: 100%; | ||
} | ||
|
||
#email-box-feed { | ||
display: flex; | ||
flex-direction: column-reverse; | ||
flex-grow: 1; | ||
overflow-y: auto; | ||
padding: 0 40px; | ||
padding-bottom: 40px; | ||
} |
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,21 @@ | ||
import SentEmail from "./SentEmail"; | ||
import "./EmailBox.css"; | ||
|
||
function EmailBox(props) { | ||
return ( | ||
<div id="email-box-feed"> | ||
{props.emails.toReversed().map((email, index) => { | ||
return ( | ||
<SentEmail | ||
address={email.address} | ||
subject={email.subject} | ||
content={email.content} | ||
key={index} | ||
/> | ||
); | ||
})} | ||
</div> | ||
); | ||
} | ||
|
||
export default EmailBox; |
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 @@ | ||
.sent-email { | ||
border-color: #ccc; | ||
border-radius: 5px; | ||
border-style: solid; | ||
border-width: 1px; | ||
font-size: 14px; | ||
margin-top: 10px; | ||
padding: 5px; | ||
} | ||
|
||
.sent-email-divider { | ||
border-bottom: 1px solid #ccc; | ||
margin: 5px 0; | ||
width: 100%; | ||
} |
Oops, something went wrong.