start editing now chooses right record.

view is updated with new data afer save
This commit is contained in:
2025-01-18 20:59:35 +01:00
parent cc76fca5af
commit 829ee38239
2 changed files with 7 additions and 12 deletions
+6 -11
View File
@@ -104,7 +104,6 @@ export default {
this.currentView = view;
},
async handleSkillUpdate({ index, skill }) {
try {
const response = await API.put(
`/api/maintenance/skills/${skill.id}`, skill,
@@ -115,16 +114,12 @@ export default {
}
}
)
/*
const response = await fetch(`skills/${skill.id}`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(skill)
});
*/
if (!response.ok) throw new Error('Update failed');
const updatedSkill = await response.json();
this.skills[index] = updatedSkill;
if (!response.statusText== "OK") throw new Error('Update failed');
const updatedSkill = response.data;
// Update the skill in mdata
this.mdata.skills = this.mdata.skills.map(s =>
s.id === updatedSkill.id ? updatedSkill : s
);
} catch (error) {
console.error('Failed to update skill:', error);
}
@@ -126,7 +126,7 @@ export default {
methods: {
startEdit(index) {
this.editingIndex = index;
this.editedItem = { ...this.mdata['skills'][index] };
this.editedItem = { ...this.sortedSkills[index] };
},
saveEdit(index) {
this.$emit('update-skill', { index, skill: this.editedItem });