Open source CapCut alternative.
TypeScript
fix(ios): a project card keeps its poster across a refresh
David Le7cca5fc6905c
diff --git a/apps/ios/Donkey/Controllers/CutCloudClient.swift b/apps/ios/Donkey/Controllers/CutCloudClient.swiftindex 38a66e08..fd086eaa 100644--- a/apps/ios/Donkey/Controllers/CutCloudClient.swift+++ b/apps/ios/Donkey/Controllers/CutCloudClient.swift@@ -440,13 +440,14 @@ extension CutCloudClient: CloudProjectsServicing {if FileManager.default.fileExists(atPath: file.localPath) { return file }guard let image = await thumbnailImage(for: project),let data = image.jpegData(compressionQuality: 0.8) else { return nil }- // Versions of this project from before the edit leave with the refresh.+ try? data.write(to: file, options: .atomic)+ // Versions of this project from before the edit leave once the new+ // poster is on disk, so a card never points at a file that is gone.let stale = (try? FileManager.default.contentsOfDirectory(atPath: directory.localPath))?- .filter { $0.hasPrefix("\(project.id)-") } ?? []+ .filter { $0.hasPrefix("\(project.id)-") && $0 != file.lastPathComponent } ?? []for name in stale {try? FileManager.default.removeItem(at: directory.appending(path: name))}- try? data.write(to: file, options: .atomic)return file}diff --git a/apps/ios/DonkeyKit/Sources/DonkeyKitModels/Projects.swift b/apps/ios/DonkeyKit/Sources/DonkeyKitModels/Projects.swiftindex a79ad9b0..d222caea 100644--- a/apps/ios/DonkeyKit/Sources/DonkeyKitModels/Projects.swift+++ b/apps/ios/DonkeyKit/Sources/DonkeyKitModels/Projects.swift@@ -31,6 +31,7 @@ public final class ProjectsModel {private var summaries: [String: RemoteProject] = [:]private var latestExports: [String: RemoteExport] = [:]+ private var thumbnails: [String: URL] = [:]private let service: (any CloudProjectsServicing)?public init(service: (any CloudProjectsServicing)? = nil) {@@ -38,14 +39,24 @@ public final class ProjectsModel {}/// Pull the listing and per-project latest exports, then fill thumbnails- /// as they cache — cards paint with names first, posters as they land.+ /// as they cache. A card keeps the poster and export it already carries+ /// while the refresh runs, so revisiting the screen repaints in place.public func refresh() async {guard let service, !isLoading else { return }isLoading = truedefer { isLoading = false }guard let remote = try? await service.fetchProjects() else { return }summaries = Dictionary(uniqueKeysWithValues: remote.map { ($0.id, $0) })- projects = remote.map { project(for: $0, latest: nil, thumbnail: nil) }+ let live = Set(remote.map(\.id))+ latestExports = latestExports.filter { live.contains($0.key) }+ thumbnails = thumbnails.filter { live.contains($0.key) }+ projects = remote.map { project(for: $0, latest: latestExports[$0.id], thumbnail: thumbnails[$0.id]) }+ async let exports: Void = fillExports(remote, service: service)+ async let posters: Void = fillThumbnails(remote, service: service)+ _ = await (exports, posters)+ }++ private func fillExports(_ remote: [RemoteProject], service: any CloudProjectsServicing) async {await withTaskGroup(of: (String, RemoteExport?).self) { group infor summary in remote {group.addTask { (summary.id, (try? await service.fetchExports(projectId: summary.id))?.first) }@@ -57,12 +68,17 @@ public final class ProjectsModel {projects[index] = project(for: summary, latest: latest, thumbnail: projects[index].thumbnail)}}+ }++ private func fillThumbnails(_ remote: [RemoteProject], service: any CloudProjectsServicing) async {await withTaskGroup(of: (String, URL?).self) { group infor summary in remote {group.addTask { (summary.id, await service.thumbnailFile(for: summary)) }}for await (id, file) in group {- guard let file, let index = projects.firstIndex(where: { $0.id == id }) else { continue }+ guard let file else { continue }+ thumbnails[id] = file+ guard let index = projects.firstIndex(where: { $0.id == id }) else { continue }projects[index].thumbnail = file}}