Prepare for selection of items

Update MainView.swift
This commit is contained in:
Christoph Hagen 2025-01-18 09:56:42 +01:00
parent e0787f991e
commit 1d4b3c266c
3 changed files with 66 additions and 52 deletions

View File

@ -187,6 +187,7 @@
E2FD1D2E2D37180900B48627 /* GeneralSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2FD1D2D2D37180600B48627 /* GeneralSettings.swift */; };
E2FD1D302D37196C00B48627 /* GeneralSettingsDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2FD1D2F2D37196500B48627 /* GeneralSettingsDetailView.swift */; };
E2FD1D322D3AEB6300B48627 /* PostVideo.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2FD1D312D3AEB6000B48627 /* PostVideo.swift */; };
E2FD1D342D3BA2E700B48627 /* SelectedContent.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2FD1D332D3BA2DE00B48627 /* SelectedContent.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 */; };
@ -420,6 +421,7 @@
E2FD1D2D2D37180600B48627 /* GeneralSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeneralSettings.swift; sourceTree = "<group>"; };
E2FD1D2F2D37196500B48627 /* GeneralSettingsDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeneralSettingsDetailView.swift; sourceTree = "<group>"; };
E2FD1D312D3AEB6000B48627 /* PostVideo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostVideo.swift; sourceTree = "<group>"; };
E2FD1D332D3BA2DE00B48627 /* SelectedContent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectedContent.swift; sourceTree = "<group>"; };
E2FE0EE52D15A0B1002963B7 /* GenerationResults.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GenerationResults.swift; sourceTree = "<group>"; };
E2FE0EE72D16D4A3002963B7 /* ConvertThrowing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConvertThrowing.swift; sourceTree = "<group>"; };
E2FE0EEB2D1C124E002963B7 /* MultiFileSelectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MultiFileSelectionView.swift; sourceTree = "<group>"; };
@ -569,6 +571,7 @@
E29D31372D043EB80051B7F4 /* Main */ = {
isa = PBXGroup;
children = (
E2FD1D332D3BA2DE00B48627 /* SelectedContent.swift */,
E229904B2D10BE59009F8D77 /* InitialSetupView.swift */,
E29D31422D0488950051B7F4 /* MainContentView.swift */,
E2DD04732C276F31003BFF1F /* MainView.swift */,
@ -1295,6 +1298,7 @@
E2FE0F262D2AF9B0002963B7 /* ImageCompareCommand.swift in Sources */,
E2FE0F1E2D281AE1002963B7 /* TagOverviewGenerator.swift in Sources */,
E29D31572D06D38B0051B7F4 /* AddTagView.swift in Sources */,
E2FD1D342D3BA2E700B48627 /* SelectedContent.swift in Sources */,
E29D31792D083DE50051B7F4 /* PageContentResultsView.swift in Sources */,
E25DA5912D023A8400AEF16D /* IntegerField.swift in Sources */,
E2FD1D192D2DC4F500B48627 /* LoadingContext.swift in Sources */,

View File

@ -45,23 +45,8 @@ struct MainView: App {
@State
private var language: ContentLanguage = .english
@State
private var selectedTab: MainViewTab = .posts
@State
private var selectedPost: Post?
@State
private var selectedPage: Page?
@State
private var selectedTag: Tag?
@State
private var selectedFile: FileResource?
@State
private var selectedSection: SettingsSection = .folders
@ObservedObject
private var selection: SelectedContent = .init()
@State
private var showAddSheet = false
@ -77,63 +62,63 @@ struct MainView: App {
@ViewBuilder
var sidebar: some View {
switch selectedTab {
switch selection.tab {
case .posts:
PostListView(selectedPost: $selectedPost)
PostListView(selectedPost: $selection.post)
case .pages:
PageListView(selectedPage: $selectedPage)
PageListView(selectedPage: $selection.page)
case .tags:
TagListView(selectedTag: $selectedTag)
TagListView(selectedTag: $selection.tag)
case .files:
FileListView(selectedFile: $selectedFile)
FileListView(selectedFile: $selection.file)
case .generation:
SettingsListView(selectedSection: $selectedSection)
SettingsListView(selectedSection: $selection.section)
}
}
@ViewBuilder
var viewContent: some View {
switch selectedTab {
switch selection.tab {
case .posts:
SelectedContentView<PostContentView>(selected: $selectedPost)
SelectedContentView<PostContentView>(selected: $selection.post)
case .pages:
SelectedContentView<PageContentView>(selected: $selectedPage)
SelectedContentView<PageContentView>(selected: $selection.page)
case .tags:
SelectedContentView<TagContentView>(selected: $selectedTag)
SelectedContentView<TagContentView>(selected: $selection.tag)
case .files:
SelectedContentView<FileContentView>(selected: $selectedFile)
SelectedContentView<FileContentView>(selected: $selection.file)
case .generation:
GenerationContentView(selected: $selectedSection)
GenerationContentView(selected: $selection.section)
}
}
@ViewBuilder
var detail: some View {
switch selectedTab {
switch selection.tab {
case .posts:
SelectedDetailView<PostDetailView>(selected: $selectedPost)
SelectedDetailView<PostDetailView>(selected: $selection.post)
case .pages:
SelectedDetailView<PageDetailView>(selected: $selectedPage)
SelectedDetailView<PageDetailView>(selected: $selection.page)
case .tags:
SelectedDetailView<TagDetailView>(selected: $selectedTag)
SelectedDetailView<TagDetailView>(selected: $selection.tag)
case .files:
SelectedDetailView<FileDetailView>(selected: $selectedFile)
SelectedDetailView<FileDetailView>(selected: $selection.file)
case .generation:
GenerationDetailView(section: selectedSection)
GenerationDetailView(section: selection.section)
}
}
@ViewBuilder
var addItemSheet: some View {
switch selectedTab {
switch selection.tab {
case .posts:
AddPostView(selected: $selectedPost)
AddPostView(selected: $selection.post)
case .pages:
AddPageView(selected: $selectedPage)
AddPageView(selected: $selection.page)
case .tags:
AddTagView(selected: $selectedTag)
AddTagView(selected: $selection.tag)
case .files:
AddFileView(selectedFile: $selectedFile)
AddFileView(selectedFile: $selection.file)
case .generation:
Text("Not implemented")
}
@ -145,7 +130,7 @@ struct MainView: App {
sidebar
.toolbar {
ToolbarItem(placement: .navigation) {
Picker("", selection: $selectedTab) {
Picker("", selection: $selection.tab) {
Text("Posts").tag(MainViewTab.posts)
Text("Pages").tag(MainViewTab.pages)
Text("Tags").tag(MainViewTab.tags)
@ -160,7 +145,7 @@ struct MainView: App {
Button(action: { showAddSheet = true }) {
Label("Add", systemSymbol: .plus)
}
.disabled(!selectedTab.canAddItems)
.disabled(!selection.tab.canAddItems)
}
}
} content: {
@ -194,6 +179,7 @@ struct MainView: App {
.navigationTitle("")
.environment(\.language, language)
.environmentObject(content)
.environmentObject(selection)
.onAppear(perform: loadContent)
.onReceive(Timer.publish(every: 60.0, on: .main, in: .common).autoconnect()) { _ in
save()
@ -202,11 +188,13 @@ struct MainView: App {
addItemSheet
.environment(\.language, language)
.environmentObject(content)
.environmentObject(selection)
}
.sheet(isPresented: $showInitialSetupSheet) {
InitialSetupView()
.environment(\.language, language)
.environmentObject(content)
.environmentObject(selection)
}
.sheet(isPresented: $showLoadErrorSheet) {
VStack {
@ -251,24 +239,24 @@ struct MainView: App {
}
private func prepareAfterLoad() {
if selectedPost == nil {
selectedPost = content.posts.first
if selection.post == nil {
selection.post = content.posts.first
}
if selectedPage == nil {
selectedPage = content.pages.first
if selection.page == nil {
selection.page = content.pages.first
}
if selectedTag == nil {
selectedTag = content.tags.first
if selection.tag == nil {
selection.tag = content.tags.first
}
if selectedFile == nil {
selectedFile = content.files.first
if selection.file == nil {
selection.file = content.files.first
}
}
private func showInitialSheet() {
DispatchQueue.main.async {
selectedSection = .folders
selectedTab = .generation
selection.section = .folders
selection.tab = .generation
showInitialSetupSheet = true
}
}

View File

@ -0,0 +1,22 @@
import Foundation
final class SelectedContent: ObservableObject {
@Published
var tab: MainViewTab = .posts
@Published
var post: Post?
@Published
var page: Page?
@Published
var tag: Tag?
@Published
var file: FileResource?
@Published
var section: SettingsSection = .folders
}