mirror of
https://github.com/writeas/writefreely-swiftui-multiplatform.git
synced 2024-11-15 01:11:02 +00:00
Move bulk of SearchablePostListFilteredView into DeprecatedListView
This commit is contained in:
parent
7a5eb1b3eb
commit
75c4d6089e
57
Shared/PostList/DeprecatedListView.swift
Normal file
57
Shared/PostList/DeprecatedListView.swift
Normal file
@ -0,0 +1,57 @@
|
||||
import SwiftUI
|
||||
|
||||
@available(iOS 15, macOS 12.0, *)
|
||||
struct DeprecatedListView: View {
|
||||
@EnvironmentObject var model: WriteFreelyModel
|
||||
@Binding var searchString: String
|
||||
|
||||
var collections: FetchedResults<WFACollection>
|
||||
var fetchRequest: FetchRequest<WFAPost>
|
||||
var onDelete: (WFAPost) -> Void
|
||||
|
||||
var body: some View {
|
||||
List(selection: $model.selectedPost) {
|
||||
ForEach(fetchRequest.wrappedValue, id: \.self) { post in
|
||||
if !searchString.isEmpty &&
|
||||
!post.title.localizedCaseInsensitiveContains(searchString) &&
|
||||
!post.body.localizedCaseInsensitiveContains(searchString) {
|
||||
EmptyView()
|
||||
} else {
|
||||
NavigationLink(
|
||||
destination: PostEditorView(post: post),
|
||||
tag: post,
|
||||
selection: $model.selectedPost,
|
||||
label: {
|
||||
if model.showAllPosts {
|
||||
if let collection = collections.filter({ $0.alias == post.collectionAlias }).first {
|
||||
PostCellView(post: post, collectionName: collection.title)
|
||||
} else {
|
||||
// swiftlint:disable:next line_length
|
||||
let collectionName = model.account.server == "https://write.as" ? "Anonymous" : "Drafts"
|
||||
PostCellView(post: post, collectionName: collectionName)
|
||||
}
|
||||
} else {
|
||||
PostCellView(post: post)
|
||||
}
|
||||
})
|
||||
.deleteDisabled(post.status != PostStatus.local.rawValue)
|
||||
}
|
||||
}
|
||||
.onDelete(perform: { indexSet in
|
||||
for index in indexSet {
|
||||
let post = fetchRequest.wrappedValue[index]
|
||||
delete(post)
|
||||
}
|
||||
})
|
||||
}
|
||||
#if os(iOS)
|
||||
.searchable(text: $searchString, prompt: "Search across posts")
|
||||
#else
|
||||
.searchable(text: $searchString, placement: .toolbar, prompt: "Search across posts")
|
||||
#endif
|
||||
}
|
||||
|
||||
func delete(_ post: WFAPost) {
|
||||
onDelete(post)
|
||||
}
|
||||
}
|
@ -6,50 +6,26 @@ struct SearchablePostListFilteredView: View {
|
||||
@Binding var postCount: Int
|
||||
@State private var searchString = ""
|
||||
|
||||
// Only used for NavigationStack in iOS 16/macOS 13 or later
|
||||
@State private var path: [WFAPost] = []
|
||||
|
||||
var collections: FetchedResults<WFACollection>
|
||||
var fetchRequest: FetchRequest<WFAPost>
|
||||
var onDelete: (WFAPost) -> Void
|
||||
|
||||
var body: some View {
|
||||
List(selection: $model.selectedPost) {
|
||||
ForEach(fetchRequest.wrappedValue, id: \.self) { post in
|
||||
if !searchString.isEmpty &&
|
||||
!post.title.localizedCaseInsensitiveContains(searchString) &&
|
||||
!post.body.localizedCaseInsensitiveContains(searchString) {
|
||||
EmptyView()
|
||||
} else {
|
||||
NavigationLink(
|
||||
destination: PostEditorView(post: post),
|
||||
tag: post,
|
||||
selection: $model.selectedPost,
|
||||
label: {
|
||||
if model.showAllPosts {
|
||||
if let collection = collections.filter({ $0.alias == post.collectionAlias }).first {
|
||||
PostCellView(post: post, collectionName: collection.title)
|
||||
} else {
|
||||
// swiftlint:disable:next line_length
|
||||
let collectionName = model.account.server == "https://write.as" ? "Anonymous" : "Drafts"
|
||||
PostCellView(post: post, collectionName: collectionName)
|
||||
}
|
||||
} else {
|
||||
PostCellView(post: post)
|
||||
}
|
||||
})
|
||||
.deleteDisabled(post.status != PostStatus.local.rawValue)
|
||||
}
|
||||
}
|
||||
.onDelete(perform: { indexSet in
|
||||
for index in indexSet {
|
||||
let post = fetchRequest.wrappedValue[index]
|
||||
delete(post)
|
||||
}
|
||||
})
|
||||
}
|
||||
#if os(iOS)
|
||||
.searchable(text: $searchString, prompt: "Search across posts")
|
||||
#else
|
||||
.searchable(text: $searchString, placement: .toolbar, prompt: "Search across posts")
|
||||
#endif
|
||||
// if #available(iOS 16, macOS 13, *) {
|
||||
// NavigationStack(path: $path) {
|
||||
// Text("Hello, modern stack navigator!")
|
||||
// }
|
||||
// } else {
|
||||
DeprecatedListView(
|
||||
searchString: $searchString,
|
||||
collections: collections,
|
||||
fetchRequest: fetchRequest,
|
||||
onDelete: onDelete
|
||||
)
|
||||
// }
|
||||
}
|
||||
|
||||
func delete(_ post: WFAPost) {
|
||||
|
@ -140,6 +140,8 @@
|
||||
37113EF92A98C10A00B36B98 /* NoSelectedPostView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37113EF82A98C10A00B36B98 /* NoSelectedPostView.swift */; };
|
||||
374451452BFA845E0000BCDD /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 374451442BFA80EA0000BCDD /* PrivacyInfo.xcprivacy */; };
|
||||
374451462BFA845F0000BCDD /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 374451442BFA80EA0000BCDD /* PrivacyInfo.xcprivacy */; };
|
||||
371937842C5677FD005FC0A8 /* DeprecatedListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 371937832C5677FD005FC0A8 /* DeprecatedListView.swift */; };
|
||||
371937852C5677FD005FC0A8 /* DeprecatedListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 371937832C5677FD005FC0A8 /* DeprecatedListView.swift */; };
|
||||
375A67E828FC555C007A1AC0 /* MultilineTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 375A67E728FC555C007A1AC0 /* MultilineTextView.swift */; };
|
||||
376A350D2B5D5C8E00255D61 /* WFNavigation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 376A350C2B5D5C8E00255D61 /* WFNavigation.swift */; };
|
||||
376A350E2B5D5C8E00255D61 /* WFNavigation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 376A350C2B5D5C8E00255D61 /* WFNavigation.swift */; };
|
||||
@ -278,6 +280,7 @@
|
||||
17E5DF892543610700DCDC9B /* PostTextEditingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostTextEditingView.swift; sourceTree = "<group>"; };
|
||||
37113EF82A98C10A00B36B98 /* NoSelectedPostView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoSelectedPostView.swift; sourceTree = "<group>"; };
|
||||
374451442BFA80EA0000BCDD /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
|
||||
371937832C5677FD005FC0A8 /* DeprecatedListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeprecatedListView.swift; sourceTree = "<group>"; };
|
||||
375A67E728FC555C007A1AC0 /* MultilineTextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MultilineTextView.swift; sourceTree = "<group>"; };
|
||||
376A350C2B5D5C8E00255D61 /* WFNavigation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WFNavigation.swift; sourceTree = "<group>"; };
|
||||
3779389629EC0C880032D6C1 /* HelpCommands.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HelpCommands.swift; sourceTree = "<group>"; };
|
||||
@ -622,6 +625,7 @@
|
||||
17DF32D424C8CA3400BCE2E3 /* PostStatusBadgeView.swift */,
|
||||
17C42E642509237800072984 /* PostListFilteredView.swift */,
|
||||
37F749D029B4D3090087F0BF /* SearchablePostListFilteredView.swift */,
|
||||
371937832C5677FD005FC0A8 /* DeprecatedListView.swift */,
|
||||
);
|
||||
path = PostList;
|
||||
sourceTree = "<group>";
|
||||
@ -967,6 +971,7 @@
|
||||
17027E25286741B90062EB29 /* Logging.swift in Sources */,
|
||||
1727526628099802003D0A6A /* ErrorConstants.swift in Sources */,
|
||||
1756DC0324FEE18400207AB8 /* WFACollection+CoreDataProperties.swift in Sources */,
|
||||
371937842C5677FD005FC0A8 /* DeprecatedListView.swift in Sources */,
|
||||
17120DA224E1985C002B9F6C /* AccountModel.swift in Sources */,
|
||||
17120DA324E19A42002B9F6C /* PreferencesView.swift in Sources */,
|
||||
1756AE6E24CB255B00FD7257 /* PostListModel.swift in Sources */,
|
||||
@ -984,6 +989,7 @@
|
||||
files = (
|
||||
171DC678272C7D0B002B9B8A /* UserDefaults+Extensions.swift in Sources */,
|
||||
17DF32AD24C87D3500BCE2E3 /* ContentView.swift in Sources */,
|
||||
371937852C5677FD005FC0A8 /* DeprecatedListView.swift in Sources */,
|
||||
1756DBBB24FED45500207AB8 /* LocalStorageManager.swift in Sources */,
|
||||
17A4FEED25927E730037E96B /* AppDelegate.swift in Sources */,
|
||||
174D313324EC2831006CA9EE /* WriteFreelyModel.swift in Sources */,
|
||||
|
Loading…
Reference in New Issue
Block a user