Page Menu
Home
Musing Studio
Search
Configure Global Search
Log In
Files
F14171562
PostEditor.swift
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
PostEditor.swift
View Options
import
SwiftUI
struct
PostEditor
:
View
{
@
EnvironmentObject
var
postStore
:
PostStore
@
ObservedObject
var
post
:
Post
@
State
private
var
isNewPost
=
false
var
body
:
some
View
{
VStack
{
TextEditor
(
text
:
$
post
.
title
)
.
font
(.
title
)
.
frame
(
height
:
100
)
.
onChange
(
of
:
post
.
title
)
{
_
in
if
post
.
status
==
.
published
{
post
.
status
=
.
edited
}
}
TextEditor
(
text
:
$
post
.
body
)
.
font
(.
body
)
.
onChange
(
of
:
post
.
body
)
{
_
in
if
post
.
status
==
.
published
{
post
.
status
=
.
edited
}
}
}
.
padding
()
.
toolbar
{
ToolbarItem
(
placement
:
.
status
)
{
PostStatusBadge
(
post
:
post
)
}
ToolbarItem
(
placement
:
.
primaryAction
)
{
Button
(
action
:
{
post
.
status
=
.
published
},
label
:
{
Image
(
systemName
:
"paperplane"
)
})
}
}
.
onAppear
(
perform
:
{
checkIfNewPost
()
if
self
.
isNewPost
{
addNewPostToStore
()
}
})
}
private
func
checkIfNewPost
()
{
self
.
isNewPost
=
!
postStore
.
posts
.
contains
(
where
:
{
$0
.
id
==
post
.
id
})
}
private
func
addNewPostToStore
()
{
withAnimation
{
postStore
.
add
(
post
)
self
.
isNewPost
=
false
}
}
}
struct
PostEditor_NewDraftPreviews
:
PreviewProvider
{
static
var
previews
:
some
View
{
PostEditor
(
post
:
Post
())
.
environmentObject
(
testPostStore
)
}
}
struct
PostEditor_ExistingPostPreviews
:
PreviewProvider
{
static
var
previews
:
some
View
{
PostEditor
(
post
:
testPostData
[
0
])
.
environmentObject
(
testPostStore
)
}
}
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Thu, Apr 2, 2:20 AM (1 d, 3 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3673777
Attached To
rWFSUI WriteFreely SwiftUI
Event Timeline
Log In to Comment