From 4131b483e6361a3fe15b139c9c0773be64f491f4 Mon Sep 17 00:00:00 2001 From: Christoph Hagen Date: Mon, 13 Jan 2025 22:34:51 +0100 Subject: [PATCH] Show linking posts on page content --- CHDataManagement.xcodeproj/project.pbxproj | 8 +++ CHDataManagement/Main/MainView.swift | 1 - .../Preview Content/Content+Mock.swift | 2 - .../Views/Generic/ListPopup.swift | 25 ++++++++ .../Views/Generic/TextWithPopup.swift | 36 ++++++++++++ .../Pages/LocalizedPageContentView.swift | 14 ++++- .../Views/Pages/PageContentResultsView.swift | 58 ------------------- 7 files changed, 80 insertions(+), 64 deletions(-) create mode 100644 CHDataManagement/Views/Generic/ListPopup.swift create mode 100644 CHDataManagement/Views/Generic/TextWithPopup.swift diff --git a/CHDataManagement.xcodeproj/project.pbxproj b/CHDataManagement.xcodeproj/project.pbxproj index 357cfa7..158cff3 100644 --- a/CHDataManagement.xcodeproj/project.pbxproj +++ b/CHDataManagement.xcodeproj/project.pbxproj @@ -183,6 +183,8 @@ E2FD1D232D2EB27000B48627 /* LoadingResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2FD1D222D2EB26C00B48627 /* LoadingResult.swift */; }; E2FD1D252D2EBA8000B48627 /* TagOverview.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2FD1D242D2EBA7C00B48627 /* TagOverview.swift */; }; E2FD1D282D2F2DAD00B48627 /* ErrorPrinter.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2FD1D272D2F2D9100B48627 /* ErrorPrinter.swift */; }; + E2FD1D2A2D35B74C00B48627 /* TextWithPopup.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2FD1D292D35B74C00B48627 /* TextWithPopup.swift */; }; + E2FD1D2C2D35B76D00B48627 /* ListPopup.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2FD1D2B2D35B76D00B48627 /* ListPopup.swift */; }; E2FE0EE62D15A0B5002963B7 /* GenerationResults.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2FE0EE52D15A0B1002963B7 /* GenerationResults.swift */; }; E2FE0EE82D16D4A3002963B7 /* ConvertThrowing.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2FE0EE72D16D4A3002963B7 /* ConvertThrowing.swift */; }; E2FE0EEC2D1C1253002963B7 /* MultiFileSelectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2FE0EEB2D1C124E002963B7 /* MultiFileSelectionView.swift */; }; @@ -412,6 +414,8 @@ E2FD1D222D2EB26C00B48627 /* LoadingResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingResult.swift; sourceTree = ""; }; E2FD1D242D2EBA7C00B48627 /* TagOverview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TagOverview.swift; sourceTree = ""; }; E2FD1D272D2F2D9100B48627 /* ErrorPrinter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErrorPrinter.swift; sourceTree = ""; }; + E2FD1D292D35B74C00B48627 /* TextWithPopup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextWithPopup.swift; sourceTree = ""; }; + E2FD1D2B2D35B76D00B48627 /* ListPopup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListPopup.swift; sourceTree = ""; }; E2FE0EE52D15A0B1002963B7 /* GenerationResults.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GenerationResults.swift; sourceTree = ""; }; E2FE0EE72D16D4A3002963B7 /* ConvertThrowing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConvertThrowing.swift; sourceTree = ""; }; E2FE0EEB2D1C124E002963B7 /* MultiFileSelectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MultiFileSelectionView.swift; sourceTree = ""; }; @@ -651,6 +655,8 @@ E2A21C372CB9A4F10060935B /* Generic */ = { isa = PBXGroup; children = ( + E2FD1D2B2D35B76D00B48627 /* ListPopup.swift */, + E2FD1D292D35B74C00B48627 /* TextWithPopup.swift */, E2FE0F6F2D2D5231002963B7 /* TextIndicator.swift */, E2FE0F232D2A8C1A002963B7 /* TagDisplayView.swift */, E229902F2D0F75CF009F8D77 /* BoolPropertyView.swift */, @@ -1185,6 +1191,7 @@ E2FD1D232D2EB27000B48627 /* LoadingResult.swift in Sources */, E29D31B82D0DAC250051B7F4 /* ButtonCommand.swift in Sources */, E29D31962D0C186E0051B7F4 /* PathSettings.swift in Sources */, + E2FD1D2C2D35B76D00B48627 /* ListPopup.swift in Sources */, E2B85F412C4294790047CD0C /* PageHead.swift in Sources */, E2FE0F2A2D2AFBE6002963B7 /* ImageCompareIcons.swift in Sources */, E29D316B2D07488B0051B7F4 /* PostListPageGenerator.swift in Sources */, @@ -1284,6 +1291,7 @@ E25DA5912D023A8400AEF16D /* IntegerField.swift in Sources */, E2FD1D192D2DC4F500B48627 /* LoadingContext.swift in Sources */, E29D318B2D0B07EE0051B7F4 /* ContentBox.swift in Sources */, + E2FD1D2A2D35B74C00B48627 /* TextWithPopup.swift in Sources */, E2FE0F4D2D2BCD30002963B7 /* PageLinkCommand.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/CHDataManagement/Main/MainView.swift b/CHDataManagement/Main/MainView.swift index fead3df..f8dcfb9 100644 --- a/CHDataManagement/Main/MainView.swift +++ b/CHDataManagement/Main/MainView.swift @@ -8,7 +8,6 @@ import SFSafeSymbols **UI** - Image search: Add view to see all images and filter - - Pages: Show linking posts - Page Content: Show all results of `PageGenerationResults` - Files: Show usages of file - Buttons to insert special commands (images, page links, ...) diff --git a/CHDataManagement/Preview Content/Content+Mock.swift b/CHDataManagement/Preview Content/Content+Mock.swift index 15a81f5..ab78586 100644 --- a/CHDataManagement/Preview Content/Content+Mock.swift +++ b/CHDataManagement/Preview Content/Content+Mock.swift @@ -12,8 +12,6 @@ extension FileManager { extension Content { - private static let dbPath = FileManager.default.documentDirectory.appendingPathComponent("db").path() - static let mock: Content = Content( settings: .default, posts: [.empty, .mock, .fullMock], diff --git a/CHDataManagement/Views/Generic/ListPopup.swift b/CHDataManagement/Views/Generic/ListPopup.swift new file mode 100644 index 0000000..7fd3dd0 --- /dev/null +++ b/CHDataManagement/Views/Generic/ListPopup.swift @@ -0,0 +1,25 @@ +import SwiftUI + +struct ListPopup: View { + + @Environment(\.dismiss) + var dismiss + + let items: [String] + + var body: some View { + VStack { + List { + ForEach(items, id: \.self) { page in + Text(page) + } + } + .frame(minHeight: min(CGFloat(items.count) * 31, 500)) + Button("Dismiss") { dismiss() } + } + .padding(.vertical) + .onTapGesture { + dismiss() + } + } +} diff --git a/CHDataManagement/Views/Generic/TextWithPopup.swift b/CHDataManagement/Views/Generic/TextWithPopup.swift new file mode 100644 index 0000000..8f64704 --- /dev/null +++ b/CHDataManagement/Views/Generic/TextWithPopup.swift @@ -0,0 +1,36 @@ +import SwiftUI +import SFSafeSymbols + +struct TextWithPopup: View { + + let symbol: SFSymbol + + let text: LocalizedStringKey + + let items: [String] + + @State + private var isHovering = false + + var body: some View { + HStack { + Image(systemSymbol: symbol) + .resizable() + .aspectRatio(contentMode: .fit) + .frame(width: 16, height: 16) + Text(text) + } + .contentShape(Rectangle()) + .onTapGesture { + if items.count > 0 { + isHovering.toggle() + } + } + .sheet(isPresented: $isHovering) { + ListPopup(items: items) + .onTapGesture { + isHovering.toggle() + } + } + } +} diff --git a/CHDataManagement/Views/Pages/LocalizedPageContentView.swift b/CHDataManagement/Views/Pages/LocalizedPageContentView.swift index afb76b3..49ad6db 100644 --- a/CHDataManagement/Views/Pages/LocalizedPageContentView.swift +++ b/CHDataManagement/Views/Pages/LocalizedPageContentView.swift @@ -42,9 +42,17 @@ struct LocalizedPageContentView: View { } Spacer() } - if let generationResults { - PageContentResultsView(results: generationResults) - } + + HStack { + if let generationResults { + PageContentResultsView(results: generationResults) + } + let linkingPosts = content.posts.filter { $0.linkedPage == page } + TextWithPopup( + symbol: .ipadAndArrowForward, + text: "\(linkingPosts.count) linking posts", + items: linkingPosts.map { $0.title(in: language) }) + }.foregroundStyle(.secondary) HighlightedTextEditor( text: $pageContent, highlightRules: .markdown) diff --git a/CHDataManagement/Views/Pages/PageContentResultsView.swift b/CHDataManagement/Views/Pages/PageContentResultsView.swift index 8973592..ffaf7c4 100644 --- a/CHDataManagement/Views/Pages/PageContentResultsView.swift +++ b/CHDataManagement/Views/Pages/PageContentResultsView.swift @@ -1,64 +1,6 @@ import SwiftUI import SFSafeSymbols -private struct ListPopup: View { - - @Environment(\.dismiss) - var dismiss - - let items: [String] - - var body: some View { - VStack { - List { - ForEach(items, id: \.self) { page in - Text(page) - } - } - .frame(minHeight: min(CGFloat(items.count) * 31, 500)) - Button("Dismiss") { dismiss() } - } - .padding(.vertical) - .onTapGesture { - dismiss() - } - } -} - -private struct TextWithPopup: View { - - let symbol: SFSymbol - - let text: LocalizedStringKey - - let items: [String] - - @State - private var isHovering = false - - var body: some View { - HStack { - Image(systemSymbol: symbol) - .resizable() - .aspectRatio(contentMode: .fit) - .frame(width: 16, height: 16) - Text(text) - } - .contentShape(Rectangle()) - .onTapGesture { - if items.count > 0 { - isHovering.toggle() - } - } - .sheet(isPresented: $isHovering) { - ListPopup(items: items) - .onTapGesture { - isHovering.toggle() - } - } - } -} - struct PageContentResultsView: View { @Environment(\.language)