Skip to content

Commit daa3dfc

Browse files
committed
feat: replace "All languages" download button with one way "Update all" download link
1 parent a742d25 commit daa3dfc

2 files changed

Lines changed: 24 additions & 34 deletions

File tree

Scribe/InstallationTab/DownloadDataScreen.swift

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -157,27 +157,22 @@ struct LanguageListView: View {
157157
comment: ""
158158
)
159159

160-
private let allLanguagesText = NSLocalizedString(
161-
"i18n.app.download.menu_ui.download_data.all_languages",
162-
value: "All languages",
163-
comment: ""
164-
)
165-
166160
@State private var showConfirmDialog = false
167161
@State private var targetLanguage = ""
168162
@State private var selectedLanguageCode = ""
169163
let userDefaults = UserDefaults(suiteName: "group.be.scri.userDefaultsContainer")!
170164

171-
private func handleButtonClick(targetLang: String, langCode: String) {
172-
if langCode == "all" {
173-
let toDownload = stateManager.downloadStates.keys.filter {
165+
private func handleUpdateAllLanguages() {
166+
let toDownload = stateManager.downloadStates.keys.filter {
174167
stateManager.downloadStates[$0] != .updated && stateManager.downloadStates[$0] != .downloading
175-
}
176-
for lang in toDownload {
168+
}
169+
170+
for lang in toDownload {
177171
stateManager.handleDownloadAction(key: lang)
178172
}
179-
return
180-
}
173+
}
174+
175+
private func handleButtonClick(targetLang: String, langCode: String) {
181176

182177
targetLanguage = targetLang
183178
selectedLanguageCode = langCode
@@ -189,16 +184,6 @@ struct LanguageListView: View {
189184
}
190185
}
191186

192-
// Determines the button state for the "All languages" option based on the states of individual languages.
193-
private var allLanguagesState: ButtonState {
194-
let states = stateManager.downloadStates.values
195-
if states.allSatisfy({ $0 == .updated }) { return .updated }
196-
if states.allSatisfy({ $0 == .downloading }) { return .downloading }
197-
let actionable = states.filter({ $0 != .updated })
198-
if actionable.allSatisfy({ $0 == .update }) { return .update }
199-
return .ready
200-
}
201-
202187
var body: some View {
203188
ZStack {
204189
VStack(alignment: .leading, spacing: 6) {
@@ -209,17 +194,22 @@ struct LanguageListView: View {
209194
EmptyStateView()
210195
} else {
211196
VStack(spacing: 0) {
212-
LanguageDownloadCard(
213-
language: allLanguagesText,
214-
state: allLanguagesState,
215-
action: {
216-
handleButtonClick(targetLang: allLanguagesText, langCode: "all")
197+
HStack {
198+
Spacer()
199+
Text(NSLocalizedString(
200+
"i18n.app.download.menu_ui.download_data.update_all",
201+
value: "Update all",
202+
comment: ""
203+
))
204+
.foregroundColor(Color("linkBlue"))
205+
.font(.system(size: 20, weight: .medium))
206+
.padding(.horizontal, 12)
207+
.padding(.bottom, 10)
208+
.onTapGesture {
209+
handleUpdateAllLanguages()
217210
}
218-
)
219-
220-
Divider()
221-
.padding(.vertical, 8)
222-
211+
}
212+
.padding(.horizontal, 4)
223213
ForEach(Array(languages.enumerated()), id: \.offset) { index, section in
224214
let langCode: String = {
225215
if case let .specificLang(code) = section.sectionState {

Scribe/InstallationTab/DownloadStateManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class DownloadStateManager: ObservableObject {
2121

2222
/// Initialize download states for languages.
2323
func initializeStates(languages: [String]) {
24-
for language in languages where language != "all" {
24+
for language in languages {
2525
if downloadStates[language] != nil { continue }
2626

2727
// Check if data exists locally.

0 commit comments

Comments
 (0)