From 42b7edc645d7d74127195e868bf1be4fcee750b9 Mon Sep 17 00:00:00 2001 From: Balazs Perlaki-Horvath Date: Sat, 12 Apr 2025 14:40:42 +0200 Subject: [PATCH] Simplify environment pass in, highlight selected items on other tabs as well --- App/App_macOS.swift | 18 +++--------------- Views/BuildingBlocks/DownloadTaskCell.swift | 10 ++++++++-- Views/Library/Library.swift | 8 ++++---- Views/Library/ZimFilesCategories.swift | 15 +++++++++++++-- Views/Library/ZimFilesNew.swift | 6 +++++- 5 files changed, 33 insertions(+), 24 deletions(-) diff --git a/App/App_macOS.swift b/App/App_macOS.swift index b4ddb5c3..5b299c73 100644 --- a/App/App_macOS.swift +++ b/App/App_macOS.swift @@ -236,23 +236,11 @@ struct RootView: View { case .opened: MultiZimFilesOpened() case .categories: -<<<<<<< HEAD - ZimFilesCategories(dismiss: nil) - .modifier(LibraryZimFileDetailSidePanel()) - .modifier(SearchFocused(isSearchFocused: isSearchFocused)) -======= - DetailSidePanel(content: { selection in ZimFilesCategories(dismiss: nil).environmentObject(selection) }) ->>>>>>> 1f496b8e (Make selection tab scoped) + DetailSidePanel(content: { ZimFilesCategories(dismiss: nil) }) case .downloads: - DetailSidePanel(content: { selection in ZimFilesDownloads(dismiss: nil).environmentObject(selection) }) + DetailSidePanel(content: { ZimFilesDownloads(dismiss: nil) }) case .new: -<<<<<<< HEAD - ZimFilesNew(dismiss: nil) - .modifier(LibraryZimFileDetailSidePanel()) - .modifier(SearchFocused(isSearchFocused: isSearchFocused)) -======= - DetailSidePanel(content: { selection in ZimFilesNew(dismiss: nil).environmentObject(selection) }) ->>>>>>> 1f496b8e (Make selection tab scoped) + DetailSidePanel(content: { ZimFilesNew(dismiss: nil) }) default: EmptyView() } diff --git a/Views/BuildingBlocks/DownloadTaskCell.swift b/Views/BuildingBlocks/DownloadTaskCell.swift index 66866fba..298eef70 100644 --- a/Views/BuildingBlocks/DownloadTaskCell.swift +++ b/Views/BuildingBlocks/DownloadTaskCell.swift @@ -1,5 +1,5 @@ /* -65;6800;1c * This file is part of Kiwix for iOS & macOS. + * This file is part of Kiwix for iOS & macOS. * * Kiwix is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by @@ -20,6 +20,7 @@ import SwiftUI import Combine struct DownloadTaskCell: View { + @EnvironmentObject var selection: SelectedZimFileViewModel @State private var isHovering: Bool = false @State private var downloadState = DownloadState(downloaded: 0, total: 1, resumeData: nil) @@ -63,7 +64,12 @@ struct DownloadTaskCell: View { }.font(.caption).foregroundColor(.secondary) } .padding() - .background(CellBackground.colorFor(isHovering: isHovering)) + .background( + CellBackground.colorFor( + isHovering: isHovering, + isSelected: selection.isSelected(downloadZimFile) + ) + ) .clipShape(CellBackground.clipShapeRectangle) .onHover { self.isHovering = $0 } .onReceive(DownloadService.shared.progress.publisher) { states in diff --git a/Views/Library/Library.swift b/Views/Library/Library.swift index 3f1d36a6..fbe737a7 100644 --- a/Views/Library/Library.swift +++ b/Views/Library/Library.swift @@ -131,16 +131,16 @@ struct MultiZimFilesDetail: View { struct DetailSidePanel: View { @StateObject private var selection = SelectedZimFileViewModel() - private let contentView: (SelectedZimFileViewModel) -> Content + private let contentView: () -> Content - init(@ViewBuilder content: @escaping (SelectedZimFileViewModel) -> Content) { + init(@ViewBuilder content: @escaping () -> Content) { contentView = content } var body: some View { VStack(spacing: 0) { Divider() - contentView(selection).safeAreaInset(edge: .trailing, spacing: 0) { + contentView().safeAreaInset(edge: .trailing, spacing: 0) { HStack(spacing: 0) { Divider() if let zimFile = selection.selectedZimFile { @@ -151,7 +151,7 @@ struct DetailSidePanel: View { } }.frame(width: 275).background(.ultraThinMaterial) } - } + }.environmentObject(selection) } } diff --git a/Views/Library/ZimFilesCategories.swift b/Views/Library/ZimFilesCategories.swift index 6b7088c1..cafd9ea2 100644 --- a/Views/Library/ZimFilesCategories.swift +++ b/Views/Library/ZimFilesCategories.swift @@ -141,7 +141,13 @@ private struct CategoryGrid: View { if sections.count <= 1 { ForEach(section) { zimFile in LibraryZimFileContext( - content: { ZimFileCell(zimFile, prominent: .size) }, + content: { + ZimFileCell( + zimFile, + prominent: .size, + isSelected: selection.isSelected(zimFile) + ) + }, zimFile: zimFile, selection: selection, dismiss: dismiss) @@ -150,7 +156,12 @@ private struct CategoryGrid: View { Section { ForEach(section) { zimFile in LibraryZimFileContext( - content: { ZimFileCell(zimFile, prominent: .size) }, + content: { ZimFileCell( + zimFile, + prominent: .size, + isSelected: selection.isSelected(zimFile) + ) + }, zimFile: zimFile, selection: selection, dismiss: dismiss) diff --git a/Views/Library/ZimFilesNew.swift b/Views/Library/ZimFilesNew.swift index d1aaf511..8512cd07 100644 --- a/Views/Library/ZimFilesNew.swift +++ b/Views/Library/ZimFilesNew.swift @@ -113,7 +113,11 @@ struct ZimFilesNew: View { ForEach(viewModel.zimFiles, id: \.fileID) { zimFile in LibraryZimFileContext( content: { - ZimFileCell(zimFile, prominent: .name) + ZimFileCell( + zimFile, + prominent: .name, + isSelected: selection.isSelected(zimFile) + ) }, zimFile: zimFile, selection: selection,