Skip to content

Instantly share code, notes, and snippets.

View ChuckkNorris's full-sized avatar

Levi ChuckkNorris

  • Credera
  • Denver, CO
View GitHub Profile
const TMDB_IMAGE_BASE_URL = (width = 300) => `https://image.tmdb.org/t/p/w${width}`;
const updateMoviePictureUrls = (movieResult, width = 300) => ({
...movieResult,
backdrop_path: `${TMDB_IMAGE_BASE_URL(width)}${movieResult.backdrop_path}`,
poster_path: `${TMDB_IMAGE_BASE_URL(width)}${movieResult.poster_path}`,
});
export const getMoviesList = (moviesResponse) => {
import React from 'react';
import {Row, Col} from 'react-bootstrap';
import MovieCard from '../movie-card/movie-card.component';
import LoaderComponent from '../../common/loader.component';
const styles = {
movieColumn: {
marginBottom: 20
}
}
@import url('https://fonts.googleapis.com/css?family=Roboto');
body {
margin: 0;
padding: 0;
font-family: 'Roboto', sans-serif;
}
import React from 'react';
import {Card, CardTitle, CardMedia} from 'material-ui';
// These are inline styles
// You can pass styles as objects using this convention
const styles = {
cardTitle: {
whiteSpace: 'nowrap',
textOverflow: 'ellipsis',
overflow: 'hidden'
import {combineReducers} from 'redux';
import { createReducer, createAsyncReducer } from '../common/redux.helpers';
import { keys as movieActionKeys } from './movie-browser.actions';
// Placeholder reducer for our movie modal
const movieModalReducer = createReducer({ isOpen: false }, {
});
// This will create a new state with both the existing
import {createAsyncActionCreator} from '../common/redux.helpers';
import * as movieService from './movie-browser.service';
export const keys = {
'GET_TOP_MOVIES': 'GET_TOP_MOVIES',
'SEARCH_MOVIES': 'SEARCH_MOVIES',
'GET_MOVIE_DETAILS': 'GET_MOVIE_DETAILS',
};
export const getTopMovies = (page) => createAsyncActionCreator(
@ChuckkNorris
ChuckkNorris / movie-browser.service.js
Last active April 8, 2018 06:16
Requests to the movie DB API
// WARNING: Don't check your actual API key into GitHub
const MOVIE_DB_API_KEY = 'MY_API_KEY_HERE';
const MOVIE_DB_BASE_URL = 'https://api.themoviedb.org/3';
const createMovieDbUrl = (relativeUrl, queryParams) => {
let baseUrl = `${MOVIE_DB_BASE_URL}${relativeUrl}?api_key=${MOVIE_DB_API_KEY}&language=en-US`;
if (queryParams) {
Object.keys(queryParams)
.forEach(paramName => baseUrl += `&${paramName}=${queryParams[paramName]}`);
}
@ChuckkNorris
ChuckkNorris / redux.helpers.js
Last active April 22, 2018 00:10
Async action/reducer helper
// Helper function to enables passing an object with
// the action.type as the key and the reducer function as the value
export const createReducer = (initialState = {}, actionHandlerKeyFuncs = {}) => {
return (state = initialState, action) => {
const actionHandler = actionHandlerKeyFuncs[action.type];
return actionHandler ? actionHandler(state, action) : state;
}
};
// Creates a basic action
import {combineReducers} from 'redux';
import { createReducer } from '../common/redux.helpers';
const movieModalReducer = createReducer({ isOpen: false }, {
});
const movieBrowserReducer = combineReducers({
movieModal: movieModalReducer
});
// Helper function to enables passing an object with
// the action.type as the key and the reducer function as the value
export const createReducer = (initialState = {}, actionHandlerKeyFuncs = {}) => {
return (state = initialState, action) => {
const actionHandler = actionHandlerKeyFuncs[action.type];
return actionHandler ? actionHandler(state, action) : state;
}
};