@@ -118,27 +118,47 @@ export const importData = (
118
118
const oldConversationsParsed = oldConversations
119
119
? JSON . parse ( oldConversations )
120
120
: [ ] ;
121
- const newHistory : Conversation [ ] = [ ...oldConversationsParsed , ...history ] ;
122
- localStorage . setItem ( 'conversationHistory' , JSON . stringify ( newHistory ) ) ;
123
- localStorage . setItem (
124
- 'selectedConversation' ,
125
- JSON . stringify ( newHistory [ newHistory . length - 1 ] ) ,
121
+
122
+ const newHistory : Conversation [ ] = [
123
+ ...oldConversationsParsed ,
124
+ ...history ,
125
+ ] . filter (
126
+ ( conversation , index , self ) =>
127
+ index === self . findIndex ( ( c ) => c . id === conversation . id ) ,
126
128
) ;
129
+ localStorage . setItem ( 'conversationHistory' , JSON . stringify ( newHistory ) ) ;
130
+ if ( newHistory . length > 0 ) {
131
+ localStorage . setItem (
132
+ 'selectedConversation' ,
133
+ JSON . stringify ( newHistory [ newHistory . length - 1 ] ) ,
134
+ ) ;
135
+ } else {
136
+ localStorage . removeItem ( 'selectedConversation' ) ;
137
+ }
127
138
128
139
const oldFolders = localStorage . getItem ( 'folders' ) ;
129
140
const oldFoldersParsed = oldFolders ? JSON . parse ( oldFolders ) : [ ] ;
130
- const newFolders : FolderInterface [ ] = [ ...oldFoldersParsed , ...folders ] ;
141
+ const newFolders : FolderInterface [ ] = [
142
+ ...oldFoldersParsed ,
143
+ ...folders ,
144
+ ] . filter (
145
+ ( folder , index , self ) =>
146
+ index === self . findIndex ( ( f ) => f . id === folder . id ) ,
147
+ ) ;
131
148
localStorage . setItem ( 'folders' , JSON . stringify ( newFolders ) ) ;
132
149
133
150
const oldPrompts = localStorage . getItem ( 'prompts' ) ;
134
151
const oldPromptsParsed = oldPrompts ? JSON . parse ( oldPrompts ) : [ ] ;
135
- const newPrompts : Prompt [ ] = [ ...oldPromptsParsed , ...prompts ] ;
152
+ const newPrompts : Prompt [ ] = [ ...oldPromptsParsed , ...prompts ] . filter (
153
+ ( prompt , index , self ) =>
154
+ index === self . findIndex ( ( p ) => p . id === prompt . id ) ,
155
+ ) ;
136
156
localStorage . setItem ( 'prompts' , JSON . stringify ( newPrompts ) ) ;
137
157
138
158
return {
139
159
version : 4 ,
140
- history : newHistory . map ( ( e , idx ) => ( { ... e , id : ` ${ idx } ` } ) ) ,
141
- folders : newFolders . map ( ( e , idx ) => ( { ... e , id : ` ${ idx } ` } ) ) ,
142
- prompts : newPrompts . map ( ( e , idx ) => ( { ... e , id : ` ${ idx } ` } ) ) ,
160
+ history : newHistory ,
161
+ folders : newFolders ,
162
+ prompts : newPrompts ,
143
163
} ;
144
164
} ;
0 commit comments