function addComment(post_id, endpoint, comment) {
    token = window.sessionStorage.getItem('key') || window.localStorage.getItem('key')
    options = {
        method: 'POST',
        cache: 'default',
        headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json',
            'Authorization': `Token ${token}`
        },
        body: JSON.stringify(comment)
    }
    fetch(`${endpoint}?post_id=${post_id}`, options)
        .then(resp => {
            switch(resp.status) {
                case 201:
                    commentSuccess(resp)
                    break
                default:
                    commentError()
            }
        })
}
// function to post a comment to comments endpoint
function to post a comment to comments endpoint
function to post a comment to comments endpoint
function addComment(post_id, endpoint, comment) {
    token = window.sessionStorage.getItem('key') || window.localStorage.getItem('key')
    options = {
        method: 'POST',
        cache: 'default',
        headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json',
            'Authorization': `Token ${token}`
        },
        body: JSON.stringify(comment)
    }
    fetch(`${endpoint}?post_id=${post_id}`, options)
        .then(resp => {
            switch(resp.status) {
                case 201:
                    commentSuccess(resp)
                    break
                default:
                    commentError()
            }
        })
}
function addComment ( post_id , endpoint , comment ) { token = window . sessionStorage . getItem ( 'key' ) || window . localStorage . getItem ( 'key' ) options = { method : 'POST' , cache : 'default' , headers : { 'Accept' : 'application/json' , 'Content-Type' : 'application/json' , 'Authorization' : ` ${ token } ` } , body : JSON . stringify ( comment ) } fetch ( ` ${ endpoint } ${ post_id } ` , options ) . then ( resp => { switch ( resp . status ) { case 201 : commentSuccess ( resp ) break default : commentError ( ) } } ) }
function to post a comment to comments endpoint
function to post a comment to comments endpoint