docbrown/app/assets/javascripts/utilities/sendFetch.js
Mac Siri 4bc9020956 Implement comment preview feature (#223)
* Create #preview endpoint for CommentController

* Create comment preview button WIP

* Implement preview feature for reply comment W

* Style preview button CSS WIP

* Style preview button CSS WIP

* Tweak markdown toggle logic and add styling

* Update comment feature spec

* Add error handling for comment preview & fix lint

* Extract handleCommentPreview into it's own file

* Adjust functionality for comment preview [WIP]

* Modify comment preview functionality and CSS

* Adjust code style based on linter
2018-04-24 14:30:52 -04:00

80 lines
2.2 KiB
JavaScript

function sendFetch(switchStatement, body) {
switch (switchStatement) {
case 'article-preview':
return function(csrfToken) {
return window.fetch('/articles/preview', {
method: 'POST',
headers: {
'X-CSRF-Token': csrfToken,
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: body,
credentials: 'same-origin',
});
};
case 'reaction-creation':
return function(csrfToken) {
body.append('authenticity_token', csrfToken);
return window.fetch('/reactions', {
method: 'POST',
headers: {
'X-CSRF-Token': csrfToken,
},
body: body,
credentials: 'same-origin',
});
};
case 'image-upload':
return function(csrfToken) {
body.append('authenticity_token', csrfToken);
return window.fetch('/image_uploads', {
method: 'POST',
headers: {
'X-CSRF-Token': csrfToken,
},
body: body,
credentials: 'same-origin',
});
};
case 'follow-creation':
return function(csrfToken) {
body.append('authenticity_token', csrfToken);
return window.fetch('/follows', {
method: 'POST',
headers: {
'X-CSRF-Token': csrfToken,
},
body: body,
credentials: 'same-origin',
});
};
case 'comment-creation':
return function(csrfToken) {
return window.fetch('/comments', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-Token': csrfToken,
},
body: body,
credentials: 'same-origin',
});
};
case 'comment-preview':
return function(csrfToken) {
return window.fetch('/comments/preview', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-Token': csrfToken,
},
body: body,
credentials: 'same-origin',
});
};
default:
console.log('A wrong switchStatement was used.');
break;
}
}