giphy project#75
Conversation
add functionality to add favorites
parameter that supports language is added
modified initial state
| // UI | ||
| import UI from './Gifs.ui'; | ||
|
|
||
| class Search extends Component { |
There was a problem hiding this comment.
I'm not sure why are you using two components to map one container. You could just use one component and one container.
|
|
||
| import UI from './Search.ui'; | ||
|
|
||
| class Search extends Component { |
There was a problem hiding this comment.
Same thing, why are you using two components and one container? I still believe that you could just use one :).
| // UI | ||
| import UI from './SearchResult.ui'; | ||
|
|
||
| class SearchResult extends Component { |
| const { add } = action; | ||
| const favoriteList = [...newState, add]; | ||
|
|
||
| localStorage.setItem('favorites', JSON.stringify(favoriteList)); |
There was a problem hiding this comment.
this are side effects and should be done by a sagas rather than a reducer.
| ...state.slice(i + 1) | ||
| ]; | ||
|
|
||
| localStorage.setItem('favorites', JSON.stringify(deleteFavorite)); |
| import gif from './getAllTrendingGifs'; | ||
| import searchGif from './searchGif'; | ||
| import favorites from './favorites'; | ||
| // import GifFilter from './GifFilter'; |
| export function* watchGetAllTrendingGif() { | ||
| try { | ||
| const options = { | ||
| url: 'http://api.giphy.com/v1/gifs/trending?limit=25&offset=50&rating=g&api_key=8lCcODDfELugUIKA3mCMdGbp1UBdtx15&lang=es' |
There was a problem hiding this comment.
use a .env for api keys, for security
| export function* searchGifs(res) { | ||
| try { | ||
| const options = { | ||
| url: `http://api.giphy.com/v1/gifs/search?q=${res.result}&api_key=8lCcODDfELugUIKA3mCMdGbp1UBdtx15&limit=5&lang=es` |
| @@ -2,7 +2,5 @@ import React from 'react'; | |||
| import ReactDOM from 'react-dom'; | |||
| import './index.css'; | |||
| import { Provider } from 'react-redux'; | ||
| import { BrowserRouter as Router, Route, Switch, Redirect } from 'react-router-dom'; | ||
|
|
||
| import './App.css'; |
| </div> | ||
| <Provider store={store}> | ||
| <Router> | ||
| <Switch> |
| <Router> | ||
| <Switch> | ||
| <Route exact path="/" component={Gifs} /> | ||
| <Route exact path="/search/:q" component={SearchResult} /> |
| <Route exact path="/search/:q" component={SearchResult} /> | ||
| <Route path="/favorites" component={Favorites} /> | ||
| <Route path="*" component={NotFound} /> | ||
| <Redirect to="not-found"/> |
| <div> | ||
| <h5>Pagina no encontrada.</h5> | ||
| <div> | ||
| <Link to="/">Regresar a inicio.</Link> |
Robfz
left a comment
There was a problem hiding this comment.
Some general feedback, looks good so far. Also, consider adding new lines at the end of files.
| export const DELETE_FAVORITES = 'DELETE_FAVORITES'; | ||
| export const FILTER_FAVORITES = 'FILTER_FAVORITES'; | ||
|
|
||
| function action(type, payload = {}) { |
There was a problem hiding this comment.
Really liked your approach to the payload definition, and the fact that you are giving a default value to it. I also like the way you are wrapping the payload inside an object 👍
| export default connect(mapStateToProps, { | ||
| deleteFav, | ||
| getFavorites, | ||
| filterFavorites, |
| // actions | ||
| import { add, getFavorites, deleteFav } from "./../../actions"; | ||
|
|
||
| class Gifs extends Component { |
There was a problem hiding this comment.
I think this could be a functional component.
| import Search from './../Search/Search'; | ||
| import Menu from './../Sidebar/Sidebar'; | ||
|
|
||
| class SearchResult extends Component { |
There was a problem hiding this comment.
This component could also be a functional one.
| const gif = (state = {}, action) => { | ||
| switch (action.type) { | ||
| case actions.FILTER_FAVORITES: | ||
| const newObj = { ...action } |
There was a problem hiding this comment.
Try to give some meaningful names to variables. This could be named newState.
| @@ -0,0 +1,22 @@ | |||
| import * as actions from "../actions"; | |||
| const favorite = { | |||
| add: [], | |||
| switch (action.type) { | ||
| case actions.SEARCH_RESULT: | ||
| return action.result; | ||
| case actions.SEARCH_EVENT: |
There was a problem hiding this comment.
You can write these cases like:
case actions.SEARCH_RESULT:
case actions.SEARCH_EVENT:
return action.result;
| import * as actions from '../actions'; | ||
|
|
||
| export function* watchFavorites() { | ||
| const storage = JSON.parse(localStorage.getItem('favorites')); |
There was a problem hiding this comment.
Great! These side effects are perfectly encapsulated in Sagas.
| const resultSearch = yield call(ajax, options); | ||
| yield put(actions.searchResult(resultSearch)); | ||
| } catch (error) { | ||
| yield put({ type: actions.GET_TRENDING_GIF_FAILED, error }); |
No description provided.