Skip to content

Commit b8b0253

Browse files
committed
Format JS Code
1 parent 1e90b18 commit b8b0253

File tree

5 files changed

+398
-215
lines changed

5 files changed

+398
-215
lines changed

public/scripts/form.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ function isPollInputValid(data) {
2828
const pollOptionB = data.get('pollOptionB');
2929
const pollOptionC = data.get('pollOptionC');
3030
const pollOptionD = data.get('pollOptionD');
31-
const pollAttached = pollOptionA || pollOptionB || pollOptionC || pollOptionD;
31+
const pollAttached =
32+
pollOptionA || pollOptionB || pollOptionC || pollOptionD;
3233

3334
if (pollAttached && (!pollOptionA || !pollOptionB)) {
3435
alert('Options A and B are required for polls.');
@@ -59,16 +60,16 @@ function isAttachmentsInputValid(data) {
5960
}
6061

6162
if (hasMediaAttachment && autoPublishText) {
62-
alert('Media attachments cannot be automatically published.')
63+
alert('Media attachments cannot be automatically published.');
6364
return false;
6465
}
6566

6667
if (hasMediaAttachment && linkAttached) {
67-
alert('Link attachments can only be used with text posts.')
68+
alert('Link attachments can only be used with text posts.');
6869
}
6970

7071
if (hasMediaAttachment && pollAttached) {
71-
alert('Poll attachments can only be used with text posts.')
72+
alert('Poll attachments can only be used with text posts.');
7273
}
7374

7475
return true;
@@ -101,10 +102,10 @@ async function processFormAsync(urlGenerator) {
101102
try {
102103
let response = await fetch(e.target.getAttribute('action'), {
103104
method: 'POST',
104-
body: formData
105+
body: formData,
105106
});
106107

107-
if(response.ok) {
108+
if (response.ok) {
108109
let jsonResponse = await response.json();
109110
id = jsonResponse.id;
110111
redirectUrl = jsonResponse.redirectUrl;

public/scripts/hide-reply.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,21 @@ document.addEventListener('DOMContentLoaded', async () => {
1717
try {
1818
let response = await fetch(e.target.getAttribute('action'), {
1919
method: 'POST',
20-
body: formData
20+
body: formData,
2121
});
2222

23-
if(response.ok) {
24-
const submitButton = e.target.querySelector('input[type="submit"]');
25-
submitButton.value = submitButton.value === 'Hide' ? 'Unhide' : 'Hide';
23+
if (response.ok) {
24+
const submitButton = e.target.querySelector(
25+
'input[type="submit"]'
26+
);
27+
submitButton.value =
28+
submitButton.value === 'Hide' ? 'Unhide' : 'Hide';
2629
} else {
2730
alert('An error occurred while hiding/unhiding the reply.');
2831
}
2932
} catch (e) {
3033
console.error('There was an error:', error);
31-
alert('error while hiding reply')
34+
alert('error while hiding reply');
3235
} finally {
3336
onAsyncRequestEnded();
3437
}

public/scripts/publish.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ document.addEventListener('DOMContentLoaded', async () => {
1515
});
1616

1717
async function queryContainerStatus() {
18-
const containerId = document.getElementById('container-id').getAttribute('value');
18+
const containerId = document
19+
.getElementById('container-id')
20+
.getAttribute('value');
1921

2022
const statusDOMElement = document.getElementById('container-status');
2123
statusDOMElement.innerText = QUERYING_STATUS_TEXT;
@@ -26,7 +28,7 @@ async function queryContainerStatus() {
2628
try {
2729
let response = await fetch(`/container/status/${containerId}`);
2830

29-
if(response?.ok) {
31+
if (response?.ok) {
3032
jsonResponse = await response.json();
3133
} else {
3234
console.error(response);
@@ -44,11 +46,15 @@ async function queryContainerStatus() {
4446
break;
4547
case 'IN_PROGRESS':
4648
// Retry
47-
setTimeout(queryContainerStatus, QUERY_CONTAINER_STATUS_TIMEOUT_IN_SECONDS * 1000);
49+
setTimeout(
50+
queryContainerStatus,
51+
QUERY_CONTAINER_STATUS_TIMEOUT_IN_SECONDS * 1000
52+
);
4853
break;
4954
case 'ERROR':
5055
default:
51-
document.getElementById('error-message').textContent = jsonResponse?.error_message ?? "Unknown error";
56+
document.getElementById('error-message').textContent =
57+
jsonResponse?.error_message ?? 'Unknown error';
5258
break;
5359
}
5460

@@ -58,9 +64,12 @@ async function queryContainerStatus() {
5864
function updateView(statusDOMElement, status) {
5965
statusDOMElement.innerText = status;
6066

61-
const explanationTemplate = document.getElementById(`template-status-${status}`);
67+
const explanationTemplate = document.getElementById(
68+
`template-status-${status}`
69+
);
6270
if (explanationTemplate) {
63-
const explanationParentDOMElement = document.getElementById('status-explanation');
71+
const explanationParentDOMElement =
72+
document.getElementById('status-explanation');
6473
if (explanationParentDOMElement) {
6574
const explanationNode = explanationTemplate.content.cloneNode(true);
6675
explanationParentDOMElement.replaceChildren(explanationNode);

public/scripts/upload.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,12 @@ async function updateMediaType(attachmentsCount, attachmentListElem) {
1111
let mediaTypeDesc;
1212
if (attachmentsCount === 0) {
1313
mediaTypeDesc = 'Text 📝';
14-
}
15-
else if (attachmentsCount === 1) {
16-
const singleAttachmentType = attachmentListElem.querySelector('select').value;
17-
if (singleAttachmentType === 'Image')
18-
mediaTypeDesc = 'Image 🖼️';
19-
else
20-
mediaTypeDesc = 'Video 🎬';
21-
}
22-
else {
14+
} else if (attachmentsCount === 1) {
15+
const singleAttachmentType =
16+
attachmentListElem.querySelector('select').value;
17+
if (singleAttachmentType === 'Image') mediaTypeDesc = 'Image 🖼️';
18+
else mediaTypeDesc = 'Video 🎬';
19+
} else {
2320
mediaTypeDesc = 'Carousel 🎠';
2421
}
2522

@@ -45,12 +42,18 @@ document.addEventListener('DOMContentLoaded', async () => {
4542
const parentDiv = e.target.parentNode.parentNode;
4643
parentDiv.remove();
4744

48-
await updateMediaType(attachmentsList.children.length, attachmentsList);
45+
await updateMediaType(
46+
attachmentsList.children.length,
47+
attachmentsList
48+
);
4949
});
5050

5151
const mediaTypeSelectElem = div.querySelector('select');
5252
mediaTypeSelectElem.addEventListener('change', async (e) => {
53-
await updateMediaType(attachmentsList.children.length, attachmentsList);
53+
await updateMediaType(
54+
attachmentsList.children.length,
55+
attachmentsList
56+
);
5457
});
5558

5659
await updateMediaType(attachmentsList.children.length, attachmentsList);
@@ -62,12 +65,13 @@ document.addEventListener('DOMContentLoaded', async () => {
6265
attachPollButton.addEventListener('click', async (e) => {
6366
e.preventDefault();
6467

65-
const pollAttachmentOptions = document.getElementById('poll-attachment-options');
68+
const pollAttachmentOptions = document.getElementById(
69+
'poll-attachment-options'
70+
);
6671
if (pollAttachmentOptions.style.display === 'none') {
6772
pollAttachmentOptions.style.display = 'block';
6873
} else {
6974
pollAttachmentOptions.style.display = 'none';
7075
}
71-
7276
});
7377
});

0 commit comments

Comments
 (0)