Add conversation component
This commit is contained in:
parent
a2b67d1fbb
commit
160077048e
@ -8,6 +8,7 @@
|
||||
"format": "prettier --write ."
|
||||
},
|
||||
"dependencies": {
|
||||
"@reduxjs/toolkit": "^1.6.1",
|
||||
"react": "^17.0.0",
|
||||
"react-dom": "^17.0.0"
|
||||
},
|
||||
|
@ -1,6 +1,7 @@
|
||||
import React, { useState } from "react";
|
||||
import logo from "./logo.svg";
|
||||
import "./App.css";
|
||||
import Conversation from "./features/conversations/Conversation";
|
||||
|
||||
interface GreeterProps {
|
||||
name: string;
|
||||
@ -30,28 +31,8 @@ function App() {
|
||||
const [count, setCount] = useState(0);
|
||||
const [name, setName] = useState("");
|
||||
return (
|
||||
<div className="bg-sky-800 bg-opacity-80 text-white flex flex-col items-center justify-center h-screen">
|
||||
<img
|
||||
src={logo}
|
||||
className="w-[300px] animate-spin"
|
||||
alt="logo"
|
||||
style={{
|
||||
animationDuration: `${20 / (name.length || 1)}s`,
|
||||
}}
|
||||
/>
|
||||
<div className="text-center">
|
||||
<p className="text-3xl">Hello Vite + React!</p>
|
||||
<p>
|
||||
<button
|
||||
className="text-xl shadow hover:shadow-md transition-all bg-lime-500 bg-opacity-70 hover:bg-lime-600 p-2 rounded m-2"
|
||||
type="button"
|
||||
onClick={() => setCount((count) => count + 1)}
|
||||
>
|
||||
count is: {count}
|
||||
</button>
|
||||
</p>
|
||||
<Greeter name={name} setName={setName} />
|
||||
</div>
|
||||
<div>
|
||||
<Conversation />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
41
client/src/features/conversations/Conversation.tsx
Normal file
41
client/src/features/conversations/Conversation.tsx
Normal file
@ -0,0 +1,41 @@
|
||||
import React from "react";
|
||||
|
||||
const Conversation: React.FC = () => {
|
||||
const [messages, setMessages] = React.useState<string[]>([]);
|
||||
const [messageInput, setMessageInput] = React.useState("");
|
||||
|
||||
console.log(messageInput)
|
||||
return (
|
||||
<div>
|
||||
<div>
|
||||
{messages.map((message, index) => (
|
||||
<div className="m-2" key={index}>
|
||||
{message}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<form
|
||||
className="flex flex-row"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
setMessages([...messages, messageInput]);
|
||||
setMessageInput("");
|
||||
}}
|
||||
>
|
||||
<input
|
||||
className="flex-auto border-2 p-2 rounded mx-1"
|
||||
type="text"
|
||||
placeholder="message"
|
||||
value={messageInput}
|
||||
onChange={(e) => setMessageInput(e.target.value)}
|
||||
/>
|
||||
<button className="bg-blue-300 p-2 rounded mr-1" type="submit">
|
||||
Send
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Conversation;
|
1
client/src/features/messages/MessageInput.tsx
Normal file
1
client/src/features/messages/MessageInput.tsx
Normal file
@ -0,0 +1 @@
|
||||
import React from 'react';
|
@ -188,6 +188,13 @@
|
||||
dependencies:
|
||||
"@babel/helper-plugin-utils" "^7.14.5"
|
||||
|
||||
"@babel/runtime@^7.9.2":
|
||||
version "7.14.8"
|
||||
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.14.8.tgz#7119a56f421018852694290b9f9148097391b446"
|
||||
integrity sha512-twj3L8Og5SaCRCErB4x4ajbvBIVV77CGeFglHpeg5WC5FF8TZzBWXtTJ4MqaD9QszLYTtr+IsaAL2rEUevb+eg==
|
||||
dependencies:
|
||||
regenerator-runtime "^0.13.4"
|
||||
|
||||
"@babel/template@^7.14.5":
|
||||
version "7.14.5"
|
||||
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.14.5.tgz#a9bc9d8b33354ff6e55a9c60d1109200a68974f4"
|
||||
@ -241,6 +248,16 @@
|
||||
"@nodelib/fs.scandir" "2.1.5"
|
||||
fastq "^1.6.0"
|
||||
|
||||
"@reduxjs/toolkit@^1.6.1":
|
||||
version "1.6.1"
|
||||
resolved "https://registry.yarnpkg.com/@reduxjs/toolkit/-/toolkit-1.6.1.tgz#7bc83b47352a663bf28db01e79d17ba54b98ade9"
|
||||
integrity sha512-pa3nqclCJaZPAyBhruQtiRwtTjottRrVJqziVZcWzI73i6L3miLTtUyWfauwv08HWtiXLx1xGyGt+yLFfW/d0A==
|
||||
dependencies:
|
||||
immer "^9.0.1"
|
||||
redux "^4.1.0"
|
||||
redux-thunk "^2.3.0"
|
||||
reselect "^4.0.0"
|
||||
|
||||
"@rollup/pluginutils@^4.1.0":
|
||||
version "4.1.1"
|
||||
resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-4.1.1.tgz#1d4da86dd4eded15656a57d933fda2b9a08d47ec"
|
||||
@ -705,6 +722,11 @@ html-tags@^3.1.0:
|
||||
resolved "https://registry.yarnpkg.com/html-tags/-/html-tags-3.1.0.tgz#7b5e6f7e665e9fb41f30007ed9e0d41e97fb2140"
|
||||
integrity sha512-1qYz89hW3lFDEazhjW0yVAV87lw8lVkrJocr72XmBkMKsoSVJCQx3W8BXsC7hO2qAt8BoVjYjtAcZ9perqGnNg==
|
||||
|
||||
immer@^9.0.1:
|
||||
version "9.0.5"
|
||||
resolved "https://registry.yarnpkg.com/immer/-/immer-9.0.5.tgz#a7154f34fe7064f15f00554cc94c66cc0bf453ec"
|
||||
integrity sha512-2WuIehr2y4lmYz9gaQzetPR2ECniCifk4ORaQbU3g5EalLt+0IVTosEPJ5BoYl/75ky2mivzdRzV8wWgQGOSYQ==
|
||||
|
||||
import-cwd@^3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/import-cwd/-/import-cwd-3.0.0.tgz#20845547718015126ea9b3676b7592fb8bd4cf92"
|
||||
@ -1078,6 +1100,28 @@ reduce-css-calc@^2.1.8:
|
||||
css-unit-converter "^1.1.1"
|
||||
postcss-value-parser "^3.3.0"
|
||||
|
||||
redux-thunk@^2.3.0:
|
||||
version "2.3.0"
|
||||
resolved "https://registry.yarnpkg.com/redux-thunk/-/redux-thunk-2.3.0.tgz#51c2c19a185ed5187aaa9a2d08b666d0d6467622"
|
||||
integrity sha512-km6dclyFnmcvxhAcrQV2AkZmPQjzPDjgVlQtR0EQjxZPyJ0BnMf3in1ryuR8A2qU0HldVRfxYXbFSKlI3N7Slw==
|
||||
|
||||
redux@^4.1.0:
|
||||
version "4.1.1"
|
||||
resolved "https://registry.yarnpkg.com/redux/-/redux-4.1.1.tgz#76f1c439bb42043f985fbd9bf21990e60bd67f47"
|
||||
integrity sha512-hZQZdDEM25UY2P493kPYuKqviVwZ58lEmGQNeQ+gXa+U0gYPUBf7NKYazbe3m+bs/DzM/ahN12DbF+NG8i0CWw==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.9.2"
|
||||
|
||||
regenerator-runtime@^0.13.4:
|
||||
version "0.13.9"
|
||||
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.9.tgz#8925742a98ffd90814988d7566ad30ca3b263b52"
|
||||
integrity sha512-p3VT+cOEgxFsRRA9X4lkI1E+k2/CtnKtU4gcxyaCUreilL/vqI6CdZ3wxVUx3UOUg+gnUOQQcRI7BmSI656MYA==
|
||||
|
||||
reselect@^4.0.0:
|
||||
version "4.0.0"
|
||||
resolved "https://registry.yarnpkg.com/reselect/-/reselect-4.0.0.tgz#f2529830e5d3d0e021408b246a206ef4ea4437f7"
|
||||
integrity sha512-qUgANli03jjAyGlnbYVAV5vvnOmJnODyABz51RdBN7M4WaVu8mecZWgyQNkG8Yqe3KRGRt0l4K4B3XVEULC4CA==
|
||||
|
||||
resolve-from@^4.0.0:
|
||||
version "4.0.0"
|
||||
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-4.0.0.tgz#4abcd852ad32dd7baabfe9b40e00a36db5f392e6"
|
||||
|
Loading…
x
Reference in New Issue
Block a user