Skip to content

Commit

Permalink
adding mobile components
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewngu committed Nov 8, 2015
1 parent b25e2db commit c965297
Show file tree
Hide file tree
Showing 24 changed files with 162 additions and 62 deletions.
13 changes: 13 additions & 0 deletions scripts/actions/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,22 @@ function changeIsMobile(isMobile) {
};
}

function changeWidthAndHeight(height, width) {
return {
type: types.CHANGE_WIDTH_AND_HEIGHT,
height,
width
};
}

export function initEnvironment() {
return dispatch => {
const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
dispatch(changeIsMobile(isMobile));
dispatch(changeWidthAndHeight(window.innerHeight, window.innerWidth));

window.onresize = () => {
dispatch(changeWidthAndHeight(window.innerHeight, window.innerWidth));
}
};
}
17 changes: 0 additions & 17 deletions scripts/actions/height.js

This file was deleted.

17 changes: 17 additions & 0 deletions scripts/components/MobileNav.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React, {Component, PropTypes} from 'react';

class MobileNav extends Component {
render() {
const {playlist} = this.props;

return (
<div className='mobile-nav'>
<div className='mobile-nav-itm'>
{'Hello'}
</div>
</div>
);
}
}

export default MobileNav;
11 changes: 11 additions & 0 deletions scripts/components/MobilePlayer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React, {Component, PropTypes} from 'react';

class MobilePlayer extends Component {
render() {
return (
<div></div>
);
}
}

export default MobilePlayer;
24 changes: 24 additions & 0 deletions scripts/components/MobileSongListItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React, {Component, PropTypes} from 'react';
import {getImageUrl} from '../utils/SongUtils';

class MobileSongListItem extends Component {
render() {
const {song, user} = this.props;

return (
<div>
<img src={getImageUrl(song.artwork_url)} />
<div>
<div>
{song.title}
</div>
<div>
{user.username}
</div>
</div>
</div>
);
}
}

export default MobileSongListItem;
40 changes: 40 additions & 0 deletions scripts/components/MobileSongs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React, {Component, PropTypes} from 'react';
import {fetchSongsIfNeeded} from '../actions/playlists';
import MobileSongListItem from '../components/MobileSongListItem';

class MobileSongs extends Component {
componentWillMount() {
const {dispatch, playlist, playlists} = this.props;
if (!(playlist in playlists) || playlists[playlist].items.length === 0) {
dispatch(fetchSongsIfNeeded(playlist));
}
}

componentWillReceiveProps(nextProps) {
const {dispatch, playlist, playlists} = this.props;
if (playlist !== nextProps.playlist) {
if (!(nextProps.playlist in playlists) || playlists[nextProps.playlist].items.length === 0) {
dispatch(fetchSongsIfNeeded(nextProps.playlist));
}
}
}

renderSongsListItems() {
const {playlist, playlists, songs, users} = this.props;
return playlists[playlist].items.map(songId => {
const song = songs[songId];
const user = users[song.user_id];
return <MobileSongListItem song={song} user={user} />
});
}

render() {
return (
<div className='mobile-songs'>
{this.renderSongsListItems()}
</div>
);
}
}

export default MobileSongs;
2 changes: 1 addition & 1 deletion scripts/constants/ActionTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ export const CHANGE_ACTIVE_PLAYLIST = 'CHANGE_ACTIVE_PLAYLIST';
export const CHANGE_ACTIVE_SONG_ID = 'CHANGE_ACTIVE_SONG_ID';
export const CHANGE_ACTIVE_USER_ID = 'CHANGE_ACTIVE_USER_ID';
export const CHANGE_CURRENT_TIME = 'CHANGE_CURRENT_TIME';
export const CHANGE_HEIGHT = 'CHANGE_HEIGHT';
export const CHANGE_IS_MOBILE = 'CHANGE_IS_MOBILE';
export const CHANGE_MODAL = 'CHANGE_MODAL';
export const CHANGE_PATH = 'CHANGE_PATH';
export const CHANGE_PLAYING_SONG = 'CHANGE_PLAYING_SONG';
export const CHANGE_SELECTED_PLAYLISTS = 'CHANGE_SELECTED_PLAYLISTS';
export const CHANGE_WIDTH_AND_HEIGHT = 'CHANGE_WIDTH_AND_HEIGHT';
export const PLAY_SONG = 'PLAY_SONG';
export const RECEIVE_ACCESS_TOKEN = 'RECEIVE_ACCESS_TOKEN';
export const RECEIVE_AUTHED_FOLLOWINGS = 'RECEIVE_AUTHED_FOLLOWINGS';
Expand Down
15 changes: 7 additions & 8 deletions scripts/containers/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {connect} from 'react-redux';

import {initAuth} from '../actions/authed';
import {initEnvironment} from '../actions/environment';
import {initHeight} from '../actions/height';
import {initNavigator} from '../actions/navigator';

import MobileFooter from '../components/MobileFooter';
Expand All @@ -16,14 +15,11 @@ import SongContainer from '../containers/SongContainer';
import SongsContainer from '../containers/SongsContainer';
import UserContainer from '../containers/UserContainer';

import styles from '../../styles/mobile/container';

class App extends Component {
componentDidMount () {
const {dispatch} = this.props;
dispatch(initEnvironment());
dispatch(initAuth());
dispatch(initHeight());
dispatch(initNavigator());
}

Expand All @@ -47,11 +43,12 @@ class App extends Component {
}

render() {
const {isMobile} = this.props;
const {height, isMobile, width} = this.props;
if (isMobile) {
return (
<div style={styles.container}>
<ModalContainer />
<div className='mobile' style={{height: `${height}px`, width: `${width}px`}}>
{this.renderContent()}
<NavContainer />
</div>
);
}
Expand All @@ -76,8 +73,10 @@ function mapStateToProps(state) {
const {environment, navigator} = state;

return {
height: environment.height,
isMobile: environment.isMobile,
path: navigator.route.path
path: navigator.route.path,
width: environment.width
};
}

Expand Down
4 changes: 2 additions & 2 deletions scripts/containers/MeContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ class MeContainer extends Component {
}

function mapStateToProps(state) {
const {authed, entities, height, navigator, player, playlists} = state;
const {authed, entities, environment, navigator, player, playlists} = state;
const playingSongId = getPlayingSongId(player, playlists);

return {
authed,
authedPlaylists: entities.playlists,
height,
height: environment.height,
player,
playingSongId,
playlists,
Expand Down
9 changes: 8 additions & 1 deletion scripts/containers/NavContainer.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
import React, {Component, PropTypes} from 'react';
import {connect} from 'react-redux';
import MobileNav from '../components/MobileNav';
import Nav from '../components/Nav';

class NavContainer extends Component {
render() {
const {isMobile} = this.props;
if (isMobile) {
return <MobileNav {...this.props} />
}

return <Nav {...this.props} />;
}
}

function mapStateToProps(state) {
const {authed, entities, navigator} = state;
const {authed, entities, environment, navigator} = state;

return {
authed,
authedPlaylists: entities.playlists,
isMobile: environment.isMobile,
navigator,
songs: entities.songs
};
Expand Down
3 changes: 2 additions & 1 deletion scripts/containers/PlayerContainer.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import React, {Component, PropTypes} from 'react';
import {connect} from 'react-redux';
import MobilePlayer from '../components/MobilePlayer';
import Player from '../components/Player';
import {getPlayingSongId} from '../utils/PlayerUtils';

class PlayerContainer extends Component {
render() {
if (!this.props.playingSongId) {
return <div/>;
return <MobilePlayer {...this.props} />;
}

return <Player {...this.props} />;
Expand Down
4 changes: 2 additions & 2 deletions scripts/containers/SongContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ class SongContainer extends Component {
}

function mapStateToProps(state) {
const {authed, entities, height, navigator, player, playlists} = state;
const {authed, entities, environment, navigator, player, playlists} = state;
const {path, query} = navigator.route;
const songId = parseInt(path[1]);

const playingSongId = getPlayingSongId(player, playlists);

return {
authed,
height,
height: environment.height,
player,
playingSongId,
playlists,
Expand Down
11 changes: 9 additions & 2 deletions scripts/containers/SongsContainer.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import React, {Component, PropTypes} from 'react';
import {connect} from 'react-redux';
import {fetchSongsIfNeeded} from '../actions/playlists';
import MobileSongs from '../components/MobileSongs';
import Songs from '../components/Songs';

class SongsContainer extends Component {
render() {
const {isMobile} = this.props;
if (isMobile) {
return <MobileSongs {...this.props} />;
}

return <Songs {...this.props} />;
}
}

function mapStateToProps(state) {
const {authed, entities, height, navigator, player, playlists} = state;
const {authed, entities, environment, navigator, player, playlists} = state;

const playingSongId = player.currentSongIndex !== null ? playlists[player.selectedPlaylists[player.selectedPlaylists.length - 1]].items[player.currentSongIndex] : null;

Expand All @@ -23,7 +29,8 @@ function mapStateToProps(state) {

return {
authed,
height,
height: environment.height,
isMobile: environment.isMobile,
playingSongId,
playlist,
playlists,
Expand Down
4 changes: 2 additions & 2 deletions scripts/containers/UserContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ class UserContainer extends Component {
}

function mapStateToProps(state) {
const {authed, entities, height, navigator, player, playlists} = state;
const {authed, entities, environment, navigator, player, playlists} = state;
const {path, query} = navigator.route;
const userId = parseInt(path[1]);
const playingSongId = getPlayingSongId(player, playlists);

return {
authed,
height,
height: environment.height,
player,
playingSongId,
playlists,
Expand Down
11 changes: 10 additions & 1 deletion scripts/reducers/environment.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import * as types from '../constants/ActionTypes';

const initialState = {
isMobile: false
isMobile: false,
height: null,
width: null
};

export default function environment(state = initialState, action) {
Expand All @@ -10,6 +12,13 @@ export default function environment(state = initialState, action) {
return Object.assign({}, state, {
isMobile: action.isMobile
});

case types.CHANGE_WIDTH_AND_HEIGHT:
return Object.assign({}, state, {
height: action.height,
width: action.width
});

default:
return state;
}
Expand Down
10 changes: 0 additions & 10 deletions scripts/reducers/height.js

This file was deleted.

2 changes: 0 additions & 2 deletions scripts/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {combineReducers} from 'redux';
import authed from '../reducers/authed';
import entities from '../reducers/entities';
import environment from '../reducers/environment';
import height from '../reducers/height';
import modal from '../reducers/modal';
import navigator from '../reducers/navigator';
import player from '../reducers/player';
Expand All @@ -12,7 +11,6 @@ const rootReducer = combineReducers({
authed,
entities,
environment,
height,
modal,
navigator,
player,
Expand Down
7 changes: 0 additions & 7 deletions scripts/styles/container.js

This file was deleted.

1 change: 1 addition & 0 deletions styles/main.scss
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
@import 'custom/custom';
@import 'mobile/mobile';
@import 'ionicons/ionicons';
5 changes: 5 additions & 0 deletions styles/mobile/components/mobile.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.mobile {
display: flex;
flex-direction: column;
overflow: hidden;
}
Loading

0 comments on commit c965297

Please sign in to comment.