-
Notifications
You must be signed in to change notification settings - Fork 0
/
writing_a_book5.txt
97 lines (81 loc) · 2.79 KB
/
writing_a_book5.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
For the frontend, I'll guide you through creating a simple React application that interacts with the Node.js TypeScript server you've set up.
Setting up a React application
First, make sure you have create-react-app installed globally:
bash
Copy code
npm install -g create-react-app
Create a new React application:
bash
Copy code
create-react-app book-writing-app --template typescript
Change to the newly created app directory:
bash
Copy code
cd book-writing-app
Install Axios for making API requests:
bash
Copy code
npm install axios
Creating a React component to interact with the server
In the src folder of the React app, create a new file called BookWriting.tsx.
In BookWriting.tsx, import the necessary dependencies and create a simple form to input the required data for each step of the book writing process:
tsx
Copy code
import React, { useState } from 'react';
import axios from 'axios';
const BookWriting: React.FC = () => {
const [step, setStep] = useState(0);
const [text, setText] = useState('');
const [chapterNumber, setChapterNumber] = useState(0);
const [previousChapters, setPreviousChapters] = useState('');
const [summaries, setSummaries] = useState('');
const [responseText, setResponseText] = useState('');
const handleSubmit = async (event: React.FormEvent) => {
event.preventDefault();
const response = await axios.post('http://localhost:3001/process_step', {
step,
text,
chapterNumber,
previousChapters,
summaries,
});
setResponseText(response.data.text);
};
return (
<div>
<form onSubmit={handleSubmit}>
<label>
Step:
<input
type="number"
value={step}
onChange={(event) => setStep(parseInt(event.target.value))}
/>
</label>
<br />
{/* Add more input fields for other data */}
{/* ... */}
<button type="submit">Submit</button>
</form>
<pre>{responseText}</pre>
</div>
);
};
export default BookWriting;
Update the input fields and state variables as needed for your specific use case.
In src/App.tsx, import and render the BookWriting component:
tsx
Copy code
import React from 'react';
import './App.css';
import BookWriting from './BookWriting';
function App() {
return (
<div className="App">
<BookWriting />
</div>
);
}
export default App;
Now, you can start your React app with npm start, and it will interact with your Node.js server. The form will allow you to input the required data for each step, and the response will be displayed below the form.
For reading the book as it's written, you can fetch the chapters from your server (by creating an API endpoint to serve the saved chapters) and display them in a separate component or within the existing BookWriting component.