feat: Show annotations button only when article contains annotations

Add conditional visibility for the annotations button in the toolbar based on whether the loaded article contains any rd-annotation tags.

Changes:
- Add hasAnnotations property to BookmarkDetailViewModel
- Check for <rd-annotation tags when processing article content
- Conditionally show/hide annotations button in BookmarkDetailView2
This commit is contained in:
Ilyas Hallak 2025-10-26 21:19:27 +01:00
parent b77e4e3e9f
commit c629894611
2 changed files with 11 additions and 5 deletions

View File

@ -270,10 +270,12 @@ struct BookmarkDetailView2: View {
Image(systemName: "tag") Image(systemName: "tag")
} }
Button(action: { if viewModel.hasAnnotations {
showingAnnotationsSheet = true Button(action: {
}) { showingAnnotationsSheet = true
Image(systemName: "pencil.line") }) {
Image(systemName: "pencil.line")
}
} }
Button(action: { Button(action: {

View File

@ -20,6 +20,7 @@ class BookmarkDetailViewModel {
var settings: Settings? var settings: Settings?
var readProgress: Int = 0 var readProgress: Int = 0
var selectedAnnotationId: String? var selectedAnnotationId: String?
var hasAnnotations: Bool = false
private var factory: UseCaseFactory? private var factory: UseCaseFactory?
private var cancellables = Set<AnyCancellable>() private var cancellables = Set<AnyCancellable>()
@ -85,8 +86,11 @@ class BookmarkDetailViewModel {
let paragraphs = articleContent let paragraphs = articleContent
.components(separatedBy: .newlines) .components(separatedBy: .newlines)
.filter { !$0.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty } .filter { !$0.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty }
articleParagraphs = paragraphs articleParagraphs = paragraphs
// Check if article contains annotations
hasAnnotations = articleContent.contains("<rd-annotation")
} }
@MainActor @MainActor