Page Menu
Home
Musing Studio
Search
Configure Global Search
Log In
Files
F14177227
CollectionListView.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
CollectionListView.swift
View Options
import
SwiftUI
struct
CollectionListView
:
View
{
@
EnvironmentObject
var
model
:
WriteFreelyModel
@
ObservedObject
var
collections
=
CollectionListModel
(
managedObjectContext
:
LocalStorageManager
.
persistentContainer
.
viewContext
)
@
State
var
selectedCollection
:
WFACollection
?
var
body
:
some
View
{
List
(
selection
:
$
selectedCollection
)
{
if
model
.
account
.
isLoggedIn
{
NavigationLink
(
"All Posts"
,
destination
:
PostListView
(
selectedCollection
:
nil
,
showAllPosts
:
true
))
NavigationLink
(
"Drafts"
,
destination
:
PostListView
(
selectedCollection
:
nil
,
showAllPosts
:
false
))
Section
(
header
:
Text
(
"Your Blogs"
))
{
ForEach
(
collections
.
list
,
id
:
\
.
self
)
{
collection
in
NavigationLink
(
destination
:
PostListView
(
selectedCollection
:
collection
,
showAllPosts
:
false
),
tag
:
collection
,
selection
:
$
selectedCollection
,
label
:
{
Text
(
"
\(
collection
.
title
)
"
)
})
}
}
}
else
{
NavigationLink
(
destination
:
PostListView
(
selectedCollection
:
nil
,
showAllPosts
:
false
))
{
Text
(
"Drafts"
)
}
}
}
.
navigationTitle
(
model
.
account
.
isLoggedIn
?
"
\(
URL
(
string
:
model
.
account
.
server
)
?.
host
??
"WriteFreely"
)
"
:
"WriteFreely"
)
.
listStyle
(
SidebarListStyle
())
.
onChange
(
of
:
model
.
selectedCollection
)
{
collection
in
if
collection
!=
model
.
editor
.
fetchSelectedCollectionFromAppStorage
()
{
self
.
model
.
editor
.
selectedCollectionURL
=
collection
?.
objectID
.
uriRepresentation
()
}
}
.
onChange
(
of
:
model
.
showAllPosts
)
{
value
in
if
value
!=
model
.
editor
.
showAllPostsFlag
{
self
.
model
.
editor
.
showAllPostsFlag
=
model
.
showAllPosts
}
}
}
}
struct
CollectionListView_LoggedOutPreviews
:
PreviewProvider
{
static
var
previews
:
some
View
{
let
context
=
LocalStorageManager
.
persistentContainer
.
viewContext
let
model
=
WriteFreelyModel
()
return
CollectionListView
()
.
environment
(
\
.
managedObjectContext
,
context
)
.
environmentObject
(
model
)
}
}
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Thu, Apr 2, 5:44 AM (11 h, 40 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3673638
Attached To
rWFSUI WriteFreely SwiftUI
Event Timeline
Log In to Comment