Skip to content

Commit feea49d

Browse files
committed
improve dictionary importing
1 parent 88c7f01 commit feea49d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/main.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ const DICTIONARY_LOADING_FAILED_MESSAGE =
5959
"syntax. Please fix it. Apologies for the inconvenience.";
6060
const NO_WORD_MESSAGE = "Please provide a word";
6161
const 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

6467
function 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

Comments
 (0)