Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Use this sample app to try the [Threads API](https://developers.facebook.com/doc
- **Reply Management:** Hide or unhide replies in the direct-replies view.
- **Search:** Search by keyword or topic tag. Choose Top or Recent results. Filter by date, media type, and author. See the [Search Guide](https://developers.facebook.com/documentation/threads/keyword-search) for parameters and limits.
- **Public Profiles:** Look up a public profile. Browse its posts.
- **Public Location Search:** Find a location to add to your post. View its details.
- **Post Insights:** View post metrics. Filter by date.
- **User Insights:** View account metrics. Filter by date.
- **Quotas:** View API usage. Refresh the reported counts.
Expand Down
38 changes: 22 additions & 16 deletions public/scripts/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,47 @@ async function queryContainerStatus() {

onAsyncRequestStarting();

let jsonResponse;
let status;
try {
let response = await fetch(`/container/status/${containerId}`);

if (response?.ok) {
jsonResponse = await response.json();
} else {
console.error(response);
}
} catch (e) {
console.error(e);
const response = await fetch(
`/container/status/${encodeURIComponent(containerId)}`
);
if (response.ok) ({ status } = await response.json());
} catch {
// Show the fixed status message below.
} finally {
onAsyncRequestEnded();
}

switch (jsonResponse?.status) {
const errorMessage = document.getElementById('error-message');
errorMessage.textContent = '';
switch (status) {
case 'FINISHED':
// Enable publishing
document.getElementById('submit').removeAttribute('disabled');
break;
case 'IN_PROGRESS':
// Retry
setTimeout(
queryContainerStatus,
QUERY_CONTAINER_STATUS_TIMEOUT_IN_SECONDS * 1000
);
break;
case 'ERROR':
errorMessage.textContent = 'The post could not be processed.';
break;
case 'EXPIRED':
errorMessage.textContent = 'The publishing container has expired.';
break;
case 'PUBLISHED':
errorMessage.textContent = 'This post has already been published.';
break;
default:
document.getElementById('error-message').textContent =
jsonResponse?.error_message ?? 'Unknown error';
status = 'Unknown';
errorMessage.textContent =
'Unable to check the post status. Refresh this page to try again.';
break;
}

updateView(statusDOMElement, jsonResponse?.status);
updateView(statusDOMElement, status);
}

function updateView(statusDOMElement, status) {
Expand Down
5 changes: 5 additions & 0 deletions public/scripts/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ document.addEventListener('DOMContentLoaded', async () => {

const topicTagInput = document.getElementById('topic-tag');
const linkAttachmentInput = document.getElementById('link-attachment');
const locationInput = document.getElementById('location-id');
const replyControlSelect = document.getElementById('reply-control');
const attachmentsList = document.getElementById('attachments-list');
const pollAttachmentOptions = document.getElementById(
Expand All @@ -173,6 +174,10 @@ document.addEventListener('DOMContentLoaded', async () => {

if (ghostPostCheckbox) {
ghostPostCheckbox.addEventListener('change', async () => {
if (locationInput) {
locationInput.disabled = ghostPostCheckbox.checked;
if (ghostPostCheckbox.checked) locationInput.value = '';
}
// When ghost post is checked, disable fields that are not relevant to ghost posts
if (ghostPostCheckbox.checked) {
topicTagMediaControl.style.display = 'none';
Expand Down
Loading