Skip to content

Commit 39ad88a

Browse files
author
Philipp Heckel
committed
Fix drag and drop / allowSubmit
1 parent 806cac3 commit 39ad88a

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

server/index.gohtml

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@
109109
<div class="col"></div>
110110
<div class="col-auto col-last">
111111
<button id="info-button" class="button">What is this?</button>
112-
<button id="save-button" class="button">Save</button>
113-
<button id="upload-button" class="button">Upload</button>
112+
<button id="save-button" class="button" title="Save the contents of the text area and generate a link">Save</button>
113+
<button id="upload-button" class="button" title="Pick a file from your computer, upload it and generate a link to access it">Upload</button>
114114
<button id="logout-button" class="button hidden">Logout</button>
115115
<input type="file" id="file-upload" class="hidden" onchange="handleFile(this.files[0])">
116116
</div>

server/static/js/app.js

+18-11
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ function logout() {
130130
/* Drag & drop */
131131

132132
function showDropZone() {
133-
if (allowSubmit) {
133+
if (allowSubmit()) {
134134
dropArea.style.visibility = "visible";
135135
hideInfoArea()
136136
}
@@ -141,7 +141,7 @@ function hideDropZone() {
141141
}
142142

143143
function allowDrag(e) {
144-
if (allowSubmit) {
144+
if (allowSubmit()) {
145145
e.dataTransfer.dropEffect = 'copy';
146146
e.preventDefault();
147147
}
@@ -176,25 +176,33 @@ headerFileId.value = ''
176176

177177
/* File ID: input validation */
178178

179-
let allowSubmit = true
180179
headerFileId.addEventListener('keyup', fileIdChanged)
181180
headerFileId.addEventListener('paste', fileIdChanged)
182181

183182
function fileIdChanged(e) {
184-
let textValid = headerFileId.value === "" || /^[0-9a-z][-_.0-9a-z]*$/i.test(headerFileId.value)
185-
if (textValid) {
186-
allowSubmit = true
183+
if (textValid()) {
187184
headerFileId.classList.remove('error')
188185
headerSaveButton.disabled = false
189186
headerUploadButton.disabled = false
190187
} else {
191-
allowSubmit = false
192188
headerFileId.classList.add('error')
193189
headerSaveButton.disabled = true
194190
headerUploadButton.disabled = true
195191
}
196192
}
197193

194+
function textValid() {
195+
return headerFileId.value === "" || /^[0-9a-z][-_.0-9a-z]*$/i.test(headerFileId.value)
196+
}
197+
198+
function allowSubmit() {
199+
if (clientSideEnabled()) {
200+
return false
201+
} else {
202+
return textValid()
203+
}
204+
}
205+
198206
/* File ID: random name checkbox */
199207

200208
headerRandomFileId.checked = randomFileNameEnabled()
@@ -241,7 +249,7 @@ function changeClientSideEnabled(enabled) {
241249
headerStream.disabled = true
242250
headerUploadButton.disabled = true
243251
} else {
244-
changeRandomFileIdEnabled(headerFileId.checked)
252+
changeRandomFileIdEnabled(randomFileNameEnabled())
245253
headerRandomFileId.disabled = false
246254
headerTTL.disabled = false
247255
headerStream.disabled = false
@@ -384,7 +392,6 @@ async function saveClientSide() {
384392
reader.onload = () => {
385393
const data = reader.result.substr(reader.result.indexOf(',') + 1)
386394
const url = `${location.protocol}//${location.host}${location.pathname}#${data}`;
387-
location.href = url // update #anchor
388395
progressFinish(200, "", url, "", 0, false)
389396
};
390397
reader.readAsDataURL(new Blob([new Uint8Array(compressed)]));
@@ -396,7 +403,7 @@ async function saveClientSide() {
396403
}
397404

398405
async function saveServerSide() {
399-
if (!allowSubmit) {
406+
if (!allowSubmit()) {
400407
return
401408
}
402409

@@ -632,7 +639,7 @@ async function reserveAndUpdateLinkFields(file, nameHint) {
632639
}
633640

634641
async function uploadFile(file) {
635-
if (!allowSubmit) {
642+
if (!allowSubmit()) {
636643
return
637644
}
638645

0 commit comments

Comments
 (0)