docbrown/app/javascript/utilities/sendFollowUser.js
Katie Davis 76453b41fb
Updates ESLint rules to error on default imports (#12512)
* add rule

* add named imports

* more missed files

* so many files
2021-02-02 10:24:03 -05:00

27 lines
847 B
JavaScript

export function sendFollowUser(user, successCb) {
const csrfToken = document.querySelector("meta[name='csrf-token']").content;
const formData = new FormData();
formData.append('followable_type', 'User');
formData.append('followable_id', user.id);
formData.append('verb', user.following ? 'unfollow' : 'follow');
fetch('/follows', {
method: 'POST',
headers: {
'X-CSRF-Token': csrfToken,
},
body: formData,
credentials: 'same-origin',
})
.then((response) => response.json())
.then((json) => {
successCb(json.outcome);
// json is followed or unfollowed
})
.catch((error) => {
// TODO: Add client-side error tracking. See https://github.com/thepracticaldev/dev.to/issues/2501
// for the discussion.
console.log(error); // eslint-disable-line no-console
});
}