Page Menu
Home
Musing Studio
Search
Configure Global Search
Log In
Files
F14172726
SearchablePostListFilteredView.swift
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Subscribers
None
SearchablePostListFilteredView.swift
View Options
import
SwiftUI
@
available
(
iOS
15
,
macOS
12.0
,
*
)
struct
SearchablePostListFilteredView
:
View
{
@
EnvironmentObject
var
model
:
WriteFreelyModel
@
Binding
var
postCount
:
Int
@
State
private
var
searchString
=
""
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
)
}
}
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Thu, Apr 2, 3:16 AM (21 h, 32 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3673248
Attached To
rWFSUI WriteFreely SwiftUI
Event Timeline
Log In to Comment