<commit_before>
import React, { PropTypes } from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import { Link } from 'react-router'
import FontAwesome from 'react-fontawesome'

import Header from '../../components/Header'
import List from '../../components/List'
import TrackList from '../../components/TrackList'
import GridItem from '../../components/GridItem'

import * as helpers from '../../helpers'
import * as mopidyActions from '../../services/mopidy/actions'
import * as spotifyActions from '../../services/spotify/actions'

class LibraryBrowse extends React.Component{

	constructor(props) {
		super(props);
	}

	// on render
	componentDidMount(){
		this.loadDirectory()
	}

	componentWillReceiveProps( nextProps ){

		// mopidy goes online
		if (!this.props.mopidy_connected && nextProps.mopidy_connected ){
			this.loadDirectory( nextProps );
		}

		// our uri changes
		if (nextProps.params.uri != this.props.params.uri){
			this.loadDirectory( nextProps );
		}
	}

	loadDirectory( props = this.props ){
		if (props.mopidy_connected){
			var uri = null
			if (typeof(props.params.uri) !== 'undefined'){
				uri = props.params.uri.replace('|','?')
			}
			this.props.mopidyActions.getDirectory(uri)
		}
	}

	arrange_directory( directory ){
		var folders = []
		var tracks = []

		for (var i = 0; i < directory.length; i++) {
			if (directory[i].type && directory[i].type == 'track') {
				tracks.push( directory[i] )
			} else {
				folders.push(Object.assign(
					{},
					directory[i],
					{
						uri: encodeURIComponent(directory[i].uri)
					}
				))
			}
		}

		return {
			folders: folders,
			tracks: tracks
		}
	}

	render(){
	}

	render(){
		if (typeof(this.props.params.uri) !== 'undefined' && this.props.params.uri){
			
			var options = null
			if (this.props.params.uri != 'local:directory' ){
				options = (
					<button onClick={ () => window.history.back() }>
						<FontAwesome name="reply" />&nbsp;
						Back
					</button>
				)
			}

			if (!this.props.directory || helpers.isLoading(this.props.load_queue,['mopidy_browse'])){
				return (
					<div className="view library-local-view">
						<Header icon="music" title="Browse" options={options} uiActions={this.props.uiActions} />
						<div className="body-loader">
							<div className="loader"></div>
						</div>
					</div>
				)
			}

			var items = this.arrange_directory( this.props.directory )

			return (
				<div className="view library-local-view">
					<Header icon="music" title={this.props.params.uri} options={options} uiActions={this.props.uiActions} />
					<section className="content-wrapper">
						<List
							columns={[{ name: 'name', width: '100'}]} 
							rows={items.folders} 
							className="library-local-directory-list"
							link_prefix={global.baseURL+"library/browse/"} />
						<TrackList 
							tracks={items.tracks} 
							className="library-local-track-list" 
							noheader />
					</section>
				</div>
			);

		} else {				

			var grid_items = [
				{
					name: 'Local artists',
					link: global.baseURL+'library/browse/local-artists',
					icons: ['assets/backgrounds/browse-artists.jpg']
				},
				{
					name: 'Local albums',
					link: global.baseURL+'library/browse/local-albums',
					icons: ['assets/backgrounds/browse-albums.jpg']
				}
			]

			if (this.props.directory){
				for (var i = 0; i < this.props.directory.length; i++){
					var directory = this.props.directory[i]

					switch (directory.name){
						case 'Files':
							directory.icons = ['assets/backgrounds/browse-folders.jpg']
							break

						case 'Local media':
							directory.icons = ['assets/backgrounds/browse-folders.jpg']
							break

						case 'Spotify':
						case 'Spotify browse':
							directory.icons = ['assets/backgrounds/browse-spotify.jpg']
							break

						case 'Spotify tunigo':
						case 'Tunigo':
							directory.icons = ['assets/backgrounds/browse-tunigo.jpg']
							break

						case 'Tunein':
							directory.icons = ['assets/backgrounds/browse-tunein.jpg']
							break

						default:
							directory.icons = ['assets/backgrounds/browse-default.jpg']
					}

					grid_items.push({
						name: directory.name,
						link: global.baseURL+'library/browse/'+encodeURIComponent(directory.uri),
						icons: directory.icons
					})
				}
			}

			return (
				<div className="view library-local-view">
					<Header icon="folder" title="Browse" />
					<section className="content-wrapper">
						<div className="grid category-grid">				
							{
								grid_items.map(
									(item, index) => {
										return <GridItem item={item} key={index} link={item.link} />
									}
								)
							}
						</div>
					</section>
				</div>
			);
		}
	}
}

const mapStateToProps = (state, ownProps) => {
	return {
		load_queue: state.ui.load_queue,
		mopidy_connected: state.mopidy.connected,
		directory: state.mopidy.directory
	}
}

const mapDispatchToProps = (dispatch) => {
	return {
		mopidyActions: bindActionCreators(mopidyActions, dispatch),
		spotifyActions: bindActionCreators(spotifyActions, dispatch)
	}
}

export default connect(mapStateToProps, mapDispatchToProps)(LibraryBrowse)<commit_msg>Default images<commit_after>
import React, { PropTypes } from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import { Link } from 'react-router'
import FontAwesome from 'react-fontawesome'

import Header from '../../components/Header'
import List from '../../components/List'
import TrackList from '../../components/TrackList'
import GridItem from '../../components/GridItem'

import * as helpers from '../../helpers'
import * as mopidyActions from '../../services/mopidy/actions'
import * as spotifyActions from '../../services/spotify/actions'

class LibraryBrowse extends React.Component{

	constructor(props) {
		super(props);
	}

	// on render
	componentDidMount(){
		this.loadDirectory()
	}

	componentWillReceiveProps( nextProps ){

		// mopidy goes online
		if (!this.props.mopidy_connected && nextProps.mopidy_connected ){
			this.loadDirectory( nextProps );
		}

		// our uri changes
		if (nextProps.params.uri != this.props.params.uri){
			this.loadDirectory( nextProps );
		}
	}

	loadDirectory( props = this.props ){
		if (props.mopidy_connected){
			var uri = null
			if (typeof(props.params.uri) !== 'undefined'){
				uri = props.params.uri.replace('|','?')
			}
			this.props.mopidyActions.getDirectory(uri)
		}
	}

	arrange_directory( directory ){
		var folders = []
		var tracks = []

		for (var i = 0; i < directory.length; i++) {
			if (directory[i].type && directory[i].type == 'track') {
				tracks.push( directory[i] )
			} else {
				folders.push(Object.assign(
					{},
					directory[i],
					{
						uri: encodeURIComponent(directory[i].uri)
					}
				))
			}
		}

		return {
			folders: folders,
			tracks: tracks
		}
	}

	render(){
	}

	render(){
		if (typeof(this.props.params.uri) !== 'undefined' && this.props.params.uri){
			
			var options = null
			if (this.props.params.uri != 'local:directory' ){
				options = (
					<button onClick={ () => window.history.back() }>
						<FontAwesome name="reply" />&nbsp;
						Back
					</button>
				)
			}

			if (!this.props.directory || helpers.isLoading(this.props.load_queue,['mopidy_browse'])){
				return (
					<div className="view library-local-view">
						<Header icon="music" title="Browse" options={options} uiActions={this.props.uiActions} />
						<div className="body-loader">
							<div className="loader"></div>
						</div>
					</div>
				)
			}

			var items = this.arrange_directory( this.props.directory )

			return (
				<div className="view library-local-view">
					<Header icon="music" title={this.props.params.uri} options={options} uiActions={this.props.uiActions} />
					<section className="content-wrapper">
						<List
							columns={[{ name: 'name', width: '100'}]} 
							rows={items.folders} 
							className="library-local-directory-list"
							link_prefix={global.baseURL+"library/browse/"} />
						<TrackList 
							tracks={items.tracks} 
							className="library-local-track-list" 
							noheader />
					</section>
				</div>
			);

		} else {				

			var grid_items = [
				{
					name: 'Local artists',
					link: global.baseURL+'library/browse/local-artists',
					icons: ['assets/backgrounds/browse-artists.jpg']
				},
				{
					name: 'Local albums',
					link: global.baseURL+'library/browse/local-albums',
					icons: ['assets/backgrounds/browse-albums.jpg']
				}
			]

			if (this.props.directory){
				for (var i = 0; i < this.props.directory.length; i++){
					var directory = this.props.directory[i]

					switch (directory.name){
						case 'Files':
							directory.icons = ['assets/backgrounds/browse-folders.jpg']
							break

						case 'Local media':
							directory.icons = ['assets/backgrounds/browse-folders.jpg']
							break

						case 'Spotify':
						case 'Spotify Browse':
							directory.icons = ['assets/backgrounds/browse-spotify.jpg']
							break

						case 'Spotify Tunigo':
						case 'Tunigo':
							directory.icons = ['assets/backgrounds/browse-tunigo.jpg']
							break

						case 'TuneIn':
							directory.icons = ['assets/backgrounds/browse-tunein.jpg']
							break

						default:
							directory.icons = ['assets/backgrounds/browse-default.jpg']
					}

					grid_items.push({
						name: directory.name,
						link: global.baseURL+'library/browse/'+encodeURIComponent(directory.uri),
						icons: directory.icons
					})
				}
			}

			return (
				<div className="view library-local-view">
					<Header icon="folder" title="Browse" />
					<section className="content-wrapper">
						<div className="grid category-grid">				
							{
								grid_items.map(
									(item, index) => {
										return <GridItem item={item} key={index} link={item.link} />
									}
								)
							}
						</div>
					</section>
				</div>
			);
		}
	}
}

const mapStateToProps = (state, ownProps) => {
	return {
		load_queue: state.ui.load_queue,
		mopidy_connected: state.mopidy.connected,
		directory: state.mopidy.directory
	}
}

const mapDispatchToProps = (dispatch) => {
	return {
		mopidyActions: bindActionCreators(mopidyActions, dispatch),
		spotifyActions: bindActionCreators(spotifyActions, dispatch)
	}
}

export default connect(mapStateToProps, mapDispatchToProps)(LibraryBrowse)
{'fraction_non_alphanumeric': 0.1451150753304372, 'fraction_numerical': 0.0009242998428690267, 'mean_word_length': 2.432741116751269, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5092438', 'n_tokens_mistral': 4592, 'n_tokens_neox': 3409, 'n_words': 628}