Files
damus/nostrdb/NdbDatabase+UI.swift
Daniel D’Aquino 795fce1b65 Add storage usage stats settings view
This commit implements a new Storage settings view that displays storage
usage statistics for NostrDB, snapshot database, and Kingfisher image cache.

Key features:
- Interactive pie chart visualization (iOS 17+) with tap-to-select functionality
- Pull-to-refresh gesture to recalculate storage
- Categorized list showing each storage type with size and percentage
- Total storage sum displayed at bottom
- Conditional compilation for iOS 16/17+ compatibility
- All calculations run on background thread to avoid blocking main thread
- NostrDB storage breakdown

Changelog-Added: Storage usage statistics view in Settings
Changelog-Changed: Moved clear cache button to storage settings
Closes: https://github.com/damus-io/damus/issues/3649
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2026-02-25 15:45:37 -08:00

92 lines
3.8 KiB
Swift

//
// NdbDatabase+UI.swift
// (UI/Features target)
//
// This extension adds UI-specific properties to NdbDatabase for presentation purposes.
// It should only be included in targets involving SwiftUI/UI presentation.
//
import SwiftUI
extension NdbDatabase {
/// Human-readable database name
var displayName: String {
switch self {
case .note:
return NSLocalizedString("Notes (NDB_DB_NOTE)", comment: "Database name for notes")
case .meta:
return NSLocalizedString("Metadata (NDB_DB_META)", comment: "Database name for metadata")
case .profile:
return NSLocalizedString("Profiles (NDB_DB_PROFILE)", comment: "Database name for profiles")
case .noteId:
return NSLocalizedString("Note ID Index", comment: "Database name for note ID index")
case .profileKey:
return NSLocalizedString("Profile Key Index", comment: "Database name for profile key index")
case .ndbMeta:
return NSLocalizedString("NostrDB Metadata", comment: "Database name for NostrDB metadata")
case .profileSearch:
return NSLocalizedString("Profile Search Index", comment: "Database name for profile search")
case .profileLastFetch:
return NSLocalizedString("Profile Last Fetch", comment: "Database name for profile last fetch")
case .noteKind:
return NSLocalizedString("Note Kind Index", comment: "Database name for note kind index")
case .noteText:
return NSLocalizedString("Note Text Index", comment: "Database name for note text index")
case .noteBlocks:
return NSLocalizedString("Note Blocks", comment: "Database name for note blocks")
case .noteTags:
return NSLocalizedString("Note Tags Index", comment: "Database name for note tags index")
case .notePubkey:
return NSLocalizedString("Note Pubkey Index", comment: "Database name for note pubkey index")
case .notePubkeyKind:
return NSLocalizedString("Note Pubkey+Kind Index", comment: "Database name for note pubkey+kind index")
case .noteRelayKind:
return NSLocalizedString("Note Relay+Kind Index", comment: "Database name for note relay+kind index")
case .noteRelays:
return NSLocalizedString("Note Relays", comment: "Database name for note relays")
case .other:
return NSLocalizedString("Other Data", comment: "Database name for other/unaccounted data")
}
}
/// SF Symbol icon name for this database type
var icon: String {
switch self {
case .note:
return "text.bubble.fill"
case .profile:
return "person.circle.fill"
case .meta, .ndbMeta:
return "info.circle.fill"
case .noteBlocks:
return "square.stack.3d.up.fill"
case .noteId, .profileKey, .profileSearch, .noteKind, .noteText, .noteTags, .notePubkey, .notePubkeyKind, .noteRelayKind:
return "list.bullet.indent"
case .noteRelays:
return "antenna.radiowaves.left.and.right"
case .profileLastFetch, .other:
return "internaldrive.fill"
}
}
/// Color for chart and UI display
var color: Color {
switch self {
case .note:
return .green
case .profile:
return .blue
case .noteBlocks:
return .purple
case .meta, .ndbMeta:
return .orange
case .noteId, .profileKey, .profileSearch, .noteKind, .noteText, .noteTags, .notePubkey, .notePubkeyKind, .noteRelayKind:
return .gray
case .noteRelays:
return .cyan
case .profileLastFetch, .other:
return .secondary
}
}
}