Skip to content

Commit ce75623

Browse files
committed
feat: All languages button download state and handle click
1 parent 9e6318a commit ce75623

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

Scribe/InstallationTab/DownloadDataScreen.swift

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,16 @@ struct LanguageListView: View {
164164
let userDefaults = UserDefaults(suiteName: "group.be.scri.userDefaultsContainer")!
165165

166166
private func handleButtonClick(targetLang: String, langCode: String) {
167+
if langCode == "all" {
168+
let toDownload = stateManager.downloadStates.keys.filter {
169+
stateManager.downloadStates[$0] != .updated && stateManager.downloadStates[$0] != .downloading
170+
}
171+
for lang in toDownload {
172+
stateManager.handleDownloadAction(key: lang)
173+
}
174+
return
175+
}
176+
167177
targetLanguage = targetLang
168178
selectedLanguageCode = langCode
169179
let currentState = stateManager.downloadStates[langCode] ?? .ready
@@ -174,6 +184,14 @@ struct LanguageListView: View {
174184
}
175185
}
176186

187+
private var allLanguagesState: ButtonState {
188+
let states = stateManager.downloadStates.values
189+
if states.allSatisfy({ $0 == .downloading }) { return .downloading }
190+
if states.allSatisfy({ $0 == .updated }) { return .updated }
191+
if states.contains(.update) { return .update }
192+
return .ready
193+
}
194+
177195
var body: some View {
178196
ZStack {
179197
VStack(alignment: .leading, spacing: 6) {
@@ -186,7 +204,7 @@ struct LanguageListView: View {
186204
VStack(spacing: 0) {
187205
LanguageDownloadCard(
188206
language: allLanguagesText,
189-
state: stateManager.downloadStates["all"] ?? .ready,
207+
state: allLanguagesState,
190208
action: {
191209
handleButtonClick(targetLang: allLanguagesText, langCode: "all")
192210
}

0 commit comments

Comments
 (0)