Skip to content

Commit

Permalink
➕ persist translation refs on deleting song translations
Browse files Browse the repository at this point in the history
Signed-off-by: Andreas Müller <[email protected]>
  • Loading branch information
devmount committed May 22, 2022
1 parent a833bbc commit 1b62f72
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/modals/SongSet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -468,11 +468,18 @@ export default {
}
// existing song should be updated
else {
let initialSong = this.initialSong; // remember initial song data before update
// check if key remained (no title or language changes)
if (this.id == slug) {
// just update the existing song
this.$db.collection('songs').doc(slug).update(processedSong).then(() => {
// persist translation references
// persist translation references by removing and adding them
let translationDiff = initialSong.translations.filter(t => !processedSong.translations.includes(t));
if (translationDiff.length > 0) {
translationDiff.forEach(s => {
this.$db.collection('songs').doc(s).update({ translations: this.songs[s].translations.filter(t => t != slug) });
});
}
if (processedSong.translations.length > 0) {
processedSong.translations.forEach(t => {
if (t in this.songs) {
Expand Down Expand Up @@ -523,7 +530,13 @@ export default {
this.$db.collection('songs').doc(songId).update({ translations: updatedTranslationsList });
}
}
// persist translation references
// persist translation references by removing and adding them
let translationDiff = initialSong.translations.filter(t => !processedSong.translations.includes(t));
if (translationDiff.length > 0) {
translationDiff.forEach(s => {
this.$db.collection('songs').doc(s).update({ translations: this.songs[s].translations.filter(t => t != slug) });
});
}
if (processedSong.translations.length > 0) {
processedSong.translations.forEach(t => {
if (t in this.songs) {
Expand Down

0 comments on commit 1b62f72

Please sign in to comment.