SPB Git

Repository Public

TagsScreen.swift 1.7 KB 48 lines swift

1// SP Notes iOS2// File: Features/Tags/TagsScreen.swift3// Description: The list of tags with the number of notes carrying each; a tag opens the notes that have it.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7import SPNotesCore8import SwiftUI910struct TagsScreen: View {11    @Environment(AppModel.self) private var app12    @State private var tags: [TagInfo] = []13    @State private var loaded = false14    @State private var query = ""1516    private var visible: [TagInfo] {17        let needle = query.trimmingCharacters(in: .whitespaces).lowercased()18        return needle.isEmpty ? tags : tags.filter { $0.name.contains(needle) }19    }2021    var body: some View {22        List {23            ForEach(visible) { tag in24                NavigationLink(value: Destination.list(.tag(tag.name))) {25                    FolderRow(title: tag.name, symbol: "number", count: tag.count)26                }27                .accessibilityIdentifier("tag-row")28            }29        }30        .listStyle(.insetGrouped)31        .scrollContentBackground(.hidden)32        .background(Color.spBackground)33        .searchable(text: $query, prompt: "Chercher un tag")34        .overlay {35            if loaded, tags.isEmpty {36                EmptyStateView(symbol: "number", title: "Aucun tag", message: "Ajoute des tags à une note depuis son menu : ils apparaîtront ici avec leurs notes.")37            } else if loaded, visible.isEmpty {38                ContentUnavailableView.search(text: query)39            }40        }41        .navigationTitle("Tags")42        .task(id: app.feed.tags &+ app.feed.structure) {43            tags = ((try? await app.store.tags()) ?? []).sorted { $0.name.localizedStandardCompare($1.name) == .orderedAscending }44            loaded = true45        }46    }47}48
Files main
Menu

Theme