Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions TablePro/Views/Sidebar/FavoritesTabView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import SwiftUI
internal struct FavoritesTabView: View {
@State private var viewModel: FavoritesSidebarViewModel
@State private var selectedFavoriteIds: Set<String> = []
@State private var lastInsertedFavoriteId: String?
@State private var folderToDelete: SQLFavoriteFolder?
@State private var showDeleteFolderAlert = false
@FocusState private var isRenameFocused: Bool
Expand Down Expand Up @@ -79,6 +80,24 @@ internal struct FavoritesTabView: View {
.onDeleteCommand {
deleteSelectedFavorites()
}
.onChange(of: selectedFavoriteIds) { oldIds, newIds in
if newIds.isEmpty {
lastInsertedFavoriteId = nil
return
}

let added = newIds.subtracting(oldIds)
guard added.count == 1,
newIds.count == 1,
let selectedId = added.first,
selectedId != lastInsertedFavoriteId else { return }

let allFavorites = collectFavorites(from: viewModel.filteredItems(searchText: searchText))
if let favorite = allFavorites.first(where: { "fav-\($0.id)" == selectedId }) {
coordinator?.insertFavorite(favorite)
lastInsertedFavoriteId = selectedId
}
}
}

/// Renders tree items with DisclosureGroup for folders.
Expand Down
Loading