Skip to content

Commit

Permalink
fix(files): Update favorites navigation list on folder renames
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Chemineau <louis@chmn.me>
  • Loading branch information
artonge committed Jun 24, 2024
1 parent 0245271 commit 2a4b729
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions apps/files/src/views/favorites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,21 @@ export default () => {
removePathFromFavorites(node.path)
})

/**
* Update favourites navigation when a folder is renamed
*/
subscribe('files:node:renamed', (node: Node) => {
if (node.type !== FileType.Folder) {
return
}

if (node.attributes.favorite !== 1) {
return
}

updateNodeFromFavorites(node as Folder)
})

/**
* Sort the favorites paths array and
* update the order property of the existing views
Expand Down Expand Up @@ -157,4 +172,17 @@ export default () => {
Navigation.remove(id)
updateAndSortViews()
}

// Update a folder from the favorites paths array and update the views
const updateNodeFromFavorites = function(node: Folder) {
const favoriteFolder = favoriteFolders.find((folder) => folder.fileid === node.fileid)

// Skip if it does not exists
if (favoriteFolder === undefined) {
return
}

removePathFromFavorites(favoriteFolder.path)
addToFavorites(node)
}
}

0 comments on commit 2a4b729

Please sign in to comment.