Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="root">
	
</div>
              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Raleway:400,700,600);
@import url(https://fonts.googleapis.com/css?family=Anonymous+Pro);

* {
	margin: 0;
	padding: 0;
	box-sizing: border-box;
}

#root {
	max-width: 1000px;
	margin: 0 auto;
}

a {
	color: #fff;
	&:hover {
		text-decoration: none;
		color:pink;
	}
}

body {
	background: #fff;
	color: #fff;
	font-family: 'Anonymous Pro', ;
	font-size: 17px;
}

.streamer {
	background-color: #5f5f5f;
	border-bottom: 1px solid #333;
  padding: 5px 0;
	&-logo {
		width: 50px;
		height: 50px;
	}
	&-desc {
		font-size: 14px;
		text-align: center;
	}
}

.search-bar {
	border: 1px solid #cacaca;
}

.author {
	color: #333;
  text-align: center;
  padding: 20px 0;
	a {
		color: #1583cc;
    font-weight: 600;
	}
}

@media all and (max-width: 30em) {
	.streamer-desc {
		text-align: right;
	}
}
              
            
!

JS

              
                class App extends React.Component {
	constructor(props) {
		super(props);
		
		this.filterStreamers = this.filterStreamers.bind(this);
		this.constructPayload = this.constructPayload.bind(this);
		this.getStreamerFullData = this.getStreamerFullData.bind(this);
		
		this.state = {
			streamers: this.getDefaultStreamers(),
			filteredPayloads: [],
			allPayloads: []
		};
	}
	
	getDefaultStreamers() {
		return [
			"freecodecamp",
			"storbeck",
			"terakilobyte",
			"habathcx",
			"RobotCaleb",
			"thomasballinger",
			"noobs2ninjas",
			"beohoff",
			"ESL_SC2"
		]
	}
	
	getStreamData(streamer) {
		return axios.get('https://api.twitch.tv/kraken/streams/' + streamer);
	}
	
	getChannelData(streamer) {
		return axios.get('https://api.twitch.tv/kraken/channels/' + streamer);

	}
	
  constructPayload(data) {
		const { streamData, channelData } = data;
		let logoURL,
				userURL,
				user,
				game,
				gameDesc;
		if(streamData.stream) {
			game = channelData.game;
			gameDesc = channelData.status ? channelData.status : '';
		}
		if(streamData.stream === null) {
			game = 'Offline';
		}
		
		logoURL = channelData.logo !== null ? channelData.logo : 'https://bit.ly/1RW3f6h';
		userURL = channelData.url;
		user = channelData.name || streamer;
		return {
			user,
			userURL,
			logoURL,
			game,
			gameDesc
		};
	}

	getStreamerFullData(streamer) {
		return axios.all([
			this.getStreamData(streamer), 
			this.getChannelData(streamer)
		])
			.then(axios.spread((stream, channel) => {
				return {
          streamData: stream.data,
          channelData: channel.data
        }
			}))
			.then((data) => this.constructPayload(data))
			.then((payload) => {
				this.setState({
					allPayloads: [...this.state.allPayloads, payload],
					filteredPayloads: [...this.state.filteredPayloads, payload]
				})
			});
	}
	
	filterStreamers(event) {
		
		const filtered = this.state.streamers
		.map((item) => item.toLowerCase())
		.filter((item) => {
      return item.search(event.target.value.toLowerCase()) !== -1;
    });
		
		const filteredPayloads = this.state.allPayloads.filter((payload) => {
			return filtered.indexOf(payload.user.toLowerCase()) !== -1;
		});
		
		this.setState({
			filteredPayloads
		});
	}
	
	render() {
		console.log(
			`filtered payloads contains 
       ${this.state.filteredPayloads.length} items: `, 
			this.state.filteredPayloads
		);
		return (
			<div>
				<SearchBar 
					filterStreamers={this.filterStreamers} 
				/>
		  	<FilteredList 
					payloads={this.state.filteredPayloads} 
				/>
				<Footer />
			</div>	
		)
	}
	
	componentDidMount() {
		this.state.streamers.forEach((streamer) => {
			this.getStreamerFullData(streamer);
		});
	}
}

const SearchBar = (props) => {
	return(
		<div className="row small-collapse">
			<div className="small-12 columns">
				<input 
					className="search-bar" 
					onChange={props.filterStreamers} 
					type='search' 
					placeholder="Search for streamers" 
				/>
			</div>
		</div>
	)
}

const FilteredList = (props) => {
	return (
		<div className="visible-streamers">
			{ props.payloads.map((payload, i) => {
					return <Streamer 
									 key={i} 
									 payload={payload} 
									/> 
			            })
			}
		</div>
	)
}

const Streamer = ({ payload }) => {
  const { user, game, gameDesc, logoURL, userURL } = payload;
	return (
		<div className="streamer">
			<div className="row">
				<div className="small-2 columns">
					<img src={logoURL} className="streamer-logo" />
				</div>
				<div className="small-2 columns">
					<div className="name">
						<a href={userURL} target="_blank">{user}</a>
					</div>
			  </div>
			  <div className="small-8 columns">
				  <div className="streamer-desc">
					  {game}
					  <span className="hide-for-small-only">
						  {gameDesc}
					  </span>
				  </div>
			  </div>
	    </div>
    </div>
	)
}

const Footer = () => {
	return (
		<div className="row">
			<div className="small-12 columns">
				<div className="author">
				 Made by 
					<a 
						href="https://dagman.github.io" 
						target="_blank"> dagman
					</a>
				</div>
			</div>
		</div>
	)
}

ReactDOM.render(
	<App />,
	document.querySelector('#root')
)
              
            
!
999px

Console