ferrywuai commited on
Commit
f90bfec
·
1 Parent(s): e26a59e

Create chat UI

Browse files

modified: README.md
modified: src/App.js
new file: src/components/ChatInterface.jsx

Files changed (3) hide show
  1. README.md +12 -49
  2. src/App.js +2 -20
  3. src/components/ChatInterface.jsx +79 -0
README.md CHANGED
@@ -11,15 +11,20 @@ license: mit
11
  short_description: Test static sdk react template
12
  ---
13
 
14
- # Getting Started with Create React App
15
 
16
  This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
17
 
18
- ## Available Scripts
19
 
20
- In the project directory, you can run:
 
21
 
22
- ### `npm start`
 
 
 
 
23
 
24
  Runs the app in the development mode.\
25
  Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
@@ -27,12 +32,10 @@ Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
27
  The page will reload when you make changes.\
28
  You may also see any lint errors in the console.
29
 
30
- ### `npm test`
31
-
32
- Launches the test runner in the interactive watch mode.\
33
- See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
34
 
35
- ### `npm run build`
 
36
 
37
  Builds the app for production to the `build` folder.\
38
  It correctly bundles React in production mode and optimizes the build for the best performance.
@@ -41,43 +44,3 @@ The build is minified and the filenames include the hashes.\
41
  Your app is ready to be deployed!
42
 
43
  See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
44
-
45
- ### `npm run eject`
46
-
47
- **Note: this is a one-way operation. Once you `eject`, you can't go back!**
48
-
49
- If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
50
-
51
- Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.
52
-
53
- You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
54
-
55
- ## Learn More
56
-
57
- You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
58
-
59
- To learn React, check out the [React documentation](https://reactjs.org/).
60
-
61
- ### Code Splitting
62
-
63
- This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
64
-
65
- ### Analyzing the Bundle Size
66
-
67
- This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
68
-
69
- ### Making a Progressive Web App
70
-
71
- This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
72
-
73
- ### Advanced Configuration
74
-
75
- This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
76
-
77
- ### Deployment
78
-
79
- This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
80
-
81
- ### `npm run build` fails to minify
82
-
83
- This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
 
11
  short_description: Test static sdk react template
12
  ---
13
 
14
+ # A Chatbot built with React
15
 
16
  This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
17
 
18
+ ## Features
19
 
20
+ - Support UI to send user input and get dummy response.
21
+ - Keep user input and response in chat history.
22
 
23
+ ## Usage
24
+
25
+ ### Development mode
26
+
27
+ - `npm start`
28
 
29
  Runs the app in the development mode.\
30
  Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
 
32
  The page will reload when you make changes.\
33
  You may also see any lint errors in the console.
34
 
35
+ ### Production mode
 
 
 
36
 
37
+ - `npm run build`
38
+ - `npx serve -s build`
39
 
40
  Builds the app for production to the `build` folder.\
41
  It correctly bundles React in production mode and optimizes the build for the best performance.
 
44
  Your app is ready to be deployed!
45
 
46
  See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/App.js CHANGED
@@ -1,25 +1,7 @@
1
- import logo from './logo.svg';
2
- import './App.css';
3
 
4
  function App() {
5
- return (
6
- <div className="App">
7
- <header className="App-header">
8
- <img src={logo} className="App-logo" alt="logo" />
9
- <p>
10
- Edit <code>src/App.js</code> and save to reload.
11
- </p>
12
- <a
13
- className="App-link"
14
- href="https://reactjs.org"
15
- target="_blank"
16
- rel="noopener noreferrer"
17
- >
18
- Learn React
19
- </a>
20
- </header>
21
- </div>
22
- );
23
  }
24
 
25
  export default App;
 
1
+ import ChatInterface from "./components/ChatInterface";
 
2
 
3
  function App() {
4
+ return <ChatInterface />;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  }
6
 
7
  export default App;
src/components/ChatInterface.jsx ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { useState } from "react";
2
+
3
+ export default function ChatInterface() {
4
+ const [input, setInput] = useState("");
5
+ const [chatHistory, setChatHistory] = useState([]);
6
+
7
+ const handleSend = () => {
8
+ if (!input.trim()) return;
9
+
10
+ const fakeResponse =
11
+ "This is a simulated response.\nIt can span multiple lines.";
12
+ const newPair = { user: input, assistant: fakeResponse };
13
+
14
+ setInput("");
15
+ setChatHistory([newPair, ...chatHistory]);
16
+ };
17
+
18
+ return (
19
+ <div
20
+ style={{
21
+ padding: "20px",
22
+ maxWidth: "600px",
23
+ margin: "auto",
24
+ display: "flex",
25
+ flexDirection: "column",
26
+ gap: "24px",
27
+ }}
28
+ >
29
+ {/* Input area */}
30
+ <div style={{ display: "flex", gap: "10px" }}>
31
+ <input
32
+ type="text"
33
+ value={input}
34
+ onChange={(e) => setInput(e.target.value)}
35
+ placeholder="Type your message..."
36
+ style={{ flex: 1, padding: "10px", fontSize: "16px" }}
37
+ />
38
+ <button onClick={handleSend} style={{ padding: "10px 20px" }}>
39
+ Send
40
+ </button>
41
+ </div>
42
+
43
+ {/* Chat history */}
44
+ <div>
45
+ {chatHistory.map((pair, index) => (
46
+ <div key={index} style={{ marginBottom: "16px" }}>
47
+ <div style={{ fontWeight: "bold", marginBottom: "4px" }}>User:</div>
48
+ <div
49
+ style={{
50
+ backgroundColor: "#e0f7fa",
51
+ padding: "10px",
52
+ borderRadius: "8px",
53
+ whiteSpace: "pre-wrap",
54
+ marginBottom: "4px",
55
+ }}
56
+ >
57
+ {pair.user}
58
+ </div>
59
+
60
+ <div style={{ fontWeight: "bold", margin: "8px 0 4px" }}>
61
+ Assistant:
62
+ </div>
63
+ <div
64
+ style={{
65
+ backgroundColor: "#f1f1f1",
66
+ padding: "10px",
67
+ borderRadius: "8px",
68
+ whiteSpace: "pre-wrap",
69
+ marginBottom: "4px",
70
+ }}
71
+ >
72
+ {pair.assistant}
73
+ </div>
74
+ </div>
75
+ ))}
76
+ </div>
77
+ </div>
78
+ );
79
+ }