Page Menu
Home
Musing Studio
Search
Configure Global Search
Log In
Files
F14174843
PostEditorView.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
PostEditorView.swift
View Options
import
SwiftUI
struct
PostEditorView
:
View
{
@
EnvironmentObject
var
model
:
WriteFreelyModel
@
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
)
{
PostStatusBadgeView
(
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
=
!
model
.
store
.
posts
.
contains
(
where
:
{
$0
.
id
==
post
.
id
})
}
private
func
addNewPostToStore
()
{
withAnimation
{
model
.
store
.
add
(
post
)
self
.
isNewPost
=
false
}
}
}
struct
PostEditorView_NewDraftPreviews
:
PreviewProvider
{
static
var
previews
:
some
View
{
PostEditorView
(
post
:
Post
())
.
environmentObject
(
WriteFreelyModel
())
}
}
struct
PostEditorView_ExistingPostPreviews
:
PreviewProvider
{
static
var
previews
:
some
View
{
PostEditorView
(
post
:
testPostData
[
0
])
.
environmentObject
(
WriteFreelyModel
())
}
}
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Thu, Apr 2, 4:28 AM (1 d, 18 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3673765
Attached To
rWFSUI WriteFreely SwiftUI
Event Timeline
Log In to Comment