Skip to content

Commit

Permalink
Merge pull request #903 from parlemonde/fix-anthem-VIL-326
Browse files Browse the repository at this point in the history
Fix anthem vil 326
  • Loading branch information
MelissaOlas authored Apr 5, 2024
2 parents e851d7f + c922bf4 commit db1b323
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/pages/parametrer-hymne/1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const AnthemStep1 = () => {
const musicIcons = [MicroIcon, PianoIcon, GuitareIcon, TrumpetIcon, FluteIcon, DrumIcon, DrumkitIcon];
const [times, setTimes] = React.useState<Record<number, number>>({});
const [editingIndex, setEditingIndex] = React.useState<number | null>(null);
const [previousValue, setPreviousValue] = React.useState('');

const created = React.useRef(false);
React.useEffect(() => {
Expand Down Expand Up @@ -100,26 +101,33 @@ const AnthemStep1 = () => {
type="text"
value={audio.label}
onBlur={() => {
if (audio.label.trim() !== '') {
setEditingIndex(null);
if (audio.label.trim() === '') {
data.verseAudios[idx].label = previousValue || 'Valeur par défaut';
updateActivity({ data: { ...data } });
}
setEditingIndex(null);
}}
onChange={(e) => {
data.verseAudios[idx].label = e.target.value;
updateActivity({ data: { ...data } });
}}
onFocus={() => {
setPreviousValue(audio.label);
}}
onKeyDown={(e) => {
if (e.key === 'Enter') {
e.preventDefault();
if (audio.label.trim() !== '') {
setEditingIndex(null);
if (audio.label.trim() === '') {
data.verseAudios[idx].label = previousValue || 'Valeur par défaut';
updateActivity({ data: { ...data } });
}
setEditingIndex(null);
}
}}
autoFocus
/>
) : (
<span onClick={() => setEditingIndex(idx)}>{audio.label}</span>
<span onClick={() => setEditingIndex(idx)}>{audio.label === '' ? 'Valeur par défaut' : audio.label}</span>
)}
</div>
<div>
Expand Down

0 comments on commit db1b323

Please sign in to comment.