Created
September 7, 2016 10:45
-
-
Save JoeNoPhoto/dd60a43fb7b95ef0c5aea23626e0c389 to your computer and use it in GitHub Desktop.
action and API index.js files for Loading Gallery DATA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { normalize } from 'normalizr'; | |
import * as schema from './schema'; | |
import * as api from '../api'; | |
import { getIsGalleryLoading } from '../reducers'; | |
// ignore this. I doing console.logs from within my action just to see what kind of data would come from it. | |
// api.galleryDB.galleries.map(gallery => gallery.name)); | |
// ["Music", "People", "Performers", "World", "BLK", "Design"] | |
export const loadGalleryData = (gallery) => (dispatch, getState) => { | |
if (getIsGalleryLoading(getState(), gallery)) { | |
return; | |
} | |
dispatch({ | |
type: 'LOAD_GALLERY_DATA_REQUEST', | |
gallery, | |
}); | |
return api.loadGalleryData(gallery).then( | |
response => { | |
dispatch({ | |
type: 'LOAD_GALLERY_DATA_SUCCESS', | |
gallery, | |
response, | |
}); | |
}, | |
error => { | |
dispatch({ | |
type: 'LOAD_GALLERY_DATA_FAILURE', | |
gallery, | |
message: error.message || 'Something dun goofed.', | |
}); | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios from 'axios'; | |
const ROOT_URL = 'https://api.flickr.com/services/rest/?api_key=762ef5752888e4728101a359a26cc0e9&user_id=16196444@N00'; | |
export const getGalleryFromFlickr = (gallery) => | |
axios.get(ROOT_URL, { | |
params: { | |
api_key: '762ef5752888e4728101a359a26cc0e9', | |
user_id: '16196444@N00', | |
format: 'json', | |
method: 'flickr.photosets.getPhotos', | |
photoset_id: gallery, | |
nojsoncallback: 1, | |
extras: 'url_n,url_c,url_o', | |
}, | |
}) | |
.then(response => { | |
const responseData = response.data.photoset.photo.map(photo => ({ | |
src: photo.url_o, | |
srcset: [ | |
`${photo.url_o} 1024w`, | |
`${photo.url_c} 800w`, | |
`${photo.url_o} 500w`, | |
`${photo.url_n} 320w`, | |
], | |
thumbnail: `${photo.url_n}`, | |
thumbnailWidth: parseInt(photo.width_n, 10), | |
thumbnailHeight: parseInt(photo.height_n, 10), | |
})); | |
return responseData; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment