-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Made frontend server exit after use, disabled repeat correction and o…
…ther handlers as they were actually making for worse results
- Loading branch information
Showing
4 changed files
with
132 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
lyrics_transcriber/frontend/src/components/WordEditControls.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import { Button, Box, TextField } from '@mui/material' | ||
import DeleteIcon from '@mui/icons-material/Delete' | ||
import { useState, useEffect } from 'react' | ||
import { ModalContent } from './LyricsAnalyzer' | ||
|
||
interface WordEditControlsProps { | ||
content: ModalContent | ||
onUpdateCorrection?: (position: number, updatedWords: string[]) => void | ||
onClose: () => void | ||
} | ||
|
||
export function useWordEdit(content: ModalContent | null) { | ||
const [editedWord, setEditedWord] = useState('') | ||
const [isEditing, setIsEditing] = useState(false) | ||
|
||
useEffect(() => { | ||
if (content) { | ||
setEditedWord(content.type === 'gap' ? content.data.word : content.type === 'anchor' ? content.data.words[0] : '') | ||
setIsEditing(false) | ||
} | ||
}, [content]) | ||
|
||
return { | ||
editedWord, | ||
setEditedWord, | ||
isEditing, | ||
setIsEditing | ||
} | ||
} | ||
|
||
export default function WordEditControls({ content, onUpdateCorrection, onClose }: WordEditControlsProps) { | ||
const { | ||
editedWord, | ||
setEditedWord, | ||
isEditing, | ||
setIsEditing | ||
} = useWordEdit(content) | ||
|
||
const handleStartEdit = () => { | ||
if (content.type === 'gap') { | ||
setEditedWord(content.data.word) | ||
} else if (content.type === 'anchor') { | ||
setEditedWord(content.data.words[0]) | ||
} | ||
setIsEditing(true) | ||
} | ||
|
||
const handleDelete = () => { | ||
if (!onUpdateCorrection) return | ||
onUpdateCorrection(content.data.position, []) | ||
onClose() | ||
} | ||
|
||
const handleSaveEdit = () => { | ||
if (onUpdateCorrection) { | ||
onUpdateCorrection(content.data.position, [editedWord]) | ||
} | ||
onClose() | ||
} | ||
|
||
const handleCancelEdit = () => { | ||
if (content.type === 'gap') { | ||
setEditedWord(content.data.word) | ||
setIsEditing(false) | ||
} | ||
} | ||
|
||
const handleWordChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
setEditedWord(event.target.value) | ||
} | ||
|
||
return isEditing ? ( | ||
<Box> | ||
<TextField | ||
value={editedWord} | ||
onChange={handleWordChange} | ||
fullWidth | ||
label="Edit word" | ||
variant="outlined" | ||
size="small" | ||
sx={{ mb: 1 }} | ||
/> | ||
<Box sx={{ display: 'flex', gap: 1 }}> | ||
<Button variant="contained" onClick={handleSaveEdit}> | ||
Save Changes | ||
</Button> | ||
<Button variant="outlined" onClick={handleCancelEdit}> | ||
Cancel | ||
</Button> | ||
<Button | ||
variant="outlined" | ||
color="error" | ||
startIcon={<DeleteIcon />} | ||
onClick={handleDelete} | ||
> | ||
Delete | ||
</Button> | ||
</Box> | ||
</Box> | ||
) : ( | ||
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}> | ||
<Button variant="outlined" size="small" onClick={handleStartEdit}> | ||
Edit | ||
</Button> | ||
<Button | ||
variant="outlined" | ||
size="small" | ||
color="error" | ||
startIcon={<DeleteIcon />} | ||
onClick={handleDelete} | ||
> | ||
Delete | ||
</Button> | ||
</Box> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"root":["./src/app.tsx","./src/api.ts","./src/main.tsx","./src/types.ts","./src/vite-env.d.ts","./src/components/correctionmetrics.tsx","./src/components/detailsmodal.tsx","./src/components/fileupload.tsx","./src/components/lyricsanalyzer.tsx","./src/components/modeselector.tsx","./src/components/referenceview.tsx","./src/components/transcriptionview.tsx","./src/components/shared/constants.ts","./src/components/shared/styles.ts","./src/components/shared/types.ts","./src/components/shared/components/highlightedtext.tsx","./src/components/shared/components/sourceselector.tsx","./src/components/shared/components/word.tsx","./src/components/shared/hooks/usewordclick.ts","./src/components/shared/utils/newlinecalculator.ts","./src/components/shared/utils/positioncalculator.ts"],"version":"5.6.3"} | ||
{"root":["./src/app.tsx","./src/api.ts","./src/main.tsx","./src/types.ts","./src/vite-env.d.ts","./src/components/correctionmetrics.tsx","./src/components/detailsmodal.tsx","./src/components/fileupload.tsx","./src/components/lyricsanalyzer.tsx","./src/components/modeselector.tsx","./src/components/referenceview.tsx","./src/components/transcriptionview.tsx","./src/components/wordeditcontrols.tsx","./src/components/shared/constants.ts","./src/components/shared/styles.ts","./src/components/shared/types.ts","./src/components/shared/components/highlightedtext.tsx","./src/components/shared/components/sourceselector.tsx","./src/components/shared/components/word.tsx","./src/components/shared/hooks/usewordclick.ts","./src/components/shared/utils/newlinecalculator.ts","./src/components/shared/utils/positioncalculator.ts"],"version":"5.6.3"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters