Skip to content
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
192 changes: 114 additions & 78 deletions Keychy/Keychy.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// BundleSwitchPopup.swift
// Keychy
//
// Created by Claude on 2/3/26.
// Created by 길지훈 on 2/3/26.
//

import SwiftUI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
// Created by 김서현 on 1/12/26.
//

// MARK: - BundleViewModel+CRUD
//
// Firebase 데이터 쓰기
// - createBundle: 뭉치 생성
// - createKeyringDataList: 키링 → Scene 데이터 변환
// - updateBundleMainStatus: 대표 뭉치 설정
// - updateBundleName: 이름 변경
// - incrementUseCount: 사용 횟수 증가

import FirebaseFirestore

extension BundleViewModel {
Expand Down Expand Up @@ -240,4 +249,40 @@ extension BundleViewModel {
}
}
}

// MARK: - 사용 횟수 증가

/// 배경, 카라비너의 사용 횟수를 증가시키는 메서드
func incrementUseCount(
carabinerId: String?,
backgroundId: String?
) {
if let carabinerId = carabinerId, !carabinerId.isEmpty {
db.collection("Carabiner")
.document(carabinerId)
.updateData([
"useCount": FieldValue.increment(Int64(1))
]) { error in
if let error = error {
print("[useCount] Carabiner 증가 실패: \(error)")
} else {
print("[useCount] Carabiner 증가 성공: \(carabinerId)")
}
}
}

if let backgroundId = backgroundId, !backgroundId.isEmpty {
db.collection("Background")
.document(backgroundId)
.updateData([
"useCount": FieldValue.increment(Int64(1))
]) { error in
if let error = error {
print("[useCount] Background 증가 실패: \(error)")
} else {
print("[useCount] Background 증가 성공: \(backgroundId)")
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
//
// BundleViewModel+Cache.swift
// Keychy
//
// Created by 길지훈 on 2/5/26.
//

// MARK: - BundleViewModel+Cache
//
// 캐시 및 씬 리로드 최적화
// - loadBundleImageFromCache: 캐시에서 이미지 로드
// - saveBundleImageToCache: 이미지 캐시 저장
// - shouldSkipReloadForReturnedConfig: 리로드 스킵 판단
// - updateLastConfigIds: 구성 ID 업데이트

import Foundation

extension BundleViewModel {

// MARK: - 이미지 캐시

/// 캐시에서 번들 이미지를 로드하여 bundleCapturedImage에 설정
@discardableResult
func loadBundleImageFromCache(bundle: KeyringBundle) -> Bool {
guard let documentId = bundle.documentId else {
print("[BundleViewModel] 번들 documentId가 없습니다.")
return false
}

if let imageData = BundleImageCache.shared.load(for: documentId) {
self.bundleCapturedImage = imageData
print("[BundleViewModel] 캐시에서 번들 이미지 로드 성공: \(documentId)")
return true
} else {
print("[BundleViewModel] 캐시에 번들 이미지가 없습니다: \(documentId)")
return false
}
}

/// 뷰모델에 저장된 뭉치 이미지를 BundleImageCache에 저장
func saveBundleImageToCache(
bundleId: String,
bundleName: String,
widgetImageData: Data? = nil,
createdAt: Date = Date()
) {
guard let imageData = bundleCapturedImage else {
return
}
BundleImageCache.shared.syncBundle(
id: bundleId,
name: bundleName,
fullImageData: imageData,
widgetImageData: widgetImageData,
createdAt: createdAt
)
}

// MARK: - 씬 리로드 최적화

/// 이전 화면에서 전달된 구성과 동일하면 씬 리로드 스킵
///
/// - Returns: true면 동일 구성 → 리로드 스킵, false면 정상 로드
///
/// 편집 화면에서 돌아올 때 변경사항이 없으면 씬을 다시 그리지 않음
func shouldSkipReloadForReturnedConfig() -> Bool {
guard let returnBGId = returnBackgroundId,
let returnCBId = returnCarabinerId,
let returnKRId = returnKeyringsId else {
return false
}

let same = (returnBGId == lastBackgroundIdForDetail) &&
(returnCBId == lastCarabinerIdForDetail) &&
(returnKRId == lastKeyringsIdForDetail)

if same {
returnBackgroundId = nil
returnCarabinerId = nil
returnKeyringsId = nil
}
return same
}

/// BundleDetailView가 뭉치 로드를 마친 후 현재 구성 ID 저장
func updateLastConfigIds(
background: Background?,
carabiner: Carabiner?,
keyringDataList: [MultiKeyringScene.KeyringData]
) {
lastBackgroundIdForDetail = makeBackgroundId(background)
lastCarabinerIdForDetail = makeCarabinerId(carabiner)
lastKeyringsIdForDetail = makeKeyringsId(keyringDataList)
}
}

This file was deleted.

Loading