public/javascript/edit-post.js
// create function to enable post to be edited by user
create function to enable post to be edited by user
create function to enable post to be edited by user
async function editFormHandler(event) {
    event.preventDefault();
    const title = document.querySelector('input[name="post-title"]').value;
    const post_content = document.querySelector('input[name="post-content"]').value;
    const id = window.location.toString().split('/')[
        window.location.toString().split('/').length - 1
      ];
    const response = await fetch(`/api/posts/${id}`, {
        method: 'PUT',
        body: JSON.stringify({
            title,
            post_content
        }),
        headers: {
            'Content-Type': 'application/json'
        }
      });
      if (response.ok) {
        document.location.replace('/dashboard/');
      } else {
        alert(response.statusText);
      }
  }
async function editFormHandler ( event ) { event . preventDefault ( ) ; const title = document . querySelector ( 'input[name="post-title"]' ) . value ; const post_content = document . querySelector ( 'input[name="post-content"]' ) . value ; const id = window . location . toString ( ) . split ( '/' ) [ window . location . toString ( ) . split ( '/' ) . length - 1 ] ; const response = await fetch ( ` ${ id } ` , { method : 'PUT' , body : JSON . stringify ( { title , post_content } ) , headers : { 'Content-Type' : 'application/json' } } ) ; if ( response . ok ) { document . location . replace ( '/dashboard/' ) ; } else { alert ( response . statusText ) ; } }
create function to enable post to be edited by user
create function to enable post to be edited by user