Simplify environment pass in, highlight selected items on other tabs as well

This commit is contained in:
Balazs Perlaki-Horvath 2025-04-12 14:40:42 +02:00
parent fcb2e2e4fa
commit 42b7edc645
5 changed files with 33 additions and 24 deletions

View File

@ -236,23 +236,11 @@ struct RootView: View {
case .opened: case .opened:
MultiZimFilesOpened() MultiZimFilesOpened()
case .categories: case .categories:
<<<<<<< HEAD DetailSidePanel(content: { ZimFilesCategories(dismiss: nil) })
ZimFilesCategories(dismiss: nil)
.modifier(LibraryZimFileDetailSidePanel())
.modifier(SearchFocused(isSearchFocused: isSearchFocused))
=======
DetailSidePanel(content: { selection in ZimFilesCategories(dismiss: nil).environmentObject(selection) })
>>>>>>> 1f496b8e (Make selection tab scoped)
case .downloads: case .downloads:
DetailSidePanel(content: { selection in ZimFilesDownloads(dismiss: nil).environmentObject(selection) }) DetailSidePanel(content: { ZimFilesDownloads(dismiss: nil) })
case .new: case .new:
<<<<<<< HEAD DetailSidePanel(content: { ZimFilesNew(dismiss: nil) })
ZimFilesNew(dismiss: nil)
.modifier(LibraryZimFileDetailSidePanel())
.modifier(SearchFocused(isSearchFocused: isSearchFocused))
=======
DetailSidePanel(content: { selection in ZimFilesNew(dismiss: nil).environmentObject(selection) })
>>>>>>> 1f496b8e (Make selection tab scoped)
default: default:
EmptyView() EmptyView()
} }

View File

@ -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 * Kiwix is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by * under the terms of the GNU General Public License as published by
@ -20,6 +20,7 @@ import SwiftUI
import Combine import Combine
struct DownloadTaskCell: View { struct DownloadTaskCell: View {
@EnvironmentObject var selection: SelectedZimFileViewModel
@State private var isHovering: Bool = false @State private var isHovering: Bool = false
@State private var downloadState = DownloadState(downloaded: 0, total: 1, resumeData: nil) @State private var downloadState = DownloadState(downloaded: 0, total: 1, resumeData: nil)
@ -63,7 +64,12 @@ struct DownloadTaskCell: View {
}.font(.caption).foregroundColor(.secondary) }.font(.caption).foregroundColor(.secondary)
} }
.padding() .padding()
.background(CellBackground.colorFor(isHovering: isHovering)) .background(
CellBackground.colorFor(
isHovering: isHovering,
isSelected: selection.isSelected(downloadZimFile)
)
)
.clipShape(CellBackground.clipShapeRectangle) .clipShape(CellBackground.clipShapeRectangle)
.onHover { self.isHovering = $0 } .onHover { self.isHovering = $0 }
.onReceive(DownloadService.shared.progress.publisher) { states in .onReceive(DownloadService.shared.progress.publisher) { states in

View File

@ -131,16 +131,16 @@ struct MultiZimFilesDetail: View {
struct DetailSidePanel<Content: View>: View { struct DetailSidePanel<Content: View>: View {
@StateObject private var selection = SelectedZimFileViewModel() @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 contentView = content
} }
var body: some View { var body: some View {
VStack(spacing: 0) { VStack(spacing: 0) {
Divider() Divider()
contentView(selection).safeAreaInset(edge: .trailing, spacing: 0) { contentView().safeAreaInset(edge: .trailing, spacing: 0) {
HStack(spacing: 0) { HStack(spacing: 0) {
Divider() Divider()
if let zimFile = selection.selectedZimFile { if let zimFile = selection.selectedZimFile {
@ -151,7 +151,7 @@ struct DetailSidePanel<Content: View>: View {
} }
}.frame(width: 275).background(.ultraThinMaterial) }.frame(width: 275).background(.ultraThinMaterial)
} }
} }.environmentObject(selection)
} }
} }

View File

@ -141,7 +141,13 @@ private struct CategoryGrid: View {
if sections.count <= 1 { if sections.count <= 1 {
ForEach(section) { zimFile in ForEach(section) { zimFile in
LibraryZimFileContext( LibraryZimFileContext(
content: { ZimFileCell(zimFile, prominent: .size) }, content: {
ZimFileCell(
zimFile,
prominent: .size,
isSelected: selection.isSelected(zimFile)
)
},
zimFile: zimFile, zimFile: zimFile,
selection: selection, selection: selection,
dismiss: dismiss) dismiss: dismiss)
@ -150,7 +156,12 @@ private struct CategoryGrid: View {
Section { Section {
ForEach(section) { zimFile in ForEach(section) { zimFile in
LibraryZimFileContext( LibraryZimFileContext(
content: { ZimFileCell(zimFile, prominent: .size) }, content: { ZimFileCell(
zimFile,
prominent: .size,
isSelected: selection.isSelected(zimFile)
)
},
zimFile: zimFile, zimFile: zimFile,
selection: selection, selection: selection,
dismiss: dismiss) dismiss: dismiss)

View File

@ -113,7 +113,11 @@ struct ZimFilesNew: View {
ForEach(viewModel.zimFiles, id: \.fileID) { zimFile in ForEach(viewModel.zimFiles, id: \.fileID) { zimFile in
LibraryZimFileContext( LibraryZimFileContext(
content: { content: {
ZimFileCell(zimFile, prominent: .name) ZimFileCell(
zimFile,
prominent: .name,
isSelected: selection.isSelected(zimFile)
)
}, },
zimFile: zimFile, zimFile: zimFile,
selection: selection, selection: selection,