~jpgleeson/caint

783e27edb813eeb7453eb160ed6bd57092692a35 — jpgleeson 1 year, 5 months ago 743c1af
Fixed javascript not loading thread on first load.
1 files changed, 3 insertions(+), 45 deletions(-)

M wwwroot/js/caint.js
M wwwroot/js/caint.js => wwwroot/js/caint.js +3 -45
@@ 1,5 1,5 @@
const uri = 'api/Comments';
const threadUri = 'api/Threads';
const uri = 'https://api.caint.casa/api/Comments';
const threadUri = 'https://api.caint.casa/api/Threads';

const threadHost = "TENANTNAMEHERE";
const threadPath = document.location.pathname;


@@ 24,22 24,13 @@ function getThreadId()
    .then(response => response.json())
    .then(_data => {
      data = _data;
      console.log(data);
      document.getElementById("threadID").value = data;
      console.log(document.getElementById("threadID").value);
      getThread(data);
      return data;
  })
    .then(getThread(document.getElementById("threadID").value))
    .catch(error => console.error('Unable to get thread id.', error));
}

function getItems() {
  fetch(uri + "/admin")
    .then(response => response.json())
    .then(data => _displayItems(data))
    .catch(error => console.error('Unable to get comments.', error));
}

function getThread(thread) {
  fetch(uri + "/thread/" + thread)
    .then(response => response.json())


@@ 102,39 93,6 @@ function approveItem(id) {
      .catch(error => console.error('Unable to approve comments.', error));
}

function displayEditForm(id) {
  const item = todos.find(item => item.id === id);
  
  document.getElementById('edit-name').value = item.name;
  document.getElementById('edit-id').value = item.id;
  document.getElementById('edit-isComplete').checked = item.isComplete;
  document.getElementById('editForm').style.display = 'block';
}

function updateItem() {
  const itemId = document.getElementById('edit-id').value;
  const item = {
    id: parseInt(itemId, 10),
    isComplete: document.getElementById('edit-isComplete').checked,
    name: document.getElementById('edit-name').value.trim()
  };

  fetch(`${uri}/${itemId}`, {
    method: 'PUT',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(item)
  })
  .then(() => getItems())
  .catch(error => console.error('Unable to update item.', error));

  closeInput();

  return false;
}

function closeInput() {
  document.getElementById('editForm').style.display = 'none';
}