@@ -2,16 +2,20 @@ import { Box, Button, HStack, Input, Text, VStack } from '@chakra-ui/react';
22import { MDXEditor } from '@mdxeditor/editor' ;
33import { ALL_PLUGINS } from './AllPlugins' ;
44import '@mdxeditor/editor/style.css' ;
5- import { ArticleCard , MdPreview , useCursor } from '@components' ;
5+ import { ArticleCard , useCursor } from '@components' ;
66import { useCallback , useLayoutEffect , useState } from 'react' ;
77import { ARTICLE_DEFAULT } from './constants' ;
88import { ArticleWithContent } from './types' ;
99import { getRequestObject , isValidArticle } from './utils' ;
10- import { useAddArticle } from '@services' ;
10+ import { useAddArticle , useGetEditorArticleData } from '@services' ;
11+ import ArticlePreviewDrawer from './ArticlePreviewDrawar' ;
1112
1213const ArticleEditor = ( ) => {
1314 const { setCursorType } = useCursor ( ) ;
15+ const [ articleKey , setArticleKey ] = useState < string > ( '' ) ;
16+ const [ queryArticleKey , setQueryArticleKey ] = useState < string > ( '' ) ;
1417 const [ state , setState ] = useState < ArticleWithContent > ( ARTICLE_DEFAULT ) ;
18+ const { data, isPending } = useGetEditorArticleData ( queryArticleKey ) ;
1519 const { mutate } = useAddArticle ( ) ;
1620
1721 useLayoutEffect ( ( ) => {
@@ -23,8 +27,23 @@ const ArticleEditor = () => {
2327 console . log ( 'Submitting article' , state ) ;
2428 } , [ mutate , state ] ) ;
2529
30+ useLayoutEffect ( ( ) => {
31+ if ( data ) {
32+ console . log ( 'Data' , ( data as any ) ?. data . rows [ 0 ] ) ;
33+ console . log ( 'state' , state ) ;
34+ setState ( ( data as any ) ?. data . rows [ 0 ] ) ;
35+ }
36+ } , [ data , state ] ) ;
37+
2638 return (
27- < VStack px = { 10 } pt = { 20 } width = { '100vw' } rowGap = { 4 } bg = { 'black' } >
39+ < VStack
40+ px = { 10 }
41+ pt = { 20 }
42+ width = { '100vw' }
43+ rowGap = { 4 }
44+ bg = { 'black' }
45+ color = { 'gray.100' }
46+ >
2847 < HStack width = { '100%' } justifyContent = { 'space-between' } align = { 'start' } >
2948 < VStack w = { '80%' } rowGap = { 4 } >
3049 < HStack w = { '100%' } justifyContent = { 'space-between' } >
@@ -37,7 +56,10 @@ const ArticleEditor = () => {
3756 Article editor
3857 </ Text >
3958 < Button
40- onClick = { ( ) => setState ( ARTICLE_DEFAULT ) }
59+ onClick = { ( ) => {
60+ setState ( ARTICLE_DEFAULT ) ;
61+ setQueryArticleKey ( '' ) ;
62+ } }
4163 colorScheme = { 'red' }
4264 >
4365 Clear Article
@@ -125,13 +147,27 @@ const ArticleEditor = () => {
125147 Submit Article
126148 </ Button >
127149 </ VStack >
128- < ArticleCard
129- views = { 0 }
130- likes = { 0 }
131- last_updated = { new Date ( ) . toISOString ( ) }
132- { ...state }
133- />
150+ < VStack borderLeft = { '1px solid gray' } p = { 1 } >
151+ < HStack >
152+ < Input
153+ placeholder = "Article Key"
154+ value = { articleKey }
155+ onChange = { ( e ) => setArticleKey ( e . target . value ) }
156+ />
157+ < Button
158+ isDisabled = { isPending }
159+ isLoading = { isPending }
160+ onClick = { ( ) => setQueryArticleKey ( articleKey ) }
161+ >
162+ Preload
163+ </ Button >
164+ </ HStack >
165+ < ArticleCard { ...state } />
166+ </ VStack >
134167 </ HStack >
168+ < Box w = { '100%' } h = { '100%' } borderRadius = { 'md' } >
169+ < ArticlePreviewDrawer mdString = { state . md_data } />
170+ </ Box >
135171 < HStack
136172 width = { '100%' }
137173 border = { '1px solid white' }
@@ -153,17 +189,6 @@ const ArticleEditor = () => {
153189 } ) ) ;
154190 } }
155191 />
156- < Box w = { '100%' } h = { '100%' } bg = { 'gray.900' } borderRadius = { 'md' } >
157- < Text
158- textAlign = { 'center' }
159- color = { 'white' }
160- fontSize = { '2xl' }
161- fontWeight = { 'bold' }
162- >
163- Preview
164- </ Text >
165- < MdPreview mdString = { state . md_data } />
166- </ Box >
167192 </ HStack >
168193 </ VStack >
169194 ) ;
0 commit comments