File tree Expand file tree Collapse file tree 6 files changed +44
-31
lines changed
Expand file tree Collapse file tree 6 files changed +44
-31
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,8 @@ export function requiresAuthentication(Component) {
2020 checkAuth ( ) {
2121 getFreshToken ( ) . then ( ( ) => {
2222 this . setState ( { isLoggedIn : true } )
23- } ) . catch ( ( ) => {
23+ } ) . catch ( ( error ) => {
24+ console . log ( error )
2425 // FIXME should we include hash, search etc
2526 const redirectBackToUrl = window . location . origin + '/' + this . props . location . pathname
2627 const newLocation = ACCOUNTS_APP_LOGIN_URL + '?retUrl=' + redirectBackToUrl
Original file line number Diff line number Diff line change 11import thunk from 'redux-thunk'
22import { createStore , applyMiddleware , compose } from 'redux'
33import reducers from '../reducers'
4- import apiMiddleware from './apiMiddleware'
4+ import apiMiddleware from '../middleware /apiMiddleware'
55// import jwt from '../middleware/jwt'
66
77
Original file line number Diff line number Diff line change 11function apiMiddleware ( { dispatch, getState } ) {
22 return next => action => {
33 console . log ( dispatch )
4- console . log ( next )
4+ // console.log(next)
55 const {
66 API_CALL
77 // payload = {}
88 } = action
99 if ( ! API_CALL ) {
10- return // next(action)
10+ return next ( action )
1111 }
1212
1313 // const config = action[API_CALL]
Original file line number Diff line number Diff line change @@ -15,7 +15,10 @@ export function loadProjects(searchTerm) {
1515 api : projectService ,
1616 method : 'getProjects' ,
1717 args : { searchTerm} ,
18- success : ( ) => { console . log ( 'dispatch success action' ) } ,
18+ success : ( resp ) => {
19+ console . log ( 'dispatch success action' )
20+ console . log ( resp )
21+ } ,
1922 failure : ( ) => { console . log ( 'dispatch failure action' ) }
2023 }
2124 }
@@ -53,4 +56,4 @@ export function projectSuggestions(searchTerm) {
5356 } )
5457
5558 } )
56- }
59+ }
Original file line number Diff line number Diff line change 1+ class BaseService {
2+ constructor ( ) {
3+ this . token = null
4+ }
5+
6+ setToken ( token ) {
7+ this . token = token
8+ }
9+
10+ getToken ( ) {
11+ return this . token
12+ }
13+
14+ getOptions ( requiresAuth ) {
15+ const options = { }
16+ const myHeaders = new Headers ( )
17+ if ( requiresAuth ) {
18+ myHeaders . append ( 'Authorization' , 'Basic ' + this . token ) //TODO use constants
19+ }
20+ options . headers = myHeaders
21+ return options
22+ }
23+ }
24+
25+ export default BaseService
Original file line number Diff line number Diff line change 1- // import _ from 'lodash '
1+ import BaseService from './baseService '
22import { fetchJSON } from '../helpers'
33
4- class ProjectService {
4+ class ProjectService extends BaseService {
55 constructor ( ) {
6- this . token = null
7- // this.getProjects = getProjects.bind(this)
6+ super ( )
7+ this . getProjects = this . getProjects . bind ( this )
8+ this . getOptions = this . getOptions . bind ( this )
89 }
910
1011 requiresAuth ( methodName ) {
@@ -14,29 +15,12 @@ class ProjectService {
1415 return false
1516 }
1617
17- setToken ( token ) {
18- this . token = token
19- }
20-
21- getToken ( ) {
22- return this . token
23- }
24-
2518 getProjects ( searchTerm ) {
26- const options = this . getOptions ( )
19+ console . log ( searchTerm )
20+ const options = this . getOptions ( true )
2721 options . method = 'GET' //TODO use constants
28- return fetchJSON ( 'http://api.topcoder-dev.com/v4/projects?q=' + searchTerm , options )
29- }
30-
31- getOptions ( requiresAuth ) {
32- const options = { }
33- const myHeaders = new Headers ( )
34- if ( requiresAuth ) {
35- myHeaders . append ( 'Authorization' , 'Basic ' + this . token ) //TODO use constants
36- }
37- options . headers = myHeaders
38- return options
22+ return fetchJSON ( 'https://api.topcoder-dev.com/v3/challenges/' , options )
3923 }
4024}
4125
42- export default new ProjectService ( )
26+ export default new ProjectService ( )
You can’t perform that action at this time.
0 commit comments