Skip to content

[feature] 위젯 구현#166

Open
aado97 wants to merge 9 commits intodevelopfrom
feature/#155
Open

[feature] 위젯 구현#166
aado97 wants to merge 9 commits intodevelopfrom
feature/#155

Conversation

@aado97
Copy link
Copy Markdown
Contributor

@aado97 aado97 commented Jun 9, 2025

🚀 PR 개요

위젯구현

💡 PR 유형

  • ✨ Feature (기능 추가)
  • 🐞 Bugfix (버그 수정)
  • 🔧 Refactor (코드 리팩토링)
  • ⚙️ Chore (환경 설정)
  • 📝 Docs (문서 작성 및 수정)
  • ✅ Test (기능 테스트)

✏️ 변경 사항 요약

  • 위젯 구현
  • quote usecase 연결

🔗 관련 이슈

🧪 테스트 내역

  • 브라우저/기기에서 동작 확인
  • 엣지 케이스 테스트 완료
  • 기존 기능 영향 없음

🎨 스크린샷 또는 시연 영상 (선택)

기능 미리보기
예시 image

✅ PR 체크리스트

  • 커밋 메시지가 명확합니다
  • PR 제목이 컨벤션에 맞습니다
  • 관련 이슈 번호를 작성했습니다
  • 기능이 정상적으로 작동합니다
  • 불필요한 코드를 제거했습니다

💬 추가 설명 or 리뷰 포인트 (선택)

리뷰어가 중점적으로 봐야 할 부분이나 설명이 필요한 내용을 자유롭게 작성해주세요.

@aado97 aado97 added this to the Sprint 2 milestone Jun 9, 2025
@aado97 aado97 requested review from Monfi98, Syrbear and doyeonk429 June 9, 2025 08:50
@aado97 aado97 self-assigned this Jun 9, 2025
@aado97 aado97 added this to B.READ Jun 9, 2025
Comment on lines +59 to +90
/// 모든 `Quote` → `SharedQuote` 로 변환한 뒤
/// App Group(UserDefaults) 에 저장하고 위젯 타임라인을 즉시 갱신.
///
/// 1. 저장소에서 모든 Quote 를 가져옴.
/// 2. ISBN → 책 제목을 비동기로 조회하여 `SharedQuote` 생성
/// 3. `SharedQuotesStore.save(_:)` 호출로 JSON 덤프
/// 4. `WidgetCenter.shared.reloadAllTimelines()` 로 위젯 갱신
///
/// - Throws:
/// - `RepositoryError.fetchError` : Quote 또는 Book 로드 과정에서 발생
/// - `EncodingError` : JSON 인코딩 실패
private func syncSharedDefaults() async throws {
let allQuotes = try await quoteRepository.fetchAllQuotes()

let sharedQuotes: [SharedQuote] = try await withThrowingTaskGroup(of: SharedQuote.self) { group in
for quote in allQuotes {
group.addTask {
let title = try? await self.loadBookTitle(quote.isbn)
return SharedQuote(
id: quote.id,
content: quote.content,
bookTitle: title ?? "" // 제목 없으면 빈 문자열
)
}
}
return try await group.reduce(into: []) { $0.append($1) }
}

try SharedQuotesStore.save(sharedQuotes)

// 새로운 데이터가 쓰였으니 위젯 타임라인 즉시 갱신
WidgetCenter.shared.reloadAllTimelines()
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.

질문) 왜 Quote를 안쓰고 SharedQuote를 쓰나요?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

앱그룹으로 UserDefaults를 이용해 JSON으로 변경하는 과정이 필요한데 불필요한거 쳐내고 필요한것만 쓰기위해 재가공한것입니다.

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.

p0) 그렇다면 더더욱 필요없을 것 같습니다. AppGroup을 사용하면 앱내에서 같은 GroupContainer를 사용하기 때문에 SwiftData를 그대로 쓸 수 있습니다.

Comment on lines +35 to +36
let entry = randomEntry()
let nextUpdate = Calendar.current.date(byAdding: .minute, value: 30, to: entry.date)!
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.

ChatGPT사용할때 꼭 코드에 대해 확인하고 써주세요.

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

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[feature] 위젯

2 participants