Skip to content

Commit 4f4b34c

Browse files
committed
Add commitToGitBook and sendToDiscord checkboxes
1 parent 2b11763 commit 4f4b34c

File tree

1 file changed

+48
-7
lines changed

1 file changed

+48
-7
lines changed

components/ArchiveSummaries.tsx

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { generateMarkdown } from '../utils/generateMarkdown';
55
import { updateGitbook } from '../utils/updateGitbook';
66
import { sendDiscordMessage } from '../utils/sendDiscordMessage';
77
import { useMyVariable } from '../context/MyVariableContext';
8+
import { confirmedStatusUpdate } from '../utils/confirmedStatusUpdate'
89

910
const ArchiveSummaries = () => {
1011
const textareaRef = useRef<HTMLTextAreaElement>(null);
@@ -17,6 +18,8 @@ const ArchiveSummaries = () => {
1718
meeting_id: myVariable.summary?.meeting_id || "",
1819
confirmed: myVariable.summary?.confirmed || false
1920
});
21+
const [commitToGitBook, setCommitToGitBook] = useState(true);
22+
const [sendToDiscord, setSendToDiscord] = useState(true);
2023
const [renderedMarkdown, setRenderedMarkdown] = useState("");
2124
const formattedDate = new Date(formData.date).toLocaleDateString('en-US', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' });
2225

@@ -49,8 +52,12 @@ const ArchiveSummaries = () => {
4952
};
5053

5154
const handleChange = (e: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>) => {
52-
const { name, value } = e.target;
53-
setFormData({ ...formData, [name]: value });
55+
const { name, value, type, checked } = e.target;
56+
if (type === "checkbox") {
57+
name === "commitToGitBook" ? setCommitToGitBook(checked) : setSendToDiscord(checked);
58+
} else {
59+
setFormData({ ...formData, [name]: value });
60+
}
5461
if (name === 'meetingSummary') {
5562
adjustTextareaHeight();
5663
}
@@ -76,9 +83,20 @@ const ArchiveSummaries = () => {
7683
return; // Exit the function early
7784
}
7885

79-
if (!myVariable.summary.confirmed) {
80-
const data = await updateGitbook(formData);
81-
if (data) {
86+
if (!formData.confirmed) {
87+
if (commitToGitBook) {
88+
const data = await updateGitbook(formData);
89+
if (data) {
90+
setMyVariable(prevState => ({
91+
...prevState,
92+
summary: {
93+
...prevState.summary,
94+
confirmed: true,
95+
},
96+
}));
97+
}
98+
} else {
99+
await confirmedStatusUpdate(formData);
82100
setMyVariable(prevState => ({
83101
...prevState,
84102
summary: {
@@ -87,7 +105,10 @@ const ArchiveSummaries = () => {
87105
},
88106
}));
89107
}
90-
await sendDiscordMessage(myVariable, renderedMarkdown);
108+
109+
if (sendToDiscord) {
110+
await sendDiscordMessage(myVariable, renderedMarkdown);
111+
}
91112
} else {
92113
alert('Summary already archived');
93114
}
@@ -110,7 +131,7 @@ const ArchiveSummaries = () => {
110131
<div className={styles['row-flex-start']}>
111132
<div className={styles['form-container']}>
112133
<form onSubmit={handleSubmit} className={styles['gitbook-form']}>
113-
<label className={styles['form-label']}>
134+
<label className={styles['form-label']}>
114135
Date:
115136
</label>
116137
<input
@@ -145,6 +166,26 @@ const ArchiveSummaries = () => {
145166
<button type="submit" disabled={loading} className={styles['submit-button']}>
146167
{loading ? "Loading..." : "Submit"}
147168
</button>
169+
<div className={styles['form-checkbox']}>
170+
<input
171+
type="checkbox"
172+
id="commitToGitBook"
173+
name="commitToGitBook"
174+
checked={commitToGitBook}
175+
onChange={handleChange}
176+
/>
177+
<label htmlFor="commitToGitBook">Commit to GitBook</label>
178+
</div>
179+
<div className={styles['form-checkbox']}>
180+
<input
181+
type="checkbox"
182+
id="sendToDiscord"
183+
name="sendToDiscord"
184+
checked={sendToDiscord}
185+
onChange={handleChange}
186+
/>
187+
<label htmlFor="sendToDiscord">Send Discord Message</label>
188+
</div>
148189
</form>
149190
</div>
150191
<div className={styles['markdown-rendered']}>

0 commit comments

Comments
 (0)