diff --git a/VoiceInk/Services/DictionaryContextService.swift b/VoiceInk/Services/DictionaryContextService.swift index da3d596..fc86617 100644 --- a/VoiceInk/Services/DictionaryContextService.swift +++ b/VoiceInk/Services/DictionaryContextService.swift @@ -16,7 +16,7 @@ class DictionaryContextService { return "Important Vocabulary: \(wordsText)" } - /// Gets enabled custom dictionary words from UserDefaults + /// Gets all custom dictionary words from UserDefaults private func getDictionaryWords() -> [String]? { guard let data = UserDefaults.standard.data(forKey: "CustomDictionaryItems") else { return nil @@ -24,8 +24,8 @@ class DictionaryContextService { do { let items = try JSONDecoder().decode([DictionaryItem].self, from: data) - let enabledWords = items.filter { $0.isEnabled }.map { $0.word } - return enabledWords.isEmpty ? nil : enabledWords + let words = items.map { $0.word } + return words.isEmpty ? nil : words } catch { return nil } diff --git a/VoiceInk/Views/Dictionary/DictionaryView.swift b/VoiceInk/Views/Dictionary/DictionaryView.swift index 845ada4..9269c00 100644 --- a/VoiceInk/Views/Dictionary/DictionaryView.swift +++ b/VoiceInk/Views/Dictionary/DictionaryView.swift @@ -4,13 +4,33 @@ struct DictionaryItem: Identifiable, Hashable, Codable { let id: UUID var word: String var dateAdded: Date - var isEnabled: Bool - init(id: UUID = UUID(), word: String, dateAdded: Date = Date(), isEnabled: Bool = true) { + init(id: UUID = UUID(), word: String, dateAdded: Date = Date()) { self.id = id self.word = word self.dateAdded = dateAdded - self.isEnabled = isEnabled + } + + // Legacy support for decoding old data with isEnabled property + private enum CodingKeys: String, CodingKey { + case id, word, dateAdded, isEnabled + } + + init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + id = try container.decode(UUID.self, forKey: .id) + word = try container.decode(String.self, forKey: .word) + dateAdded = try container.decode(Date.self, forKey: .dateAdded) + // Ignore isEnabled during decoding - all items are enabled by default now + _ = try? container.decodeIfPresent(Bool.self, forKey: .isEnabled) + } + + func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(id, forKey: .id) + try container.encode(word, forKey: .word) + try container.encode(dateAdded, forKey: .dateAdded) + // Don't encode isEnabled anymore } } @@ -54,15 +74,8 @@ class DictionaryManager: ObservableObject { saveItems() } - func toggleWordState(id: UUID) { - if let index = items.firstIndex(where: { $0.id == id }) { - items[index].isEnabled.toggle() - saveItems() - } - } - var allWords: [String] { - items.filter { $0.isEnabled }.map { $0.word } + items.map { $0.word } } } @@ -118,11 +131,6 @@ struct DictionaryView: View { .font(.system(size: 12, weight: .medium)) .foregroundColor(.secondary) - Text("Toggle words on/off to optimize recognition. Disable unnecessary words to improve local AI model performance.") - .font(.system(size: 11)) - .foregroundColor(.secondary) - .padding(.bottom, 4) - ScrollView { let columns = [ GridItem(.adaptive(minimum: 240, maximum: .infinity), spacing: 12) @@ -132,8 +140,6 @@ struct DictionaryView: View { ForEach(dictionaryManager.items) { item in DictionaryItemView(item: item) { dictionaryManager.removeWord(item.word) - } onToggle: { - dictionaryManager.toggleWordState(id: item.id) } } } @@ -170,7 +176,6 @@ struct DictionaryView: View { struct DictionaryItemView: View { let item: DictionaryItem let onDelete: () -> Void - let onToggle: () -> Void @State private var isHovered = false var body: some View { @@ -178,29 +183,18 @@ struct DictionaryItemView: View { Text(item.word) .font(.system(size: 13)) .lineLimit(1) - .foregroundColor(item.isEnabled ? .primary : .secondary) + .foregroundColor(.primary) Spacer(minLength: 8) - HStack(spacing: 4) { - Button(action: onToggle) { - Image(systemName: item.isEnabled ? "checkmark.circle.fill" : "circle") - .symbolRenderingMode(.hierarchical) - .foregroundStyle(item.isEnabled ? .green : .secondary) - .contentTransition(.symbolEffect(.replace)) - } - .buttonStyle(.borderless) - .help(item.isEnabled ? "Disable word" : "Enable word") - - Button(action: onDelete) { - Image(systemName: "xmark.circle.fill") - .symbolRenderingMode(.hierarchical) - .foregroundStyle(isHovered ? .red : .secondary) - .contentTransition(.symbolEffect(.replace)) - } - .buttonStyle(.borderless) - .help("Remove word") + Button(action: onDelete) { + Image(systemName: "xmark.circle.fill") + .symbolRenderingMode(.hierarchical) + .foregroundStyle(isHovered ? .red : .secondary) + .contentTransition(.symbolEffect(.replace)) } + .buttonStyle(.borderless) + .help("Remove word") .onHover { hover in withAnimation(.easeInOut(duration: 0.2)) { isHovered = hover @@ -215,9 +209,8 @@ struct DictionaryItemView: View { } .overlay { RoundedRectangle(cornerRadius: 6) - .stroke(Color.secondary.opacity(item.isEnabled ? 0.2 : 0.1), lineWidth: 1) + .stroke(Color.secondary.opacity(0.2), lineWidth: 1) } - .opacity(item.isEnabled ? 1 : 0.7) - .shadow(color: Color.black.opacity(item.isEnabled ? 0.05 : 0), radius: 2, y: 1) + .shadow(color: Color.black.opacity(0.05), radius: 2, y: 1) } }