@@ -56,10 +56,18 @@ export default function NewPostPage() {
5656 [ e . target . name ] : e . target . value ,
5757 } ) as TPostAPI ,
5858 ) ;
59+ localStorage . setItem ( "postData" , JSON . stringify ( data ) ) ;
5960 }
6061
62+ useEffect ( ( ) => {
63+ if ( data . title !== "" || data . sig !== "" || data . hashtag ?. length !== 0 ) {
64+ localStorage . setItem ( "postData" , JSON . stringify ( data ) ) ;
65+ }
66+ } , [ data ] ) ;
67+
6168 useEffect ( ( ) => {
6269 const storedContent = localStorage ?. getItem ( "editorContent" ) ;
70+ const storedData = localStorage ?. getItem ( "postData" ) ;
6371 if ( storedContent ) {
6472 setPostData (
6573 ( prev : TPostAPI | undefined ) =>
@@ -69,6 +77,15 @@ export default function NewPostPage() {
6977 } ) as TPostAPI ,
7078 ) ;
7179 }
80+ if ( storedData ) {
81+ setPostData (
82+ ( prev : TPostAPI | undefined ) =>
83+ ( {
84+ ...prev ,
85+ ...JSON . parse ( storedData ) ,
86+ } ) as TPostAPI ,
87+ ) ;
88+ }
7289 } , [ ] ) ;
7390
7491 async function NewPostAPI ( ) {
@@ -96,6 +113,7 @@ export default function NewPostPage() {
96113 return Swal . fire ( alertMessageConfigs . Success ) . then ( ( ) => {
97114 setPostButtonDisable ( false ) ;
98115 localStorage . removeItem ( "editorContent" ) ;
116+ localStorage . removeItem ( "postData" ) ;
99117 route . push ( `/post/${ res . data . _id } ` ) ;
100118 } ) ;
101119 } else if ( res . status === 4001 ) {
@@ -123,6 +141,7 @@ export default function NewPostPage() {
123141 hashtag : [ ] ,
124142 } ) ;
125143 localStorage . removeItem ( "editorContent" ) ;
144+ localStorage . removeItem ( "postData" ) ;
126145 }
127146
128147 async function handleFileChange ( e : ChangeEvent < HTMLInputElement > ) {
0 commit comments