diff --git a/public/js/texts.js b/public/js/texts.js index a0b69e1..6fca9fd 100644 --- a/public/js/texts.js +++ b/public/js/texts.js @@ -3,17 +3,18 @@ document.addEventListener('DOMContentLoaded', () => { const form = document.getElementById('texts-form'); async function loadTexts() { - const res = await fetch('/api/texts', { + const res = await fetch('/api/texts/all', { credentials: 'same-origin', }); const texts = await res.json(); - textsList.innerHTML = texts.map(text => - '
  • ' + text.name - + '
  • ').join(''); + + ''; + }).join(''); } form.addEventListener('submit', async (e) => { diff --git a/public/js/userTexts.js b/public/js/userTexts.js new file mode 100644 index 0000000..db1503c --- /dev/null +++ b/public/js/userTexts.js @@ -0,0 +1,43 @@ +document.addEventListener('DOMContentLoaded', () => { + const textsList = document.getElementById('texts-list'); + const form = document.getElementById('texts-form'); + + async function loadTexts() { + const response = await fetch('/api/texts', { + credentials: 'same-origin', + }); + const texts = await response.json(); + textsList.innerHTML = texts.map(function (text) { + return '
  • ' + + text.name + + '
  • '; + }).join(''); + } + + form.addEventListener('submit', async (submitEvent) => { + submitEvent.preventDefault(); + const formData = new FormData(form); + const response = await fetch('/api/texts', { + method: 'POST', + credentials: 'same-origin', + body: formData, + }); + if (response.ok) { + const text = await response.json(); + const li = document.createElement('li'); + li.className = 'card'; + const link = document.createElement('a'); + link.className = 'card-link'; + link.href = '/texts/' + text.id; + link.textContent = text.name; + li.appendChild(link); + textsList.appendChild(li); + form.reset(); + } + }); + + loadTexts(); +}); diff --git a/views/templates/home.php b/views/templates/home.php index 97d3aa7..63cfbfd 100644 --- a/views/templates/home.php +++ b/views/templates/home.php @@ -11,6 +11,9 @@

    Home

    + + My texts + Today's schedule diff --git a/views/templates/userText.php b/views/templates/userText.php new file mode 100644 index 0000000..c9b568a --- /dev/null +++ b/views/templates/userText.php @@ -0,0 +1,22 @@ + + + + + + Daily Goals - Text + + + + +
    +
    +
    + + + diff --git a/views/templates/userTexts.php b/views/templates/userTexts.php new file mode 100644 index 0000000..a90ca94 --- /dev/null +++ b/views/templates/userTexts.php @@ -0,0 +1,38 @@ + + + + + + Daily Goals - My Texts + + + + +
    +
      +
      + +
      + +
      +
      +
      + + + +