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
11 changes: 7 additions & 4 deletions Projects/Feature/Sources/Utilities/BookDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import Service
public struct BookDetailView: View {
@Environment(\.dismiss) private var dismiss
@StateObject private var viewModel: BookDetailViewModel
private let onBack: () -> Void
private let onBack: (() -> Void)?

public init(bookId: Int, booksService: BooksService = BooksService(), onBack: @escaping () -> Void = {}) {
public init(bookId: Int, booksService: BooksService = BooksService(), onBack: (() -> Void)? = nil) {
_viewModel = StateObject(wrappedValue: BookDetailViewModel(bookId: bookId, service: booksService))
self.onBack = onBack
}
Expand All @@ -25,8 +25,11 @@ public struct BookDetailView: View {
}

private func goBack() {
onBack()
dismiss()
if let onBack {
onBack()
} else {
dismiss()
}
}

private func detail(_ book: BookDetail, scale: CGFloat) -> some View {
Expand Down
Loading