Skip to content

Commit

Permalink
feat(custom text): add text file opening (Shuja-Mahmood) (#4596)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shuja-Mahmood committed Sep 11, 2023
1 parent 9f05da9 commit 7c971e5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion frontend/src/styles/popups.scss
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@

.buttonsTop {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-template-columns: 1fr 1fr 1fr 1fr;
gap: 1rem;
}

Expand Down
3 changes: 3 additions & 0 deletions frontend/src/styles/z_media-queries.scss
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
// .pageSettings .section.themes .buttons {
// grid-template-columns: 1fr 1fr 1fr;
// }
#customTextPopupWrapper #customTextPopup .buttonsTop {
grid-template-columns: 1fr 1fr;
}
}

//1050px
Expand Down
26 changes: 26 additions & 0 deletions frontend/src/ts/popups/custom-text-popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,4 +384,30 @@ $(`#customTextPopupWrapper .longCustomTextWarning .button`).on("click", () => {
$(`#customTextPopup .longCustomTextWarning`).addClass("hidden");
});

$(`#fileInput`).on("change", () => {
const file = ($(`#fileInput`)[0] as HTMLInputElement).files?.[0];
if (file) {
if (file.type !== "text/plain") {
Notifications.add("File is not a text file", -1, {
duration: 5,
});
return;
}

const reader = new FileReader();
reader.readAsText(file, "UTF-8");

reader.onload = (readerEvent): void => {
const content = readerEvent.target?.result as string;
$(`${popup} textarea`).val(content);
$(`#fileInput`).val("");
};
reader.onerror = (): void => {
Notifications.add("Failed to read file", -1, {
duration: 5,
});
};
}
});

Skeleton.save(skeletonId);
5 changes: 5 additions & 0 deletions frontend/static/html/popups.html
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,11 @@
<i class="fas fa-folder"></i>
Show saved texts
</div>
<input id="fileInput" type="file" class="hidden" accept=".txt" />
<label for="fileInput" class="button importText">
<i class="fas fa-file-import"></i>
Open file
</label>
<div class="button wordfilter">
<i class="fas fa-filter"></i>
Words filter
Expand Down

0 comments on commit 7c971e5

Please sign in to comment.