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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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="app"></div>
              
            
!

CSS

              
                .html
  position relative
  min-height 100%
body
  margin-bottom 60px
.jumbotron
	margin-top -10px
.footer
  position absolute
  bottom 0
  width 100%
  height 60px
  background-color #f5f5f5
	
.text-footer
  margin 20px 0

.text-lastupdated
	margin-top 20px
	text-align right

.stream-icon
	margin-left 10px

.vertical-align
	display flex
	align-items center

.loading
	color #ddd
p.loading-text
	// background-color #ddd
	text-decoration solid
	text-decoration-color green
	
.gray-circle
	border-radius 50%
	background #ddd
	width 13rem
	height 13rem
              
            
!

JS

              
                const twitchApiURL = 'https://wind-bow.glitch.me/twitch-api'
const channels = shuffle(["cretetion", "freecodecamp", "habathcx", "RobotCaleb", "noobs2ninjas"]);
const Navbar = React.createClass({
	propTypes: {
		brand: React.PropTypes.string.isRequired,
	},
	getDefaultProps: function(){
		return {
			brand: "Title",
			color: "default",
		}
	},
	render: function(){
		return (
			<nav className={"navbar navbar-"+this.props.color}>
				<div className="container-fluid">
					<div className="navbar-header">
					<button type="button" className="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
						<span className="sr-only">Toggle navigation</span>
						<span className="icon-bar"></span>
						<span className="icon-bar"></span>
						<span className="icon-bar"></span>
					</button>
					<a className="navbar-brand" href="#">{ this.props.brand }</a>
			</div>
					<div className="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
						<ul className="nav navbar-nav">
							<li><a href="#">Home</a></li>
							<li><a href="#">About</a></li>
						</ul>
					</div>
				</div>
			</nav>
		)
	}
})

const Footer = React.createClass({
	getDefaultProps: function(){
		return {
			brand: "La Terminal, Inc.",
			year: 2017,
		}
	},
	render: function(){
		return(
			<footer className="footer">
				<div className="container">
					<p className="text-muted text-footer">Made with 🍣 by <a href="https://mrcrjs.github.io/" target="_blank">Marco A. Rojas</a></p>
				</div>
			</footer>
		)
	}
})

const TwitchCard = React.createClass({

	propTypes: {
		twitchUser: React.PropTypes.string.isRequired,
	},

	getInitialState: function(){
		return {
			streams: {
				stream: null
			}
		}
	},

	componentDidMount: function(){
		const apiUserUrl = twitchApiURL + '/users/' + this.props.twitchUser
		
		fetch(apiUserUrl, { method: 'GET'})
		.then(resp => resp.json())
		.then(user => {
			// console.log(user)
			const apiStreamUrl = twitchApiURL + '/streams/' + user._id
			return this.setState({ twitchUser: user, streams: Math.random() >= 0.6 })
			/* API Streams not working correctly, using a random value instead
			() => fetch(apiStreamUrl, { method: 'GET'})
				.then(resp => resp.json())
				.then(streams => {
					return this.setState({ streams })
				})
			*/
		})		
	},

	render: function(){
		if(this.state.twitchUser)
		{
			let formatedDate = new Date(this.state.twitchUser.updated_at).toISOString().substring(0, 10)
			return (
				<div className={"jumbotron"}>
					<div className={"container"}>
						<div className={"row vertical-align"}>
							<div className={"col-md-3 hidden-xs hidden-sm"}>
								<img
									src={ this.state.twitchUser.logo }
									alt={ this.state.twitchUser.display_name }
									className="img-circle img-responsive"
								/>
							</div>
							<div className={"col-md-9"}>
								<div className={"row"}>
									<div className={"col-md-12"}>
										<h3>
											<a href={ 'https://www.twitch.tv/' + this.state.twitchUser.name } target="_blank">
												{ this.state.twitchUser.display_name }
												</a>
												{ this.state.streams ? <span className="glyphicon glyphicon-fire stream-icon" style={{color: '#bd1502'}}/> : <span className="glyphicon glyphicon-fire text-muted stream-icon"/> }
										</h3>
									</div>
								</div>
								<div className={"row"}>
									<div className={"col-md-12"}>
										<p className={ "lead" }>{ this.state.twitchUser.bio }</p>
									</div>
								</div>
							</div>
						</div>
						<div className={"row"}>
							<div className={"col-md-12"}>
								<p className={"text-muted text-lastupdated"}><small>Last updated { formatedDate }</small></p>
							</div>
						</div>
					</div>
				</div>
			)
		}
		else
			return (
				<div className={"jumbotron"} >
										<div className={"container loading"}>
						<div className={"row vertical-align"}>
							<div className={"col-md-3 hidden-xs hidden-sm"}>
								<div className={"gray-circle"}/>
							</div>
							<div className={"col-md-9"}>
								<div className={"row"}>
									<div className={"col-md-12"}>
										<p>
												&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585; <span className="glyphicon glyphicon-fire stream-icon"/>
										</p>
									</div>
								</div>
								<div className={"row"}>
									<div className={"col-md-12"}>
										<p className={"loading-text"}>&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;</p>
										<p className={"loading-text"}>&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;</p>
										<p className={"loading-text"}>&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;</p>
										<p className={"loading-text"}>&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;&#x2585;</p>
									</div>
								</div>
							</div>
						</div>
						<div className={"row"}>
							<div className={"col-md-12"}>
								<p className={"text-lastupdated"}><small>Last updated 1707-15-04</small></p>
							</div>
						</div>
					</div>			
				</div>
			)
	}
})
const App = React.createClass({
	getInitialState: function(){
		return{
			currentPage: "home"
		}
	},
	
	render: function(){
		return(
			<div >
				<Navbar
					brand="Twitcher"
					activePage={ this.state.currentPage }
					color="inverse"
				/>
				<br />
				<div className="container">
					<div className="row">
						<div className="col-sm-12 col-md-8 col-md-offset-2">
							<h1>React Twitch</h1>
							<p className=" lead text-muted">This an app build for Free Code Camp using React, Bootstrap and Twitch API</p>
							<br />
							<div>
								{ channels.map(chName => <TwitchCard twitchUser={chName} />) }
							</div>
						</div>
					</div>
					<div className="row">
						<div className="col-md-8 col-md-offset-2">
						</div>
					</div>
				</div>
				<Footer brand="Made with 🍻 by Marco A. Rojas"/>
			</div>
		)
	}
})

ReactDOM.render(<App />, document.getElementById('app'));

// https://stackoverflow.com/a/2450976/3011836
function shuffle(array) {
  let currentIndex = array.length, temporaryValue, randomIndex;

  // While there remain elements to shuffle...
  while (0 !== currentIndex) {

    // Pick a remaining element...
    randomIndex = Math.floor(Math.random() * currentIndex);
    currentIndex -= 1;

    // And swap it with the current element.
    temporaryValue = array[currentIndex];
    array[currentIndex] = array[randomIndex];
    array[randomIndex] = temporaryValue;
  }

  return array;
}

              
            
!
999px

Console