Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ gem "sdoc", group: :doc
# Use Rails Html Sanitizer for HTML sanitization
gem "rails-html-sanitizer"

gem "react_on_rails", "~> 6"
gem "react_on_rails", "~> 6.1"

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# mini_racer is probably faster than therubyracer
Expand Down
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ GEM
ffi (>= 0.5.0)
rdoc (4.2.2)
json (~> 1.4)
react_on_rails (6.0.5)
react_on_rails (6.1.0)
addressable
connection_pool
execjs (~> 2.5)
Expand Down Expand Up @@ -336,7 +336,7 @@ DEPENDENCIES
rails-html-sanitizer
rails_12factor
rainbow
react_on_rails (~> 6)
react_on_rails (~> 6.1)
rspec-rails (= 3.5.0.beta3)
rspec-retry
rubocop
Expand All @@ -355,4 +355,4 @@ RUBY VERSION
ruby 2.3.1p112

BUNDLED WITH
1.12.3
1.12.5
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react';
import Immutable from 'immutable';
import request from 'axios';
import _ from 'lodash';
import fetch from 'isomorphic-fetch';

import BaseComponent from 'libs/components/BaseComponent';
import metaTagsManager from 'libs/metaTagsManager';
import ror from 'libs/ror';

import CommentForm from '../CommentBox/CommentForm/CommentForm';
import CommentList from '../CommentBox/CommentList/CommentList';
Expand All @@ -29,8 +29,10 @@ export default class SimpleCommentScreen extends BaseComponent {

fetchComments() {
return (
request
.get('comments.json', { responseType: 'json' })
fetch('comments.json')
.then(res => ror.checkStatus(res))
.then(res => res.json())
.then(res => ({ data: res }))
.then(res => this.setState({ $$comments: Immutable.fromJS(res.data.comments) }))
.catch(error => this.setState({ fetchCommentsError: error }))
);
Expand All @@ -39,16 +41,11 @@ export default class SimpleCommentScreen extends BaseComponent {
handleCommentSubmit(comment) {
this.setState({ isSaving: true });

const requestConfig = {
responseType: 'json',
headers: {
'X-CSRF-Token': metaTagsManager.getCSRFToken(),
},
};

return (
request
.post('comments.json', { comment }, requestConfig)
fetch('comments.json', ror.makeJsonPostHeader(comment))
.then(res => ror.checkStatus(res))
.then(res => res.json())
.then(res => ({ data: res }))
.then(() => {
const { $$comments } = this.state;
const $$comment = Immutable.fromJS(comment);
Expand Down
15 changes: 0 additions & 15 deletions client/app/libs/metaTagsManager.js

This file was deleted.

29 changes: 12 additions & 17 deletions client/app/libs/requestsManager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import request from 'axios';
import metaTagsManager from './metaTagsManager';
import fetch from 'isomorphic-fetch';
import ror from './ror';

const API_URL = 'comments.json';

Expand All @@ -11,11 +11,11 @@ export default {
* @returns {Promise} - Result of ajax call.
*/
fetchEntities() {
return request({
method: 'GET',
url: API_URL,
responseType: 'json',
});
return (fetch(API_URL)
.then(res => ror.checkStatus(res))
.then(res => res.json())
.then(res => ({ data: res }))
);
},

/**
Expand All @@ -25,15 +25,10 @@ export default {
* @returns {Promise} - Result of ajax call.
*/
submitEntity(entity) {
return request({
method: 'POST',
url: API_URL,
responseType: 'json',
headers: {
'X-CSRF-Token': metaTagsManager.getCSRFToken(),
},
data: entity,
});
return (fetch(API_URL, ror.makeJsonPostHeader(entity))
.then(res => ror.checkStatus(res))
.then(res => res.json())
.then(res => ({ data: res }))
);
},

};
27 changes: 27 additions & 0 deletions client/app/libs/ror.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import ReactOnRails from 'react-on-rails';

export default {

checkStatus(res) {
debugger;
if (!(res.ok || res.status === 304)) {
const e = Error(res.statusText);
e.response = res;
throw e;
}
return res;
},

makeJsonPostHeader(entity) {
return {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
'X-CSRF-Token': ReactOnRails.authenticityToken(),
},
body: JSON.stringify(entity),
credentials: 'same-origin',
};
},
};
Loading