@@ -59,7 +59,10 @@ const DICTIONARY_LOADING_FAILED_MESSAGE =
5959 "syntax. Please fix it. Apologies for the inconvenience." ;
6060const NO_WORD_MESSAGE = "Please provide a word" ;
6161const WORD_NOT_FOUND_MESSAGE = "Word not found" ;
62- const DICTIONARY_ERROR_MESSAGE = "Please fix the errors before saving" ;
62+ const WORD_ALREADY_IMPORTED_MESSAGE = "The word is already imported" ;
63+ const DICTIONARY_ERROR_MESSAGE_ON_IMPORT =
64+ "Please fix the errors before adding words" ;
65+ const DICTIONARY_ERROR_MESSAGE_ON_SAVE = "Please fix the errors before saving" ;
6366
6467function main ( ) : void {
6568 // load elements
@@ -296,6 +299,12 @@ function main(): void {
296299 const word = importWordTextBox . value . trim ( ) ;
297300 if ( word === "" ) {
298301 showMessage ( NO_WORD_MESSAGE ) ;
302+ } else if ( currentDictionary . isError ( ) ) {
303+ showMessage ( WORD_ALREADY_IMPORTED_MESSAGE ) ;
304+ } else if (
305+ currentDictionary . unwrap ( ) [ 0 ] . has ( word )
306+ ) {
307+ showMessage ( DICTIONARY_ERROR_MESSAGE_ON_IMPORT ) ;
299308 } else {
300309 const definitions = dictionary . get ( word ) ?. source ;
301310 if ( definitions != null ) {
@@ -307,6 +316,7 @@ function main(): void {
307316 0 ,
308317 customDictionaryTextBox . scrollHeight ,
309318 ) ;
319+ updateDictionary ( ) ;
310320 } else {
311321 showMessage ( WORD_NOT_FOUND_MESSAGE ) ;
312322 }
@@ -344,7 +354,7 @@ function main(): void {
344354 setIgnoreError ( DICTIONARY_KEY , customDictionaryTextBox . value ) ;
345355 customDictionaryDialogBox . close ( ) ;
346356 } else {
347- showMessage ( DICTIONARY_ERROR_MESSAGE ) ;
357+ showMessage ( DICTIONARY_ERROR_MESSAGE_ON_SAVE ) ;
348358 }
349359 }
350360 closeButton . addEventListener ( "click" , ( ) => {
0 commit comments