diff --git a/index.html b/index.html index ae2e85d..6a97d44 100644 --- a/index.html +++ b/index.html @@ -11,7 +11,7 @@ appId : '1964785470475309', cookie : true, xfbml : true, - version : 'v2.8' + version : 'v2.9' }); FB.AppEvents.logPageView(); }; diff --git a/src/actions/pageAction.js b/src/actions/pageAction.js index 0055625..195e352 100644 --- a/src/actions/pageAction.js +++ b/src/actions/pageAction.js @@ -1,21 +1,47 @@ import { GET_PHOTOS_REQUEST, - GET_PHOTOS_SUCCESS + GET_PHOTOS_SUCCESS, + GET_PHOTOS_FAIL } from '../constants/page' -export function getPhotos(year){ - return (dispatch) => { +let photosArr =[]; + +export function getPhotos(dispatch) { + return function (dispatch){ dispatch({ - type: GET_PHOTOS_REQUEST, - payload: year + type: GET_PHOTOS_REQUEST + }); + FB.getLoginStatus(function(response) { + if (response.status === 'connected'){ + FB.api( + 'me?fields=albums{photos{source,width,height}}', + function (response) { + if (response && !response.error) { + let albums = response.albums.data.map((item) => + item.photos.data); + let albumUnidade = albums.map((item) => item.map((item) => photosArr.push(item))); + dispatch({ + type: GET_PHOTOS_SUCCESS, + payload: photosArr + }) + } else { + dispatch({ + type: GET_PHOTOS_FAIL, + error: true, + payload: new Error ('Cannot get photos') + }) + } + } + ); + } else { + dispatch({ + type: GET_PHOTOS_FAIL, + error: true, + payload: new Error ('Cannot get photos') + }) + } }); - - setTimeout(() => { - dispatch({ - type: GET_PHOTOS_SUCCESS, - payload: [1,2,3,4,5] - }) - }, 1000) - } } + + diff --git a/src/actions/userAction.js b/src/actions/userAction.js index ca52eed..fedf1be 100644 --- a/src/actions/userAction.js +++ b/src/actions/userAction.js @@ -41,10 +41,10 @@ export function handleLogout (){ dispatch({ type: LOGOUT_REQUEST }); - FB.logout(function(response) { - }); FB.getLoginStatus(function(response) { - if (response.status ='unknown'){ + if (response.status === 'connected'){ + FB.logout(function(response) { + }); username =''; dispatch({ type: LOGOUT_SUCCESS, @@ -54,7 +54,7 @@ export function handleLogout (){ dispatch({ type: LOGOUT_FAIL, error: true, - payload: new Error('Something os wrong, cannot out from app') + payload: new Error('Something is wrong, maybe you are out from app earlier') }) } }); diff --git a/src/components/page.js b/src/components/page.js index cad6ae1..0212ba6 100644 --- a/src/components/page.js +++ b/src/components/page.js @@ -1,29 +1,31 @@ import React, { PropTypes, Component } from 'react'; export default class Page extends Component { - onYearBtnClick(e) { + onBtnClick(e) { this.props.getPhotos(+e.target.innerText) } render(){ - const { year, photos, fetching } = this.props; + const { photos, fetching, error } = this.props; return (
+ +
Oops, download is failed...
: '' } { fetching ?Downloading...
: -- You have {photos.length} photos -
+ photos.map((entry, index) => +