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:
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()
}

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
* 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

View File

@ -131,16 +131,16 @@ struct MultiZimFilesDetail: View {
struct DetailSidePanel<Content: View>: 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<Content: View>: View {
}
}.frame(width: 275).background(.ultraThinMaterial)
}
}
}.environmentObject(selection)
}
}

View File

@ -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)

View File

@ -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,