Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix macOS unlink last ZIM file issue #810

Merged
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Support/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@

"zim_file_missing_indicator.help" = "Zim file is missing.";

"library.zim_file_details.side_panel.message" = "Select a ZIM file to see detail";
"library.zim_file_details.side_panel.message" = "Select a ZIM file to see details";
"library.zim_file_context.main_page.label" = "Main Page";
"library.zim_file_context.random.label" = "Random Page";
"library.zim_file_context.copy_url" = "Copy URL";
Expand Down
4 changes: 4 additions & 0 deletions Views/Library/ZimFilesOpened.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct ZimFilesOpened: View {
animation: .easeInOut
) private var zimFiles: FetchedResults<ZimFile>
@State private var isFileImporterPresented = false
@EnvironmentObject private var viewModel: LibraryViewModel
let dismiss: (() -> Void)? // iOS only

var body: some View {
Expand All @@ -46,6 +47,9 @@ struct ZimFilesOpened: View {
Message(text: "zim_file_opened.overlay.no-opened.message".localized)
}
}
.onChange(of: zimFiles.count) { _ in
viewModel.selectedZimFile = zimFiles.first // makes sure we also nil out, if all ZIMs were unlinked
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explanation: zimFiles.first returns an optional, so it covers both cases, when there's still files to pick from, and when there's nothing left.

// not using OpenFileButton here, because it does not work on iOS/iPadOS 15 when this view is in a modal
.fileImporter(
isPresented: $isFileImporterPresented,
Expand Down