Skip to content

Commit

Permalink
feat: support restore text onchange webview
Browse files Browse the repository at this point in the history
  • Loading branch information
oeyoews committed Oct 27, 2024
1 parent ffc6feb commit b86660f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"publisher": "oeyoews",
"name": "usewiki2",
"displayName": "usewiki2",
"version": "2.4.0",
"version": "2.5.0",
"private": true,
"packageManager": "pnpm@9.0.6",
"description": "",
Expand Down
14 changes: 13 additions & 1 deletion packages/react/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ function App() {
}
}

function updateInputValue(value: string) {
setInputValue(value);
localStorage.setItem('text', value);
}

function playSound() {
const currentAudio = new Audio('data:audio/mp3;base64,' + sound);
currentAudio.volume = 0.9;
Expand All @@ -69,9 +74,16 @@ function App() {
if (!inputValue) return;
messenger.send('sendWiki', { text: inputValue });
setInputValue('');
localStorage.removeItem('text');
inputRef.current?.focus();
}

useEffect(() => {
if (localStorage.getItem('text')) {
setInputValue(localStorage.getItem('text')!);
}
}, []);

useEffect(() => {
messenger.on('playSound', () => {
playSound();
Expand Down Expand Up @@ -173,7 +185,7 @@ function App() {
rows={6}
placeholder={placeholder}
className="focus-visible:ring-0 border-none input-bg resize-none"
onChange={(e) => setInputValue(e.target.value)}
onChange={(e) => updateInputValue(e.target.value)}
value={inputValue}
/>
<Button
Expand Down
2 changes: 1 addition & 1 deletion src/generated/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Meta info
export const publisher = "oeyoews"
export const name = "usewiki2"
export const version = "2.4.0"
export const version = "2.5.0"
export const displayName = "usewiki2"
export const description = undefined
export const extensionId = `${publisher}.${name}`
Expand Down

0 comments on commit b86660f

Please sign in to comment.