consolidate tags, hide date

This commit is contained in:
Christoph Hagen
2025-01-05 12:19:32 +01:00
parent 93e642c3c9
commit 5ac5a7b000
26 changed files with 284 additions and 129 deletions

View File

@@ -0,0 +1,42 @@
import SwiftUI
struct TagDisplayView: View {
@Environment(\.language)
private var language
@EnvironmentObject
private var content: Content
@Binding
var tags: [Tag]
@State
private var showTagPicker = false
var body: some View {
FlowHStack {
ForEach(tags, id: \.id) { tag in
TagView(text: tag.localized(in: language).name)
.foregroundStyle(.white)
}
Button(action: { showTagPicker = true }) {
Image(systemSymbol: .squareAndPencilCircleFill)
.resizable()
.aspectRatio(1, contentMode: .fit)
.frame(height: 22)
.foregroundColor(Color.gray)
.background(Circle()
.fill(Color.white)
.padding(1))
}
.buttonStyle(.plain)
}
.sheet(isPresented: $showTagPicker) {
TagSelectionView(
presented: $showTagPicker,
selected: $tags,
tags: $content.tags)
}
}
}

View File

@@ -72,6 +72,7 @@ struct AddPageView: View {
externalLink: nil,
isDraft: true,
createdDate: .now,
hideDate: false,
startDate: .now,
endDate: nil,
german: .init(content: content,

View File

@@ -24,9 +24,6 @@ struct PageContentView: View {
@EnvironmentObject
private var content: Content
@State
private var showTagPicker = false
init(page: Page) {
self.page = page
}
@@ -44,36 +41,13 @@ struct PageContentView: View {
}.padding()
} else {
VStack(alignment: .leading) {
FlowHStack {
ForEach(page.tags, id: \.id) { tag in
TagView(text: tag.localized(in: language).name)
.foregroundStyle(.white)
}
Button(action: { showTagPicker = true }) {
Image(systemSymbol: .squareAndPencilCircleFill)
.resizable()
.aspectRatio(1, contentMode: .fit)
.frame(height: 22)
.foregroundColor(Color.gray)
.background(Circle()
.fill(Color.white)
.padding(1))
}
.buttonStyle(.plain)
}
TagDisplayView(tags: $page.tags)
LocalizedPageContentView(pageId: page.id, page: page.localized(in: language), language: language)
.id(page.id + language.rawValue)
}.padding()
.sheet(isPresented: $showTagPicker) {
TagSelectionView(
presented: $showTagPicker,
selected: $page.tags,
tags: $content.tags)
}
.padding()
}
}
}
extension PageContentView: MainContentView {

View File

@@ -67,6 +67,18 @@ struct PageDetailView: View {
value: $page.isDraft,
footer: "Indicate a page as a draft to hide it from the website")
.disabled(page.isExternalUrl)
.onChange(of: page.externalLink) { _, newValue in
// Ensure that external pages are not drafts
if newValue != nil && page.isDraft {
page.isDraft = false
}
}
BoolPropertyView(
title: "Hide date",
value: $page.hideDate,
footer: "Do not show the date string on the page")
.disabled(page.isExternalUrl)
DatePropertyView(
title: "Start date",

View File

@@ -68,14 +68,21 @@ private struct LocalizedContentEditor: View {
}
}
private struct LinkedPageTagView: View {
@ObservedObject
var page: Page
var body: some View {
TagDisplayView(tags: $page.tags)
}
}
struct LocalizedPostContentView: View {
@ObservedObject
var post: Post
@State
private var showTagPicker = false
@Environment(\.language)
private var language
@@ -95,32 +102,14 @@ struct LocalizedPostContentView: View {
}
PostImagesView(post: post.localized(in: language))
LocalizedTitle(post: post.localized(in: language))
FlowHStack {
ForEach(post.tags, id: \.id) { tag in
TagView(text: tag.localized(in: language).name)
.foregroundStyle(.white)
}
Button(action: { showTagPicker = true }) {
Image(systemSymbol: .squareAndPencilCircleFill)
.resizable()
.aspectRatio(1, contentMode: .fit)
.frame(height: 22)
.foregroundColor(Color.gray)
.background(Circle()
.fill(Color.white)
.padding(1))
}
.buttonStyle(.plain)
if let page = post.linkedPage {
LinkedPageTagView(page: page)
} else {
TagDisplayView(tags: $post.tags)
}
LocalizedContentEditor(post: post.localized(in: language))
}
.padding()
.sheet(isPresented: $showTagPicker) {
TagSelectionView(
presented: $showTagPicker,
selected: $post.tags,
tags: $content.tags)
}
}
private func copyImagesFromOtherLanguage() {

View File

@@ -76,6 +76,16 @@ struct PostDetailView: View {
title: "Linked page",
selectedPage: $post.linkedPage,
footer: "The page to open when clicking on the post")
.onChange(of: post.linkedPage) { oldValue, newValue in
if newValue != nil {
post.tags = []
} else {
// Link removed, so copy tags from previous link
if let oldValue {
post.tags = oldValue.tags
}
}
}
LocalizedPostDetailView(post: post.localized(in: language))
}

View File

@@ -223,6 +223,7 @@ struct PageIssueView: View {
externalLink: nil,
isDraft: true,
createdDate: .now,
hideDate: false,
startDate: .now,
endDate: nil,
german: .init(content: content,

View File

@@ -14,24 +14,16 @@ private struct PageSelectionView: View {
var body: some View {
HStack {
let isSelected = page.tags.contains(tag)
let isSelected = page.contains(tag)
Image(systemSymbol: isSelected ? .checkmarkCircleFill : .circle)
.foregroundStyle(Color.blue)
Text(page.localized(in: language).title)
}
.contentShape(Rectangle())
.onTapGesture {
toggleTagAssignment()
page.toggle(tag)
}
}
private func toggleTagAssignment() {
guard let index = page.tags.firstIndex(of: tag) else {
page.tags.append(tag)
return
}
page.tags.remove(at: index)
}
}
struct PageTagAssignmentView: View {

View File

@@ -14,24 +14,16 @@ private struct PostSelectionView: View {
var body: some View {
HStack {
let isSelected = post.tags.contains(tag)
let isSelected = post.contains(tag)
Image(systemSymbol: isSelected ? .checkmarkCircleFill : .circle)
.foregroundStyle(Color.blue)
Text(post.localized(in: language).title)
}
.contentShape(Rectangle())
.onTapGesture {
toggleTagAssignment()
post.toggle(tag)
}
}
private func toggleTagAssignment() {
guard let index = post.tags.firstIndex(of: tag) else {
post.tags.append(tag)
return
}
post.tags.remove(at: index)
}
}
struct PostTagAssignmentView: View {

View File

@@ -22,7 +22,7 @@ struct TagContentView: View {
}
var selectedPosts: [Post] {
content.posts.filter { $0.tags.contains(tag) }
content.posts.filter { $0.contains(tag) }
}
var body: some View {