-
Notifications
You must be signed in to change notification settings - Fork 0
/
my-changes.patch
439 lines (428 loc) · 17.2 KB
/
my-changes.patch
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
diff --git a/app/page.tsx b/app/page.tsx
index b989443..b9aa07e 100644
--- a/app/page.tsx
+++ b/app/page.tsx
@@ -84,7 +84,7 @@ const markdownComponents: Components = {
/>
),
// Separate handling for <pre>
- pre: ({ ...props }) => (
+ pre: (props) => (
<pre
className="bg-gray-200 dark:bg-gray-800 p-4 rounded-md my-4 overflow-auto"
{...props}
@@ -122,6 +122,28 @@ const markdownComponents: Components = {
),
};
+// Helper functions to get and set cookies
+const getCookie = (name: string): string | null => {
+ const nameEQ = name + "=";
+ const ca = document.cookie.split(";").map((c) => c.trim());
+ for (let c of ca) {
+ if (c.indexOf(nameEQ) === 0)
+ return decodeURIComponent(c.substring(nameEQ.length));
+ }
+ return null;
+};
+
+const setCookie = (name: string, value: string, days: number): void => {
+ let expires = "";
+ if (days) {
+ const date = new Date();
+ date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
+ expires = "; expires=" + date.toUTCString();
+ }
+ document.cookie =
+ name + "=" + encodeURIComponent(value) + expires + "; path=/";
+};
+
const Home: React.FC = () => {
// State hooks with explicit types
const [inputText, setInputText] = useState<string>("");
@@ -129,7 +151,8 @@ const Home: React.FC = () => {
const [isClient, setIsClient] = useState<boolean>(false);
const [notification, setNotification] = useState<string>("");
const [showNotification, setShowNotification] = useState<boolean>(false);
- const [isMac, setIsMac] = useState<boolean>(false); // New state to track if user is on Mac
+ const [isMac, setIsMac] = useState<boolean>(false); // State to track if user is on Mac
+ const [useTwoButtons, setUseTwoButtons] = useState<boolean>(false); // State for checkbox
// Refs with precise types
const inputTextareaRef = useRef<HTMLTextAreaElement>(null);
@@ -137,11 +160,17 @@ const Home: React.FC = () => {
const modifiedTextareaRef = useRef<HTMLTextAreaElement>(null);
const modifiedPreviewRef = useRef<HTMLDivElement>(null);
- // Set isClient and detect if user is on Mac after the first render
+ // Initialize client state, OS detection, and load checkbox state from cookies
useEffect(() => {
setIsClient(true);
const platform = navigator.platform.toLowerCase();
setIsMac(platform.includes("mac"));
+
+ // Initialize useTwoButtons from cookies (default: false)
+ const useTwoButtonsCookie = getCookie("useTwoButtons");
+ if (useTwoButtonsCookie) {
+ setUseTwoButtons(useTwoButtonsCookie === "true");
+ }
}, []);
// Set focus and select text on the input textarea after client is set
@@ -169,6 +198,45 @@ const Home: React.FC = () => {
return result;
};
+ // Handler to process text
+ const handleProcess = useCallback((): void => {
+ const result = processText(inputText);
+ setModifiedText(result);
+ setNotification("Text processed successfully!");
+ setShowNotification(true);
+ setTimeout(() => {
+ setShowNotification(false);
+ }, 5000);
+ }, [inputText]);
+
+ // Handler to copy text to clipboard
+ const handleCopy = useCallback(async (): Promise<void> => {
+ if (isClient) {
+ try {
+ await navigator.clipboard.writeText(modifiedText);
+ setNotification("Text copied to clipboard!");
+ } catch (err: unknown) {
+ if (err instanceof Error) {
+ setNotification(`Copy failed: ${err.message}`);
+ } else {
+ setNotification("Unknown error occurred while copying.");
+ }
+ }
+ setShowNotification(true);
+ setTimeout(() => {
+ setShowNotification(false);
+ }, 5000);
+ } else {
+ setNotification(
+ "Clipboard functionality is not available on the server."
+ );
+ setShowNotification(true);
+ setTimeout(() => {
+ setShowNotification(false);
+ }, 5000);
+ }
+ }, [isClient, modifiedText]);
+
// Handler to process text and copy to clipboard
const handleProcessAndCopy = useCallback(async (): Promise<void> => {
const result = processText(inputText);
@@ -177,12 +245,12 @@ const Home: React.FC = () => {
if (isClient) {
try {
await navigator.clipboard.writeText(result);
- setNotification("Text verarbeitet und in die Zwischenablage kopiert!");
+ setNotification("Text processed and copied to clipboard!");
} catch (err: unknown) {
if (err instanceof Error) {
- setNotification(`Fehler beim Kopieren: ${err.message}`);
+ setNotification(`Copy failed: ${err.message}`);
} else {
- setNotification("Unbekannter Fehler beim Kopieren.");
+ setNotification("Unknown error occurred while copying.");
}
}
setShowNotification(true);
@@ -191,7 +259,7 @@ const Home: React.FC = () => {
}, 5000);
} else {
setNotification(
- "Zwischenablagefunktion ist auf dem Server nicht verfügbar."
+ "Clipboard functionality is not available on the server."
);
setShowNotification(true);
setTimeout(() => {
@@ -205,6 +273,16 @@ const Home: React.FC = () => {
setShowNotification(false);
}, []);
+ // Handler for checkbox change
+ const handleCheckboxChange = useCallback(
+ (e: React.ChangeEvent<HTMLInputElement>): void => {
+ const checked = e.target.checked;
+ setUseTwoButtons(checked);
+ setCookie("useTwoButtons", checked.toString(), 365); // Save for 1 year
+ },
+ []
+ );
+
// Synchronized scrolling for input and preview
useEffect(() => {
const textarea = inputTextareaRef.current;
@@ -328,7 +406,24 @@ const Home: React.FC = () => {
(!isMac && e.ctrlKey && e.key === "Enter")
) {
e.preventDefault();
- handleProcessAndCopy();
+ if (useTwoButtons) {
+ handleProcessAndCopy();
+ } else {
+ handleProcessAndCopy(); // In single-button mode, same as handleProcessAndCopy
+ }
+ }
+
+ // Additional shortcut for "Copy to Clipboard" when using two buttons
+ if (useTwoButtons) {
+ // For Mac: Command (⌘) + C
+ // For Others: Ctrl + C
+ if (
+ (isMac && e.metaKey && e.key.toLowerCase() === "c") ||
+ (!isMac && e.ctrlKey && e.key.toLowerCase() === "c")
+ ) {
+ e.preventDefault();
+ handleCopy();
+ }
}
};
@@ -337,10 +432,10 @@ const Home: React.FC = () => {
return () => {
document.removeEventListener("keydown", handleKeyDown);
};
- }, [handleProcessAndCopy, isMac]);
+ }, [handleProcessAndCopy, handleCopy, isMac, useTwoButtons]);
return (
- <div className="min-h-screen bg-gradient-to-br from-blue-50 to-gray-100 dark:from-gray-800 dark:to-black flex flex-col justify-center items-center overflow-y-hidden text-black dark:text-white transition-colors duration-300 relative p-4">
+ <div className="min-h-screen bg-gradient-to-br from-blue-50 to-gray-100 dark:from-gray-800 dark:to-black flex flex-col justify-center items-center overflow-y-auto text-black dark:text-white transition-colors duration-300 relative p-4">
{/* Notification Banner */}
<div
className={`fixed top-0 left-0 w-full bg-green-500 text-white px-4 py-2 shadow-md flex items-center justify-between transition-opacity duration-500 ${
@@ -391,79 +486,180 @@ const Home: React.FC = () => {
</ReactMarkdown>
</div>
</div>
+ {/* Buttons Section */}
+ <div className="mt-6 w-full max-w-5xl flex flex-col items-center">
+ {/* Buttons */}
+ <div className="flex justify-center space-x-4 mb-2">
+ {useTwoButtons ? (
+ <>
+ <button
+ className="bg-blue-600 dark:bg-blue-500 text-white font-semibold px-6 py-3 rounded-lg hover:bg-blue-700 dark:hover:bg-blue-600 transition-colors duration-300 shadow-md focus:outline-none focus:ring-2 focus:ring-blue-500"
+ onClick={handleProcess}
+ >
+ Process Text
+ </button>
+ <button
+ className="bg-green-600 dark:bg-green-500 text-white font-semibold px-6 py-3 rounded-lg hover:bg-green-700 dark:hover:bg-green-600 transition-colors duration-300 shadow-md focus:outline-none focus:ring-2 focus:ring-green-500"
+ onClick={handleCopy}
+ >
+ Copy to Clipboard
+ </button>
+ </>
+ ) : (
+ <button
+ className="bg-purple-600 dark:bg-purple-500 text-white font-semibold px-6 py-3 rounded-lg hover:bg-purple-700 dark:hover:bg-purple-600 transition-colors duration-300 shadow-md focus:outline-none focus:ring-2 focus:ring-purple-500"
+ onClick={handleProcessAndCopy}
+ >
+ Process Text & Copy
+ </button>
+ )}
+ </div>
+ </div>
+ </div>
- {/* Process Text and Copy Button */}
- <div className="flex justify-center mt-6">
- <button
- className="bg-blue-600 dark:bg-blue-500 text-white font-semibold px-6 py-3 rounded-full hover:bg-blue-700 dark:hover:bg-blue-600 transition duration-300"
- onClick={handleProcessAndCopy}
+ {/* Checkbox and Description */}
+ <div className="mt-6 w-full max-w-5xl bg-white dark:bg-gray-800 rounded-lg shadow-md p-6 flex flex-col space-y-4">
+ <div className="flex items-center">
+ <input
+ type="checkbox"
+ id="buttonMode"
+ checked={useTwoButtons}
+ onChange={handleCheckboxChange}
+ className="mr-3 h-5 w-5 text-blue-600 focus:ring-blue-500 border-gray-300 rounded transition duration-200 ease-in-out"
+ />
+ <label
+ htmlFor="buttonMode"
+ className="text-lg text-gray-800 dark:text-gray-200 font-medium cursor-pointer"
>
- Process Text & Copy
- </button>
+ Show Two Buttons
+ </label>
</div>
+ <p className="text-md text-gray-600 dark:text-gray-400">
+ Enable this option to have separate buttons for processing text and
+ copying it to the clipboard. When disabled, a single button will
+ perform both actions simultaneously. This setting is saved in your
+ browser.
+ </p>
+ </div>
- {/* Modified Text Section */}
- {modifiedText && (
- <div className="mt-10">
- <h2 className="text-2xl font-bold text-blue-600 dark:text-blue-400 mb-4">
- Modified Text
- </h2>
- <div className="flex flex-col md:flex-row gap-8">
- {/* Modified Textarea */}
- <textarea
- ref={modifiedTextareaRef}
- className="w-full md:w-1/2 p-4 border border-green-300 dark:border-gray-700 rounded-lg focus:outline-none focus:ring-2 focus:ring-green-500 dark:focus:ring-green-400 bg-white dark:bg-gray-800 text-black dark:text-white resize-y overflow-auto max-h-96 min-h-40"
- value={modifiedText}
- readOnly
- onChange={() => {}}
- rows={10}
- ></textarea>
-
- {/* Modified Markdown Preview */}
- <div
- ref={modifiedPreviewRef}
- className="w-full md:w-1/2 p-4 border border-green-300 dark:border-gray-700 rounded-lg bg-white dark:bg-gray-800 text-black dark:text-white overflow-auto max-h-96"
+ {/* Modified Text Section */}
+ {modifiedText && (
+ <div className="mt-10 w-full max-w-5xl bg-white dark:bg-gray-900 rounded-lg shadow-md p-8 flex flex-col">
+ <h2 className="text-2xl font-bold text-blue-600 dark:text-blue-400 mb-4">
+ Modified Text
+ </h2>
+ <div className="flex flex-col md:flex-row gap-8">
+ {/* Modified Textarea */}
+ <textarea
+ ref={modifiedTextareaRef}
+ className="w-full md:w-1/2 p-4 border border-green-300 dark:border-gray-700 rounded-lg focus:outline-none focus:ring-2 focus:ring-green-500 dark:focus:ring-green-400 bg-white dark:bg-gray-800 text-black dark:text-white resize-y overflow-auto max-h-96 min-h-40"
+ value={modifiedText}
+ readOnly
+ onChange={() => {}}
+ rows={10}
+ ></textarea>
+
+ {/* Modified Markdown Preview */}
+ <div
+ ref={modifiedPreviewRef}
+ className="w-full md:w-1/2 p-4 border border-green-300 dark:border-gray-700 rounded-lg bg-white dark:bg-gray-800 text-black dark:text-white overflow-auto max-h-96"
+ >
+ <ReactMarkdown
+ remarkPlugins={[remarkGfm, remarkMath]}
+ rehypePlugins={[rehypeKatex]}
+ components={markdownComponents}
>
- <ReactMarkdown
- remarkPlugins={[remarkGfm, remarkMath]}
- rehypePlugins={[rehypeKatex]}
- components={markdownComponents}
- >
- {modifiedText}
- </ReactMarkdown>
- </div>
+ {modifiedText}
+ </ReactMarkdown>
</div>
</div>
- )}
- </div>
+ </div>
+ )}
{/* Shortcuts Display */}
- <div className="mt-6 w-full max-w-5xl bg-white dark:bg-gray-900 rounded-lg shadow-md p-4">
- <h3 className="text-lg font-semibold text-blue-600 dark:text-blue-400 mb-2">
+ <div className="mt-6 w-full max-w-5xl bg-white dark:bg-gray-900 rounded-lg shadow-md p-6">
+ <h3 className="text-lg font-semibold text-blue-600 dark:text-blue-400 mb-4">
Shortcuts
</h3>
- <ul className="list-disc list-inside text-text-light dark:text-text-dark">
- {isMac ? (
- <li>
- <kbd className="bg-gray-200 dark:bg-gray-700 px-1 py-0.5 rounded">
- ⌘
- </kbd>{" "}
- +{" "}
- <kbd className="bg-gray-200 dark:bg-gray-700 px-1 py-0.5 rounded">
- Enter
- </kbd>
- : Process and Copy Text
- </li>
+ <ul className="list-disc list-inside text-text-light dark:text-text-dark space-y-2">
+ {useTwoButtons ? (
+ <>
+ <li>
+ {isMac ? (
+ <>
+ <kbd className="bg-gray-200 dark:bg-gray-700 px-2 py-1 rounded">
+ ⌘
+ </kbd>{" "}
+ +{" "}
+ <kbd className="bg-gray-200 dark:bg-gray-700 px-2 py-1 rounded">
+ Enter
+ </kbd>
+ : Process and Copy Text
+ </>
+ ) : (
+ <>
+ <kbd className="bg-gray-200 dark:bg-gray-700 px-2 py-1 rounded">
+ Ctrl
+ </kbd>{" "}
+ +{" "}
+ <kbd className="bg-gray-200 dark:bg-gray-700 px-2 py-1 rounded">
+ Enter
+ </kbd>
+ : Process and Copy Text
+ </>
+ )}
+ </li>
+ <li>
+ {isMac ? (
+ <>
+ <kbd className="bg-gray-200 dark:bg-gray-700 px-2 py-1 rounded">
+ ⌘
+ </kbd>{" "}
+ +{" "}
+ <kbd className="bg-gray-200 dark:bg-gray-700 px-2 py-1 rounded">
+ C
+ </kbd>
+ : Copy to Clipboard
+ </>
+ ) : (
+ <>
+ <kbd className="bg-gray-200 dark:bg-gray-700 px-2 py-1 rounded">
+ Ctrl
+ </kbd>{" "}
+ +{" "}
+ <kbd className="bg-gray-200 dark:bg-gray-700 px-2 py-1 rounded">
+ C
+ </kbd>
+ : Copy to Clipboard
+ </>
+ )}
+ </li>
+ </>
) : (
<li>
- <kbd className="bg-gray-200 dark:bg-gray-700 px-1 py-0.5 rounded">
- Ctrl
- </kbd>{" "}
- +{" "}
- <kbd className="bg-gray-200 dark:bg-gray-700 px-1 py-0.5 rounded">
- Enter
- </kbd>
- : Process and Copy Text
+ {isMac ? (
+ <>
+ <kbd className="bg-gray-200 dark:bg-gray-700 px-2 py-1 rounded">
+ ⌘
+ </kbd>{" "}
+ +{" "}
+ <kbd className="bg-gray-200 dark:bg-gray-700 px-2 py-1 rounded">
+ Enter
+ </kbd>
+ : Process and Copy Text
+ </>
+ ) : (
+ <>
+ <kbd className="bg-gray-200 dark:bg-gray-700 px-2 py-1 rounded">
+ Ctrl
+ </kbd>{" "}
+ +{" "}
+ <kbd className="bg-gray-200 dark:bg-gray-700 px-2 py-1 rounded">
+ Enter
+ </kbd>
+ : Process and Copy Text
+ </>
+ )}
</li>
)}
</ul>