Skip to content

Commit a207b2f

Browse files
refactor: harden github import modal disable handling
Co-authored-by: ThisIs-Developer <109382325+ThisIs-Developer@users.noreply.github.com>
1 parent 359a903 commit a207b2f

1 file changed

Lines changed: 20 additions & 24 deletions

File tree

script.js

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,12 @@ This is a fully client-side application. Your content never leaves your browser
982982

983983
async function handleGitHubImportSubmit() {
984984
if (!githubImportSubmitBtn || !githubImportUrlInput || !githubImportFileSelect) return;
985+
const setGitHubImportDialogDisabled = (disabled) => {
986+
githubImportSubmitBtn.disabled = disabled;
987+
if (githubImportCancelBtn) {
988+
githubImportCancelBtn.disabled = disabled;
989+
}
990+
};
985991
const step = githubImportSubmitBtn.dataset.step || "url";
986992
if (step === "select") {
987993
const selectedPath = githubImportFileSelect.value;
@@ -993,8 +999,7 @@ This is a fully client-side application. Your content never leaves your browser
993999
return;
9941000
}
9951001
setGitHubImportLoading(true);
996-
githubImportSubmitBtn.disabled = true;
997-
githubImportCancelBtn.disabled = true;
1002+
setGitHubImportDialogDisabled(true);
9981003
try {
9991004
const markdown = await fetchTextContent(buildRawGitHubUrl(owner, repo, ref, selectedPath));
10001005
newTab(markdown, getFileName(selectedPath).replace(/\.(md|markdown)$/i, ""));
@@ -1003,8 +1008,7 @@ This is a fully client-side application. Your content never leaves your browser
10031008
console.error("GitHub import failed:", error);
10041009
setGitHubImportMessage("GitHub import failed: " + error.message);
10051010
} finally {
1006-
githubImportSubmitBtn.disabled = false;
1007-
githubImportCancelBtn.disabled = false;
1011+
setGitHubImportDialogDisabled(false);
10081012
setGitHubImportLoading(false);
10091013
}
10101014
return;
@@ -1024,8 +1028,7 @@ This is a fully client-side application. Your content never leaves your browser
10241028

10251029
setGitHubImportMessage("");
10261030
setGitHubImportLoading(true);
1027-
githubImportSubmitBtn.disabled = true;
1028-
githubImportCancelBtn.disabled = true;
1031+
setGitHubImportDialogDisabled(true);
10291032
try {
10301033
if (parsed.type === "file") {
10311034
if (!isMarkdownPath(parsed.filePath)) {
@@ -1080,8 +1083,7 @@ This is a fully client-side application. Your content never leaves your browser
10801083
console.error("GitHub import failed:", error);
10811084
setGitHubImportMessage("GitHub import failed: " + error.message);
10821085
} finally {
1083-
githubImportSubmitBtn.disabled = false;
1084-
githubImportCancelBtn.disabled = false;
1086+
setGitHubImportDialogDisabled(false);
10851087
setGitHubImportLoading(false);
10861088
}
10871089
}
@@ -1537,25 +1539,19 @@ This is a fully client-side application. Your content never leaves your browser
15371539
if (githubImportCancelBtn) {
15381540
githubImportCancelBtn.addEventListener("click", closeGitHubImportModal);
15391541
}
1542+
const handleGitHubImportInputKeydown = function(e) {
1543+
if (e.key === "Enter") {
1544+
e.preventDefault();
1545+
handleGitHubImportSubmit();
1546+
} else if (e.key === "Escape") {
1547+
closeGitHubImportModal();
1548+
}
1549+
};
15401550
if (githubImportUrlInput) {
1541-
githubImportUrlInput.addEventListener("keydown", function(e) {
1542-
if (e.key === "Enter") {
1543-
e.preventDefault();
1544-
handleGitHubImportSubmit();
1545-
} else if (e.key === "Escape") {
1546-
closeGitHubImportModal();
1547-
}
1548-
});
1551+
githubImportUrlInput.addEventListener("keydown", handleGitHubImportInputKeydown);
15491552
}
15501553
if (githubImportFileSelect) {
1551-
githubImportFileSelect.addEventListener("keydown", function(e) {
1552-
if (e.key === "Enter") {
1553-
e.preventDefault();
1554-
handleGitHubImportSubmit();
1555-
} else if (e.key === "Escape") {
1556-
closeGitHubImportModal();
1557-
}
1558-
});
1554+
githubImportFileSelect.addEventListener("keydown", handleGitHubImportInputKeydown);
15591555
}
15601556

15611557
fileInput.addEventListener("change", function (e) {

0 commit comments

Comments
 (0)