fixes
Showing
1 changed file
with
24 additions
and
2 deletions
| ... | @@ -42,10 +42,32 @@ function App() { | ... | @@ -42,10 +42,32 @@ function App() { |
| 42 | 42 | ||
| 43 | async function handleSubmit(e){ | 43 | async function handleSubmit(e){ |
| 44 | e.preventDefault(); | 44 | e.preventDefault(); |
| 45 | let chatLogNew = [...chatLog, { user: "me", message: `${chatInput}`} ] | 45 | // console.log(chatInput) |
| 46 | const userInput = ['what', 'why', 'when', 'where' , 'which', 'did', 'do', 'how', 'can', 'are']; | ||
| 47 | const userInputRegex = new RegExp(`\\b(${userInput.join('|')})\\b`, 'gi'); | ||
| 48 | const inputMatches = chatInput.match(userInputRegex); | ||
| 49 | |||
| 50 | const userPunctuation = ['.', '?', '!', ':', ';', ',']; | ||
| 51 | const userPunctuationRegex = new RegExp(`[${userPunctuation.join('')}]`, 'gi'); | ||
| 52 | const punctuationMatches = chatInput.match(userPunctuationRegex); | ||
| 53 | |||
| 54 | // console.log(punctuationMatches) | ||
| 55 | var userModifiedInput = chatInput | ||
| 56 | |||
| 57 | if (!punctuationMatches) { | ||
| 58 | if (!inputMatches) { | ||
| 59 | userModifiedInput = chatInput + "."; | ||
| 60 | // console.log("not a question!") | ||
| 61 | } else { | ||
| 62 | userModifiedInput = chatInput + "?"; | ||
| 63 | // console.log("its a question!") | ||
| 64 | } | ||
| 65 | } | ||
| 66 | |||
| 67 | let chatLogNew = [...chatLog, { user: "me", message: `${userModifiedInput}`} ] | ||
| 46 | setChatInput(""); | 68 | setChatInput(""); |
| 47 | setChatLog(chatLogNew) | 69 | setChatLog(chatLogNew) |
| 48 | console.log(chatInput) | 70 | |
| 49 | // fetch response to the api combining the chat log array of messages and seinding it as a message to localhost:3000 as a post | 71 | // fetch response to the api combining the chat log array of messages and seinding it as a message to localhost:3000 as a post |
| 50 | const messages = chatLogNew.map((message) => message.message).join("\n") | 72 | const messages = chatLogNew.map((message) => message.message).join("\n") |
| 51 | 73 | ... | ... |
-
Please register or sign in to post a comment