Change 'change video' button to 'remove video'

This commit is contained in:
Reimar 2026-01-09 08:58:18 +01:00
parent 5e937f5de6
commit 2cc5437f21
Signed by: Reimar
GPG Key ID: 93549FA07F0AE268
5 changed files with 33 additions and 20 deletions

View File

@ -2,6 +2,7 @@ export class FileSelector {
dropZones = [];
selectedFile = null;
onFileSelected = null;
onFileRemoved = null;
constructor(mimeType) {
this.mimeType = mimeType;
@ -24,6 +25,12 @@ export class FileSelector {
if (this.onFileSelected) this.onFileSelected(file);
}
removeFile() {
this.selectedFile = null;
if (this.onFileRemoved) this.onFileRemoved();
}
addInput(elem) {
elem.oninput = () => {
setTimeout(() => this.selectFile(elem.files[0]), 200);

View File

@ -21,26 +21,26 @@ export class UiManager {
elem.style.opacity = "0";
elem.dataset.oldDisplay = getComputedStyle(elem).display;
setTimeout(() => {
elem.style.display = "none";
}, this.TRANSITION_TIME);
setTimeout(() => elem.style.display = "none", this.TRANSITION_TIME);
}
}
showElements() {
setTimeout(() => {
for (const input of arguments) {
const elem = input instanceof Element ? input : document.querySelector(input);
return new Promise(resolve => {
setTimeout(() => {
for (const input of arguments) {
const elem = input instanceof Element ? input : document.querySelector(input);
elem.style.opacity = "0";
elem.style.opacity = "0";
elem.style.display = elem.dataset.oldDisplay || "block";
elem.dataset.oldDisplay = null;
elem.style.display = elem.dataset.oldDisplay || "block";
elem.dataset.oldDisplay = null;
setTimeout(() => {
elem.style.opacity = "1";
}, 10);
}
}, this.TRANSITION_TIME);
setTimeout(() => elem.style.opacity = "1", 10);
}
resolve();
}, this.TRANSITION_TIME);
});
}
}

View File

@ -18,9 +18,18 @@ fileSelector.onFileSelected = file => {
document.getElementById("uploaded-video").load();
ui.hideElements("#file-drop-area", "#file-input-spacing");
ui.showElements("#uploaded-video", "#change-file");
ui.showElements("#uploaded-video", "#remove-file");
};
fileSelector.onFileRemoved = async () => {
ui.hideElements("#uploaded-video", "#remove-file");
await ui.showElements("#file-drop-area", "#file-input-spacing");
document.getElementById("uploaded-video").src = "";
}
document.getElementById("remove-file").onclick = () => fileSelector.removeFile();
async function compress(filesize, filesizeUnit) {
document.getElementById("uploaded-video").pause();
@ -97,9 +106,6 @@ document.getElementById("cancel").onclick = () => {
ui.showSection("file-picker");
};
document.getElementById("change-file").onclick = () => document.getElementById("file-input").click();
document.getElementById("back").onclick = () => ui.showSection("file-picker");
window.onbeforeunload = event => {

View File

@ -1,4 +1,4 @@
#file-input, #change-file {
#file-input, #remove-file {
display: none;
opacity: 0;
}

View File

@ -30,7 +30,7 @@
</div>
<video id="uploaded-video" controls autoplay></video>
<button id="change-file" class="simple">Change video</button>
<button id="remove-file" class="simple">Remove video</button>
<input id="filesize" type="number" value="10" size="3" placeholder="#" style="margin-top: 1rem"><!--