|
1 | 1 | import { ipcRenderer } from 'electron';
|
2 |
| -import React, { useEffect, useState } from 'react'; |
| 2 | +import React, { useState } from 'react'; |
| 3 | +import { useDebouncedEffect } from '../../helpers/effectHooks'; |
3 | 4 |
|
4 | 5 | const HtmlPreview = () => {
|
5 | 6 | const [content, setContent] = useState('https://plainbelt.github.io');
|
6 | 7 | const [qrCode, setQrCode] = useState();
|
7 | 8 | const [opening, setOpening] = useState(false);
|
8 | 9 | const [saving, setSaving] = useState(false);
|
9 | 10 |
|
10 |
| - useEffect(() => { |
11 |
| - ipcRenderer |
12 |
| - .invoke('generate-qrcode', { content }) |
13 |
| - .then((qr) => setQrCode(qr)) |
14 |
| - .catch(() => {}); |
15 |
| - }); |
| 11 | + useDebouncedEffect( |
| 12 | + () => { |
| 13 | + ipcRenderer |
| 14 | + .invoke('generate-qrcode', { content }) |
| 15 | + .then((qr) => setQrCode(qr)) |
| 16 | + .catch(() => {}); |
| 17 | + }, |
| 18 | + [content], |
| 19 | + 500 |
| 20 | + ); |
16 | 21 |
|
17 | 22 | const handleChange = async (evt: { target: { value: string } }) => {
|
18 | 23 | setContent(evt.target.value);
|
19 |
| - const qr = await ipcRenderer.invoke('generate-qrcode', { content }); |
20 |
| - setQrCode(qr); |
21 | 24 | };
|
22 | 25 |
|
23 | 26 | const handleOpen = async () => {
|
@@ -57,16 +60,16 @@ const HtmlPreview = () => {
|
57 | 60 | Save...
|
58 | 61 | </button>
|
59 | 62 | </div>
|
60 |
| - <div className="flex min-h-full"> |
| 63 | + <div className="flex flex-1 min-h-full"> |
61 | 64 | <textarea
|
62 | 65 | onChange={handleChange}
|
63 |
| - className="flex-1 min-h-full bg-white p-4" |
| 66 | + className="flex-1 min-h-full bg-white p-4 rounded-md" |
64 | 67 | value={content}
|
65 | 68 | />
|
66 | 69 | <div className="mx-1" />
|
67 | 70 | {qrCode && (
|
68 |
| - <section className="flex-1 min-h-full flex items-center p-4 prose bg-white"> |
69 |
| - <img src={qrCode} alt={content} className="w-full h-full" /> |
| 71 | + <section className="flex-1 min-h-full flex items-center p-4 prose bg-white rounded-md"> |
| 72 | + <img src={qrCode} alt={content} /> |
70 | 73 | </section>
|
71 | 74 | )}
|
72 | 75 | </div>
|
|
0 commit comments