@@ -45,7 +45,6 @@ export const CreatePostView: React.FC = () => {
4545 const { type } = useParams < { type : "new" | "edit" } > ( )
4646 const [ loading , setLoading ] = useState < boolean > ( false )
4747 const [ currentTab , setCurrentTab ] = useState < "write" | "preview" > ( "write" )
48- const [ articleContent , setArticleContent ] = useState < string > ( "" )
4948 const permissions = article && article . publication && article . publication . permissions
5049 const havePermissionToDelete = haveActionPermission ( permissions || [ ] , "articleDelete" , account || "" )
5150 const havePermissionToUpdate = haveActionPermission ( permissions || [ ] , "articleUpdate" , account || "" )
@@ -86,8 +85,9 @@ export const CreatePostView: React.FC = () => {
8685 }
8786 } , [ navigate , saveDraftArticle , transactionCompleted ] )
8887
88+
8989 const handleChange = ( event : ChangeEvent < HTMLInputElement > ) => {
90- setArticleContent ( event . target . value )
90+ setValue ( "article" , event . target . value )
9191 }
9292
9393 const onSubmitHandler = ( data : Article ) => {
@@ -158,53 +158,46 @@ export const CreatePostView: React.FC = () => {
158158 ) }
159159 </ Grid >
160160 < Grid item xs = { 12 } >
161-
162161 < ArticleTabs onChange = { setCurrentTab } />
163- { currentTab === "write" && (
164- < >
165- < Controller
166- control = { control }
167- name = "article"
168- render = { ( { field } ) => (
162+ < Controller
163+ control = { control }
164+ name = "article"
165+ render = { ( { field } ) => {
166+ return (
167+ currentTab === "write" ? (
169168 < TextField
170- { ...field }
171- placeholder = "Start your post..."
172- multiline
173- rows = { 14 }
174- onChange = { handleChange }
175- value = { articleContent }
176- sx = { {
177- width : "100%" ,
178- "& .MuiInputBase-root" : {
179- borderTopLeftRadius : 0 ,
180- }
181- } }
182- />
183- ) }
184- rules = { { required : true } }
185- />
186-
187- { errors && errors . article && (
188- < FormHelperText sx = { { color : palette . secondary [ 1000 ] , textTransform : "capitalize" } } >
189- { errors . article . message }
190- </ FormHelperText >
191- ) }
192- </ >
193- ) }
194- { currentTab === "preview" && (
195- articleContent ? (
196- < Markdown > { articleContent } </ Markdown >
197- ) : (
198- < Box
199- sx = { {
200- color : palette . grays [ 800 ] ,
201- fontSize : 14 ,
202- mt : 1
203- } }
204- >
205- Nothing to preview
206- </ Box >
207- )
169+ { ...field }
170+ placeholder = "Start your post..."
171+ multiline
172+ rows = { 14 }
173+ onChange = { handleChange }
174+ sx = { {
175+ width : "100%" ,
176+ "& .MuiInputBase-root" : {
177+ borderTopLeftRadius : 0 ,
178+ }
179+ } }
180+ />
181+ ) : (
182+ < Box sx = { { borderTop : `1px solid ${ palette . grays [ 400 ] } ` , pt : 1 } } >
183+ { field . value ? (
184+ < Markdown > { field . value } </ Markdown >
185+ ) : (
186+ < Box sx = { { color : palette . grays [ 800 ] , fontSize : 14 } } >
187+ Nothing to preview
188+ </ Box >
189+ ) }
190+ </ Box >
191+ )
192+ )
193+ } }
194+ rules = { { required : true } }
195+ />
196+
197+ { errors && errors . article && (
198+ < FormHelperText sx = { { color : palette . secondary [ 1000 ] , textTransform : "capitalize" } } >
199+ { errors . article . message }
200+ </ FormHelperText >
208201 ) }
209202
210203 </ Grid >
0 commit comments