Skip to content

Instantly share code, notes, and snippets.

@productioncoder
productioncoder / Home.js
Last active February 28, 2019 19:44
Youtube fetch video categories
/* imports unchanged */
class Home extends React.Component {
render() {
/* ... */
}
componentDidMount() {
if (this.props.youtubeLibraryLoaded) {
this.fetchCategoriesAndMostPopularVideos();
}
@productioncoder
productioncoder / InfiniteScroll.js
Last active February 28, 2019 19:21
Infinite scroll component
import React from 'react';
import Waypoint from 'react-waypoint';
import {Loader} from 'semantic-ui-react';
import './InfiniteScroll.scss';
export function InfiniteScroll(props) {
return (
<React.Fragment>
{props.children}
<Waypoint onEnter={props.bottomReachedCallback}>
@productioncoder
productioncoder / VideoPreview.js
Last active February 14, 2019 19:03
Youtube VideoPreview with correct video duration formatting
/*...*/
import {getVideoDurationString} from '../../services/date/date-format';
export class VideoPreview extends React.Component {
render() {
/* ... */
const duration = video.contentDetails ? video.contentDetails.duration : null;
const videoDuration = getVideoDurationString(duration);
const viewAndTimeString = VideoPreview.getFormattedViewAndTime(video);
const horizontal = this.props.horizontal ? 'horizontal' : null;
@productioncoder
productioncoder / VideoPreview.js
Last active February 14, 2019 18:58
Youtube VideoPreview component with proper view count formatting
/*...*/
import {getShortNumberString} from '../../services/number/number-format';
TimeAgo.locale(en);
const timeAgo = new TimeAgo('en-US');
export class VideoPreview extends React.Component {
render() {
{/* unchanged */}
}
@productioncoder
productioncoder / Comments.js
Last active February 5, 2019 07:34
Youtube in React: wiring up AddComment, CommentsHeader and Comment component
import React from 'react';
import {CommentsHeader} from "./CommentsHeader/CommentsHeader";
import {AddComment} from "./AddComment/AddComment";
import {Comment} from "./Comment/Comment";
export class Comments extends React.Component {
render() {
return (
<div>
<CommentsHeader amountComments={this.props.amountComments}/>
@productioncoder
productioncoder / Watch.js
Last active February 1, 2019 19:59
Watch component using Grid
import React from 'react';
import './Watch.scss';
import {RelatedVideos} from '../../components/RelatedVideos/RelatedVideos';
import {Video} from '../../components/Video/Video';
export class Watch extends React.Component {
render() {
return (
<div className='watch-grid'>
<Video className='video' id='-7fuHEEmEjs' />
@productioncoder
productioncoder / SideBar.js
Last active January 29, 2019 18:42
SideBar with items
render() {
return (
<Menu borderless vertical stackable fixed='left' className='side-nav'>
<SideBarItem highlight={true} label='Home' icon='home'/>
<SideBarItem label='Trending' icon='fire'/>
<SideBarItem label='Followers' icon='spy'/>
<SideBarItem label='History' icon='history'/>
<SideBarItem label='Watch later' icon='clock'/>
<SideBarItem label='Liked videos' icon='thumbs up'/>
<SideBarItem label='Movies and Shows' icon='film'/>
@productioncoder
productioncoder / App.js
Created January 29, 2019 18:36
Youtube in React: show side bar and header in app component
import React, {Component} from 'react';
import HeaderNav from './containers/HeaderNav/HeaderNav';
import {SideBar} from './containers/SideBar/SideBar';
class App extends Component {
render() {
return (
<React.Fragment>
<HeaderNav/>
<SideBar/>
@productioncoder
productioncoder / HeaderNav.scss
Last active January 28, 2019 18:56
Styling shared across the app
@import '../../styles/shared.scss';
.ui.menu.top-menu {
border: none;
.logo {
width: $sidebar-left-width;
}
/* ... */
}
@productioncoder
productioncoder / SideBarItem.js
Last active January 25, 2019 21:06
SideBarItem for youtube-react app
import React from 'react';
import {Icon, Menu} from "semantic-ui-react";
import './SideBarItem.scss';
export function SideBarItem(props) {
// React will ignore custom boolean attributes, therefore we pass a string
// we use this attribute in our SCSS for styling
const highlight = props.highlight ? 'highlight-item' : null;
return (
<Menu.Item className={['sidebar-item', highlight].join(' ')}>