Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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: 11 additions & 0 deletions ONMIR/Core/Enum/BookStatus/BookStatusTypeKind.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ public final class BookStatusTypeKind: NSObject, NSSecureCoding, @unchecked Send

let status: BookStatusType

var displayName: String {
switch status {
case .toRead:
return "To Read"
case .reading:
return "Reading"
case .completed:
return "Completed"
}
}

init(status: BookStatusType) {
self.status = status
super.init()
Expand Down
26 changes: 4 additions & 22 deletions ONMIR/Domain/Representation/BookRepresentation.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import Foundation

public struct BookRepresentation: Sendable, Hashable {
// Core book properties matching BookEntity
public let originalBookID: String
public let originalBookID: String?
public let title: String
public let author: String?
public let isbn: String?
Expand All @@ -11,7 +10,7 @@ public struct BookRepresentation: Sendable, Hashable {
public let publishedDate: Date?
public let publisher: String?
public let rating: Double
public let source: BookSourceType
public let source: BookSourceType?
public let status: BookStatusType?
public let coverImageURL: URL?

Expand Down Expand Up @@ -46,7 +45,7 @@ public struct BookRepresentation: Sendable, Hashable {

extension BookRepresentation {
public init(from bookEntity: BookEntity) {
self.originalBookID = bookEntity.originalBookID ?? ""
self.originalBookID = bookEntity.originalBookID
self.title = bookEntity.title ?? ""
self.author = bookEntity.author
self.isbn = bookEntity.isbn
Expand All @@ -55,25 +54,8 @@ extension BookRepresentation {
self.publishedDate = bookEntity.publishedDate
self.publisher = bookEntity.publisher
self.rating = bookEntity.rating
self.source = bookEntity.source?.sourceType ?? .googleBooks
self.source = bookEntity.source?.sourceType
self.status = bookEntity.status?.status
self.coverImageURL = bookEntity.coverImageURL
}

public func toBookEntity(in context: NSManagedObjectContext) -> BookEntity {
let bookEntity = BookEntity(context: context)
bookEntity.originalBookID = originalBookID
bookEntity.title = title
bookEntity.author = author
bookEntity.isbn = isbn
bookEntity.isbn13 = isbn13
bookEntity.pageCount = pageCount
bookEntity.publishedDate = publishedDate
bookEntity.publisher = publisher
bookEntity.rating = rating
bookEntity.source = BookSourceTypeKind(sourceType: source)
bookEntity.status = status.map { BookStatusTypeKind(status: $0) }
bookEntity.coverImageURL = coverImageURL
return bookEntity
}
}
48 changes: 47 additions & 1 deletion ONMIR/Feature/BookDetail/BookDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ final class BookDetailViewController: UIViewController {
case bookInfo
case readingLogs
case quotes
case bookDetails
}

enum Item: Hashable, @unchecked Sendable {
Expand All @@ -16,6 +17,7 @@ final class BookDetailViewController: UIViewController {
case quote(QuoteEntity)
case addRecord
case addQuote
case bookDetails(BookEntity)
}

private let viewModel = BookDetailViewModel()
Expand Down Expand Up @@ -208,10 +210,11 @@ final class BookDetailViewController: UIViewController {
private func updateSnapshot() {
var snapshot = NSDiffableDataSourceSnapshot<Section, Item>()

snapshot.appendSections([.bookInfo, .readingLogs, .quotes])
snapshot.appendSections([.bookInfo, .readingLogs, .quotes, .bookDetails])

if let book = viewModel.book {
snapshot.appendItems([.book(book)], toSection: .bookInfo)
snapshot.appendItems([.bookDetails(book)], toSection: .bookDetails)
}

let logItems: [Item] = [.addRecord] + viewModel.recentReadingLogs.map { Item.readingLog($0) }
Expand Down Expand Up @@ -253,6 +256,14 @@ final class BookDetailViewController: UIViewController {
}
}

let bookDetailsInfoCellRegistration = UICollectionView.CellRegistration<
BookDetailsInfoCell, BookEntity
> { [weak self] cell, indexPath, book in
cell.configure(with: book) {
self?.collectionView.performBatchUpdates(nil, completion: nil)
}
}

let headerRegistration = UICollectionView.SupplementaryRegistration<
SectionHeaderView
>(elementKind: UICollectionView.elementKindSectionHeader) {
Expand Down Expand Up @@ -319,6 +330,12 @@ final class BookDetailViewController: UIViewController {
for: indexPath,
item: .newQuote
)
case .bookDetails(let book):
return collectionView.dequeueConfiguredReusableCell(
using: bookDetailsInfoCellRegistration,
for: indexPath,
item: book
)
}
}

Expand Down Expand Up @@ -346,6 +363,8 @@ final class BookDetailViewController: UIViewController {
return self.createReadingLogsSection()
case .quotes:
return self.createQuotesSection()
case .bookDetails:
return self.createBookDetailsSection()
}
}
}
Expand Down Expand Up @@ -453,6 +472,33 @@ final class BookDetailViewController: UIViewController {
return section
}

private func createBookDetailsSection() -> NSCollectionLayoutSection {
let itemSize = NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1.0),
heightDimension: .estimated(200)
)
let item = NSCollectionLayoutItem(layoutSize: itemSize)

let groupSize = NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1.0),
heightDimension: .estimated(200)
)
let group = NSCollectionLayoutGroup.horizontal(
layoutSize: groupSize,
subitems: [item]
)

let section = NSCollectionLayoutSection(group: group)
section.contentInsets = NSDirectionalEdgeInsets(
top: 0,
leading: 0,
bottom: 24,
trailing: 0
)

return section
}

private func updateBackgroundImage(with book: BookEntity) {
guard let coverURL = book.coverImageURL else { return }

Expand Down
Loading