Skip to content

ReadingLog 편집 추가#25

Open
baekteun wants to merge 1 commit intofeature/home-datafrom
feature/book-redcord-edit
Open

ReadingLog 편집 추가#25
baekteun wants to merge 1 commit intofeature/home-datafrom
feature/book-redcord-edit

Conversation

@baekteun
Copy link
Copy Markdown
Member

💡 배경 및 개요

ReadingLog 편집 추가

📃 작업내용

  • 책 기록 ContextMenu, Trailing Swipe Action을 통한 편집/삭제 지원
  • 고화질 이미지 로딩
  • 데이터 새로고침 지원

✅ PR 체크리스트

  • 이 작업으로 인해 변경이 필요한 문서가 변경되었나요? (e.g. .env, 노션, README)
  • 이 작업을 하고나서 공유해야할 팀원들에게 공유되었나요? (e.g. "API 개발 완료됐어요", "환경값 추가되었어요")
  • 작업한 코드가 정상적으로 동작하나요?
  • Merge 대상 브랜치가 올바른가요?
  • PR과 관련 없는 작업이 있지는 않나요?

🎸 기타

@github-actions
Copy link
Copy Markdown

✅ PR의 Assign 자동 지정을 성공했어요!

@baekteun

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @baekteun, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

이 PR은 독서 기록 및 인용구 관리 기능을 개선합니다. 사용자가 독서 기록과 인용구를 쉽게 편집하고 삭제할 수 있도록 ContextMenu와 Trailing Swipe Action을 추가하며, 고화질 이미지 로딩과 데이터 새로고침 기능을 구현하여 사용자 경험을 향상시킵니다.

Highlights

  • 독서 기록 편집/삭제 기능 추가: ContextMenu와 Trailing Swipe Action을 통해 독서 기록을 편집하고 삭제할 수 있습니다.
  • 인용구 편집/삭제 기능 추가: ContextMenu와 Trailing Swipe Action을 통해 인용구에 대한 편집 및 삭제 기능을 지원합니다 (현재 TODO 상태).
  • 고화질 이미지 로딩: Google Books API에서 extraLarge 이미지 링크를 우선적으로 사용하고, 이미지 URL에 고화질 파라미터를 추가하여 더 선명한 이미지를 로딩합니다.
  • 데이터 새로고침 지원: 독서 기록 저장 또는 삭제 후 관련 데이터를 자동으로 새로고침하여 최신 상태를 유지합니다.
  • BookRecordEditorViewController 통합 개선: 저장 완료 시 콜백을 통해 데이터 새로고침을 트리거할 수 있도록 BookRecordEditorViewController가 개선되었습니다.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

이 PR은 ReadingLog 편집 및 삭제 기능을 추가하고, 고화질 이미지 로딩 및 데이터 새로고침을 지원하는 변경 사항을 포함하고 있습니다. 전반적으로 코드 변경 사항은 명확하고 목적에 부합합니다. 몇 가지 리팩토링을 통해 코드 중복을 줄이고 가독성을 높일 수 있는 부분과, 이미지 URL 생성 시 발생할 수 있는 버그를 수정하는 것을 제안합니다.

self.thumbnailURL = URL(string: secureURL)
if let baseURL = URL(string: secureURL) {
var urlComponents = URLComponents(url: baseURL, resolvingAgainstBaseURL: false)
urlComponents?.queryItems?.append(URLQueryItem(name: "fife", value: "w400-h600"))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

urlComponents.queryItemsnil일 수 있는데, 이 경우 ?.append(...)는 아무 작업도 수행하지 않습니다. 이로 인해 fife 쿼리 파라미터가 추가되지 않는 버그가 발생할 수 있습니다. queryItemsnil인 경우를 처리하도록 코드를 수정해야 합니다.

Suggested change
urlComponents?.queryItems?.append(URLQueryItem(name: "fife", value: "w400-h600"))
urlComponents?.queryItems = (urlComponents?.queryItems ?? []) + [URLQueryItem(name: "fife", value: "w400-h600")]

Comment on lines +666 to +699
func collectionView(
_ collectionView: UICollectionView,
contextMenuConfiguration configuration: UIContextMenuConfiguration,
highlightPreviewForItemAt indexPath: IndexPath
) -> UITargetedPreview? {
guard let item = dataSource.itemIdentifier(for: indexPath) else { return nil }

switch item {
case .readingLog:
guard let cell = collectionView.cellForItem(at: indexPath) as? BookDetailViewController.ReadingLogCell,
let highlightView = cell.contextMenuHighlightView() else {
return nil
}

let parameters = UIPreviewParameters()
parameters.backgroundColor = .clear

return UITargetedPreview(view: highlightView, parameters: parameters)

case .quote:
guard let cell = collectionView.cellForItem(at: indexPath) as? BookDetailViewController.QuoteCell,
let highlightView = cell.contextMenuHighlightView() else {
return nil
}

let parameters = UIPreviewParameters()
parameters.backgroundColor = .clear

return UITargetedPreview(view: highlightView, parameters: parameters)

default:
return nil
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

이 메서드와 collectionView(_:contextMenuConfiguration:dismissalPreviewForItemAt:) 메서드의 내용이 거의 동일하여 코드 중복이 발생하고 있습니다. 중복을 제거하고 코드를 더 간결하게 만들기 위해, 공통 로직을 별도의 private 헬퍼 메서드로 추출하는 것을 고려해 보세요. 이렇게 하면 유지보수성이 향상됩니다.

예를 들어, 다음과 같은 헬퍼 메서드를 만들 수 있습니다:

private func getContextMenuTargetedPreview(forItemAt indexPath: IndexPath) -> UITargetedPreview? {
    guard let item = dataSource.itemIdentifier(for: indexPath) else { return nil }

    let cell = collectionView.cellForItem(at: indexPath)
    var highlightView: UIView?

    switch item {
    case .readingLog:
        highlightView = (cell as? ReadingLogCell)?.contextMenuHighlightView()
    case .quote:
        highlightView = (cell as? QuoteCell)?.contextMenuHighlightView()
    default:
        return nil
    }

    guard let viewToHighlight = highlightView else { return nil }

    let parameters = UIPreviewParameters()
    parameters.backgroundColor = .clear

    return UITargetedPreview(view: viewToHighlight, parameters: parameters)
}

그런 다음 두 UICollectionViewDelegate 메서드에서 이 헬퍼 메서드를 호출하면 됩니다.

Comment on lines 802 to +842
private func showAddNewRecord() {
print("Add new reading record tapped")
guard let book = viewModel.book else { return }

let recordViewModel = BookRecordEditorViewModel(book: book, editMode: .create)
let recordViewController = BookRecordEditorViewController(viewModel: recordViewModel) { [weak self] in
self?.refreshBookData()
}
let navigationController = UINavigationController(rootViewController: recordViewController)

if let sheet = navigationController.sheetPresentationController {
sheet.detents = [.medium(), .large()]
sheet.prefersGrabberVisible = true
}

present(navigationController, animated: true)
}

private func showAddNewQuote() {
print("Add new quote tapped")
}

private func refreshBookData() {
viewModel.loadBook(with: bookObjectID)
}

private func showEditReadingLog(_ readingLog: ReadingLogEntity) {
guard let book = viewModel.book else { return }

let recordViewModel = BookRecordEditorViewModel(book: book, editMode: .edit(readingLog))
let recordViewController = BookRecordEditorViewController(viewModel: recordViewModel) { [weak self] in
self?.refreshBookData()
}
let navigationController = UINavigationController(rootViewController: recordViewController)

if let sheet = navigationController.sheetPresentationController {
sheet.detents = [.medium(), .large()]
sheet.prefersGrabberVisible = true
}

present(navigationController, animated: true)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

showAddNewRecord() 메서드와 showEditReadingLog(_:) 메서드에 BookRecordEditorViewController를 생성하고 표시하는 로직이 중복되어 있습니다. 이 로직을 하나의 private 헬퍼 메서드로 추출하여 코드 중복을 줄이고 재사용성을 높일 수 있습니다.

예를 들어, 다음과 같은 헬퍼 메서드를 만들 수 있습니다.

private func showBookRecordEditor(with editMode: BookRecordEditorViewModel.EditMode) {
    guard let book = viewModel.book else { return }
    
    let recordViewModel = BookRecordEditorViewModel(book: book, editMode: editMode)
    let recordViewController = BookRecordEditorViewController(viewModel: recordViewModel) { [weak self] in
        self?.refreshBookData()
    }
    let navigationController = UINavigationController(rootViewController: recordViewController)
    
    if let sheet = navigationController.sheetPresentationController {
        sheet.detents = [.medium(), .large()]
        sheet.prefersGrabberVisible = true
    }
    
    present(navigationController, animated: true)
}

그런 다음 showAddNewRecord()showEditReadingLog(_:)에서 이 헬퍼 메서드를 호출하도록 수정하면 코드가 더 간결해집니다.

private func showAddNewRecord() {
    showBookRecordEditor(with: .create)
}

private func showEditReadingLog(_ readingLog: ReadingLogEntity) {
    showBookRecordEditor(with: .edit(readingLog))
}

}
} catch {
await MainActor.run {
let count = readingLogs.count
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

count 변수가 선언되었지만 이후 코드에서 사용되지 않고 있습니다. 불필요한 변수이므로 제거하는 것이 좋습니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant