Simplify images, tag overview

This commit is contained in:
Christoph Hagen
2025-01-04 08:44:26 +01:00
parent 4d4275e072
commit 22e7d9a05a
49 changed files with 603 additions and 509 deletions

View File

@ -1,34 +1,5 @@
import SwiftUI
enum FileFilterType: String, Hashable, CaseIterable, Identifiable {
case images
case text
case videos
case other
var text: String {
switch self {
case .images: return "Image"
case .text: return "Text"
case .videos: return "Video"
case .other: return "Other"
}
}
var id: String {
rawValue
}
func matches(_ type: FileType) -> Bool {
switch self {
case .images: return type.isImage
case .text: return type.isTextFile
case .videos: return type.isVideo
case .other: return type.isOtherFile
}
}
}
struct FileListView: View {
@EnvironmentObject
@ -38,21 +9,23 @@ struct FileListView: View {
var selectedFile: FileResource?
@State
private var selectedFileType: FileFilterType
private var selectedFileType: FileTypeCategory? = nil
@State
private var searchString = ""
let allowedType: FileFilterType?
let allowedType: FileTypeCategory?
init(selectedFile: Binding<FileResource?>, allowedType: FileFilterType? = nil) {
init(selectedFile: Binding<FileResource?>, allowedType: FileTypeCategory? = nil) {
self._selectedFile = selectedFile
self.allowedType = allowedType
self.selectedFileType = allowedType ?? .images
}
var filesBySelectedType: [FileResource] {
content.files.filter { selectedFileType.matches($0.type) }
guard let selectedFileType else {
return content.files
}
return content.files.filter { selectedFileType == $0.type.category }
}
var filteredFiles: [FileResource] {
@ -64,14 +37,17 @@ struct FileListView: View {
var body: some View {
VStack(alignment: .center) {
Picker("", selection: $selectedFileType) {
ForEach(FileFilterType.allCases) { type in
Text(type.text).tag(type)
if allowedType == nil {
Picker("", selection: $selectedFileType) {
let all: FileTypeCategory? = nil
Text("All").tag(all)
ForEach(FileTypeCategory.allCases) { type in
Text(type.text).tag(type)
}
}
.pickerStyle(.menu)
.padding(.trailing, 7)
}
.pickerStyle(.segmented)
.padding(.trailing, 7)
.disabled(allowedType != nil)
TextField("", text: $searchString, prompt: Text("Search"))
.textFieldStyle(.roundedBorder)
.padding(.horizontal, 8)
@ -93,7 +69,7 @@ struct FileListView: View {
return
}
if newValue.matches(selectedFile.type) {
if newValue == selectedFile.type.category {
return
}
DispatchQueue.main.async {
@ -102,10 +78,11 @@ struct FileListView: View {
}
}
.onAppear {
if let allowedType {
selectedFileType = allowedType
}
if selectedFile == nil {
DispatchQueue.main.async {
selectedFile = content.files.first
}
selectedFile = content.files.first
}
}
}

View File

@ -8,9 +8,9 @@ struct FileSelectionView: View {
@Binding
private var selectedFile: FileResource?
let allowedType: FileFilterType?
let allowedType: FileTypeCategory?
init(selectedFile: Binding<FileResource?>, allowedType: FileFilterType? = nil) {
init(selectedFile: Binding<FileResource?>, allowedType: FileTypeCategory? = nil) {
self._selectedFile = selectedFile
self.newSelection = selectedFile.wrappedValue
self.allowedType = allowedType

View File

@ -11,12 +11,12 @@ struct MultiFileSelectionView: View {
@Binding
private var selectedFiles: [FileResource]
let allowedType: FileFilterType?
let allowedType: FileTypeCategory?
let insertSorted: Bool
@State
private var selectedFileType: FileFilterType
private var selectedFileType: FileTypeCategory?
@State
private var searchString = ""
@ -24,16 +24,19 @@ struct MultiFileSelectionView: View {
@State
private var newSelection: [FileResource]
init(selectedFiles: Binding<[FileResource]>, allowedType: FileFilterType? = nil, insertSorted: Bool = false) {
init(selectedFiles: Binding<[FileResource]>, allowedType: FileTypeCategory? = nil, insertSorted: Bool = false) {
self._selectedFiles = selectedFiles
self.newSelection = selectedFiles.wrappedValue
self.allowedType = allowedType
self.selectedFileType = allowedType ?? .images
self.selectedFileType = allowedType ?? .image
self.insertSorted = insertSorted
}
private var filesBySelectedType: [FileResource] {
content.files.filter { selectedFileType.matches($0.type) }
guard let selectedFileType else {
return content.files
}
return content.files.filter { selectedFileType == $0.type.category }
}
private var filteredFiles: [FileResource] {
@ -75,7 +78,9 @@ struct MultiFileSelectionView: View {
}
VStack {
Picker("", selection: $selectedFileType) {
ForEach(FileFilterType.allCases) { type in
let all: FileTypeCategory? = nil
Text("All").tag(all)
ForEach(FileTypeCategory.allCases) { type in
Text(type.text).tag(type)
}
}

View File

@ -9,9 +9,9 @@ struct FilePropertyView: View {
@Binding
var selectedFile: FileResource?
let allowedType: FileFilterType?
let allowedType: FileTypeCategory?
init(title: LocalizedStringKey, footer: LocalizedStringKey, selectedFile: Binding<FileResource?>, allowedType: FileFilterType? = nil) {
init(title: LocalizedStringKey, footer: LocalizedStringKey, selectedFile: Binding<FileResource?>, allowedType: FileTypeCategory? = nil) {
self.title = title
self.footer = footer
self._selectedFile = selectedFile

View File

@ -30,7 +30,7 @@ struct OptionalImagePropertyView: View {
}
}
.sheet(isPresented: $showSelectionSheet) {
FileSelectionView(selectedFile: $selectedImage, allowedType: .images)
FileSelectionView(selectedFile: $selectedImage, allowedType: .image)
}
}
}

View File

@ -51,7 +51,7 @@ struct PostImagesView: View {
}
}
.sheet(isPresented: $showImagePicker) {
MultiFileSelectionView(selectedFiles: $post.images, allowedType: .images)
MultiFileSelectionView(selectedFiles: $post.images, allowedType: .image)
}
}

View File

@ -39,11 +39,12 @@ struct GenerationContentView: View {
if content.isGeneratingWebsite {
content.endCurrentGeneration()
} else {
generateFullWebsite()
content.generateWebsiteInAllLanguages()
}
} label: {
Text(content.isGeneratingWebsite ? "Cancel" : "Generate")
}
.disabled(content.isGeneratingWebsite != content.shouldGenerateWebsite)
if content.isGeneratingWebsite {
ProgressView()
.progressViewStyle(.circular)
@ -108,39 +109,6 @@ struct GenerationContentView: View {
}
}.padding()
}
private func generateFullWebsite() {
DispatchQueue.main.async {
content.generateWebsiteInAllLanguages()
}
#warning("Update feed generation")
/*
guard let url = content.storage.outputPath else {
print("Invalid output path")
return
}
guard FileManager.default.fileExists(atPath: url.path) else {
print("Missing output folder")
return
}
isGeneratingWebsite = true
DispatchQueue.global(qos: .userInitiated).async {
let generator = LocalizedWebsiteGenerator(
content: content,
language: language)
_ = generator.generateWebsite { text in
DispatchQueue.main.async {
self.generatorText = text
}
}
DispatchQueue.main.async {
isGeneratingWebsite = false
self.generatorText = "Generation complete"
}
}
*/
}
}
#Preview {

View File

@ -2,8 +2,6 @@ import SFSafeSymbols
enum SettingsSection: String {
//case generation = "Generation"
case folders = "Folders"
case navigationBar = "Navigation Bar"
@ -21,7 +19,7 @@ extension SettingsSection {
var icon: SFSymbol {
switch self {
case .folders: return .folder
case .navigationBar: return .menubarRectangle
case .navigationBar: return .menubarArrowUpRectangle
case .postFeed: return .rectangleGrid1x2
case .pages: return .docRichtext
case .tagOverview: return .tag

View File

@ -17,10 +17,12 @@ struct TagOverviewDetailView: View {
if let page = content.tagOverview?.localized(in: language) {
TagOverviewDetails(page: page)
.id(language)
} else {
Button("Create", action: createTagOverviewPage)
}
}
.padding()
}
}
@ -70,6 +72,5 @@ private struct TagOverviewDetails: View {
text: $page.linkPreviewDescription,
footer: "The description to show in previews of the page")
}
.padding()
}
}