Skip to content

Commit

Permalink
migrate everything to react (#120)
Browse files Browse the repository at this point in the history
refact(App): migrate everything to React 
BREAKING CHANGE: Remove preact and use react
  • Loading branch information
tsirlucas authored Oct 12, 2018
1 parent df01c72 commit 2bfcfdb
Show file tree
Hide file tree
Showing 34 changed files with 234 additions and 183 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Sound Place

A Preact/Redux/RxJS/redux-observable PWA where you can manage and listen to Youtube playlists and songs.
A React/Redux/RxJS/redux-observable PWA where you can manage and listen to Youtube playlists and songs.

[![Greenkeeper badge](https://badges.greenkeeper.io/tsirlucas/soundplace.svg?token=e89f78d8d624e9199c4384185ba87645ef4309023ffbaaeee1133b0183921fd6&ts=1508702348672)](https://greenkeeper.io/)
[![build status](https://travis-ci.com/tsirlucas/soundplace.svg?token=ZNhrvg7GyFkRokuwtw6s&branch=master)](https://travis-ci.com/tsirlucas/soundplace)
Expand All @@ -10,7 +10,7 @@ A Preact/Redux/RxJS/redux-observable PWA where you can manage and listen to Yout
## Features and toolbelt

- [X] [Typescript](https://www.typescriptlang.org)
- [x] [Preact](https://github.com/developit/preact) as [React](https://github.com/facebook/react) alternative
- [x] [React](https://github.com/facebook/react)
- [x] [React Router](https://github.com/ReactTraining/react-router)
- [x] [Redux](http://redux.js.org/) to manage application state
- [x] [redux-observable](https://github.com/redux-observable/redux-observable) as middleware
Expand Down
2 changes: 1 addition & 1 deletion config/loaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ export const loaders = [
},
'awesome-typescript-loader',
],
include: [path.resolve('src'), path.resolve('node_modules/preact-compat/src')],
include: [path.resolve('src')],
},
];
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
"history": "4.7.2",
"localforage": "1.5.7",
"normalize.css": "8.0.0",
"preact": "8.2.9",
"preact-compat": "3.18.2",
"preact-redux": "2.0.1",
"query-string": "5.1.1",
"raven-for-redux": "1.1.1",
"raven-js": "3.26.4",
"react": "^16.5.2",
"react-dom": "^16.5.2",
"react-redux": "^5.0.7",
"react-router-dom": "4.3.1",
"redux": "3.7.2",
"redux-act": "1.7.4",
Expand All @@ -37,6 +37,10 @@
"devDependencies": {
"@types/js-cookie": "2.1.0",
"@types/node": "10.5.8",
"@types/react": "^16.4.16",
"@types/react-dom": "^16.0.9",
"@types/react-redux": "^6.0.9",
"@types/react-router-dom": "^4.3.1",
"@types/wicg-mediasession": "1.0.2",
"awesome-typescript-loader": "5.2.0",
"babel-core": "6.26.3",
Expand Down Expand Up @@ -81,8 +85,6 @@
"webpack-manifest-plugin": "2.0.3"
},
"keywords": [
"preact",
"preact-compat",
"react",
"redux",
"sass",
Expand Down
10 changes: 5 additions & 5 deletions src/components/AppLayout/AppLayout.container.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {Component, h} from 'preact';
import {connect} from 'preact-redux';

import React, {Component} from 'react';
import {connect} from 'react-redux';
import {browserHistory} from 'src/routes/routes.config';

import {Player} from '../Player';
Expand All @@ -14,7 +13,7 @@ import {Bottombar, Networkbar, Sidebar, StatusBar, Topbar} from './components';

export type Props = MapDispatchToProps &
MapStateToProps & {
children: HTMLElement;
children: JSX.Element;
};

class AppLayoutComponent extends Component<Props, {}> {
Expand Down Expand Up @@ -53,7 +52,8 @@ class AppLayoutComponent extends Component<Props, {}> {
browserHistory.push(path);
}

render({children, hasNetwork, showPlayer, window, userActions, user, api}: Props) {
render() {
const {children, hasNetwork, showPlayer, window, userActions, user, api} = this.props;
const {width} = window;

const isDesktop = width > 765;
Expand Down
8 changes: 4 additions & 4 deletions src/components/AppLayout/components/Bottombar.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import {h} from 'preact';

import React from 'react';
import {privateRoutes} from 'src/routes/routes.config';

import {Icon} from '../../Icons/Icons';

export const Bottombar = ({changeRoute}) => (
<div className="bottom-bar">
{privateRoutes.filter((route) => route.header).map((privRoute) => (
<label className="bottom-bar-item">
{privateRoutes.filter((route) => route.header).map((privRoute, i) => (
<label className="bottom-bar-item" key={i}>
<input
type="radio"
name="tab-bar"
value={privRoute.path}
checked={location.hash.includes(privRoute.path)}
disabled={location.hash === `#${privRoute.path}`}
readOnly
onClick={() => changeRoute(privRoute.path)}
/>
<button className="bottom-bar-button">
Expand Down
4 changes: 2 additions & 2 deletions src/components/AppLayout/components/Networkbar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {h} from 'preact';
import React from 'react';

type Props = {
networkClass: string;
Expand All @@ -8,7 +8,7 @@ type Props = {

export const Networkbar = ({networkClass, width, isDesktop}: Props) => {
const parsedWidth = isDesktop ? width - 250 : width;
const style = `width: ${parsedWidth}px;`;
const style = {width: `${parsedWidth}px`};

return (
<section className={`network-bar ${networkClass}`} style={style}>
Expand Down
20 changes: 13 additions & 7 deletions src/components/AppLayout/components/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {Component, h} from 'preact';

import React, {Component} from 'react';
import {Icon} from 'components/Icons/Icons';
import {privateRoutes} from 'src/routes/routes.config';

Expand All @@ -20,7 +19,9 @@ export class Sidebar extends Component<Props, null> {
img.src = '/assets/img/avatar.jpeg';
};

render({user}: Props) {
render() {
const {user} = this.props;

return (
<aside id="sidebar">
{user && (
Expand All @@ -37,15 +38,16 @@ export class Sidebar extends Component<Props, null> {
<Icon icon="SYNC" size="24" color="white" />
</span>
) : (
<div onClick={this.props.actions.import} style="cursor:pointer;">
<div onClick={this.props.actions.import} style={{cursor: 'pointer'}}>
<Icon icon="SYNC" size="24" color="white" />
</div>
)}
</div>
)}
<Navigation>
{privateRoutes.filter((route) => route.header).map((route) => (
{privateRoutes.filter((route) => route.header).map((route, i) => (
<NavigationItem
key={i}
onClick={() => this.props.changeRoute(route.path)}
header={route.header}
icon={route.icon}
Expand All @@ -64,10 +66,14 @@ const Navigation = ({children}: {children?: JSX.Element[]}) => (
);

const NavigationItem = ({header, icon, active, onClick, disabled}) => (
<li className="brand-nav-item" style={disabled ? 'pointer-events:none;' : ''} onClick={onClick}>
<li
className="brand-nav-item"
style={disabled ? {pointerEvents: 'none'} : null}
onClick={onClick}
>
<div className="brand-nav-icon">
<Icon icon={icon} size="34" color={active ? 'white' : null} />
</div>
<span style={active ? 'color: white' : null}>{header}</span>
<span style={active ? {color: 'white'} : null}>{header}</span>
</li>
);
2 changes: 1 addition & 1 deletion src/components/AppLayout/components/Statusbar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {h} from 'preact';
import React from 'react';

type Props = {
error: string;
Expand Down
5 changes: 2 additions & 3 deletions src/components/AppLayout/components/Topbar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {Component, h} from 'preact';

import React, {Component} from 'react';
import {Icon} from 'components';

import {Props as ContainerProps} from '../AppLayout.container';
Expand All @@ -21,7 +20,7 @@ export class Topbar extends Component<Props, null> {
const {user} = this.props;

return (
<div class="top-bar">
<div className="top-bar">
{user && (
<div id="brand">
<img
Expand Down
10 changes: 3 additions & 7 deletions src/components/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import {h} from 'preact';

interface EventHandler<E extends Event> {
(event: E): void;
}
import React, {MouseEvent} from 'react';

interface Props {
href?: string;
className?: string;
onClick?: EventHandler<MouseEvent>;
children?: Element;
onClick?: (e: MouseEvent<HTMLAnchorElement>) => void;
children?: Element | string;
}

export const Button = (props: Props) => (
Expand Down
6 changes: 4 additions & 2 deletions src/components/Card.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {h} from 'preact';
import React from 'react';

export const Card = ({children}: {children: Element}) => <section className="card">{children}</section>;
export const Card = ({children}: {children: Element}) => (
<section className="card">{children}</section>
);
6 changes: 3 additions & 3 deletions src/components/CardList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {h} from 'preact';

import React from 'react';
import {Cover} from 'models';

type Item = {
Expand All @@ -19,7 +18,8 @@ type ItemProps = {

const CardList = ({items, open}: ListProps) => (
<section className="cardlist-container">
{items && Object.values(items).map((item) => <CardListItem item={item} open={open} />)}
{items &&
Object.values(items).map((item, i) => <CardListItem key={i} item={item} open={open} />)}
</section>
);

Expand Down
11 changes: 5 additions & 6 deletions src/components/Icons/Icons.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {h} from 'preact';

import React from 'react';
import {icons} from './Icons.constants';

type Props = {
Expand All @@ -25,10 +24,10 @@ export const Icon = (props: Props) => {
height={`${props.size}`}
viewBox={`0 0 24 24`}
xmlns="http://www.w3.org/2000/svg"
fill-rule="evenodd"
clip-rule="evenodd"
stroke-linejoin="round"
stroke-miterlimit="1.414"
fillRule="evenodd"
clipRule="evenodd"
strokeLinejoin="round"
strokeMiterlimit="1.414"
>
<path style={styles.path} d={icons[props.icon]} />
</svg>
Expand Down
10 changes: 5 additions & 5 deletions src/components/Player/Player.container.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {Component, h} from 'preact';
import {connect} from 'preact-redux';

import React, {Component} from 'react';
import {connect} from 'react-redux';
import {PlayerService} from 'services';

import {Icon} from '../Icons';
Expand All @@ -23,7 +22,8 @@ class PlayerComponent extends Component<Props, {}> {
PlayerService.getInstance().setPlayer(nextProps.player, nextProps.actions);
}

render({player, actions, playerClass}: Props) {
render() {
const {player, actions, playerClass} = this.props;
const hasPrevious = PlayerService.getInstance().hasPrev();
const hasNext = PlayerService.getInstance().hasNext();

Expand All @@ -39,7 +39,7 @@ class PlayerComponent extends Component<Props, {}> {
<div id="playing-details">
<div
id="playing-cover"
style={`background-image: url(${currentlyPlaying.cover.small});`}
style={{backgroundImage: `url(${currentlyPlaying.cover.small})`}}
/>
<div id="playing-data">
<div className="music">
Expand Down
8 changes: 4 additions & 4 deletions src/components/Player/Player.selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import {actions as tracksActions} from 'core/tracks';
import {RootState} from 'src/core';

type OtherProps = {
isDesktop: boolean;
scrollbarWidth: number;
width: number;
playerClass: string;
isDesktop?: boolean;
scrollbarWidth?: number;
width?: number;
playerClass?: string;
};

export const mapStateToProps = ({player}: RootState, otherProps: OtherProps) => ({
Expand Down
10 changes: 7 additions & 3 deletions src/components/Player/Progressbar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component, h} from 'preact';
import React, {Component} from 'react';

type State = {
progressPercentage: number;
Expand All @@ -10,6 +10,9 @@ type Props = {
};

export default class PlayerProgress extends Component<Props, State> {
state = {
progressPercentage: 0,
};
shouldComponentUpdate(_nextProps, nextState) {
return this.state.progressPercentage !== nextState.progressPercentage;
}
Expand All @@ -20,8 +23,9 @@ export default class PlayerProgress extends Component<Props, State> {
this.setState({progressPercentage});
}

render(_props, {progressPercentage}) {
const style = `width: ${progressPercentage || 0}%;`;
render() {
const {progressPercentage} = this.state;
const style = {width: `${progressPercentage}%`};

return <div id="player-progress-bar" style={style} />;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/PublicLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import {h} from 'preact';
import React from 'react';

export const PublicLayout = (props) => <main>{props.children}</main>;
Empty file.
Empty file.
11 changes: 6 additions & 5 deletions src/components/Tracks/Tracks.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {Component, h} from 'preact';

import React, {Component} from 'react';
import {RootState} from 'core';
import {actions as playerActions} from 'core/player';
import {actions as storageActions} from 'core/storage';
Expand Down Expand Up @@ -64,7 +63,8 @@ export class Tracks extends Component<Props, {}> {
return false;
};

render({tracks, playlist}: Props) {
render() {
const {tracks, playlist} = this.props;
if (!tracks.data || !playlist) return null;
const playlistTracks = Object.keys(tracks.playlist).map((id) => tracks.data[id]);

Expand All @@ -73,14 +73,15 @@ export class Tracks extends Component<Props, {}> {
<header className="playlist-header">
<div
className="playlist-image"
style={`background-image: url(${playlist.cover.medium})`}
style={{backgroundImage: `url(${playlist.cover.medium})`}}
/>
<h1 className="playlist-name">{playlist.name}</h1>
</header>
<main className="playlist-content">
<ul className="tracks-list">
{Object.values(playlistTracks).map((track) => (
{Object.values(playlistTracks).map((track, i) => (
<Track
key={i}
status={tracks.saved[track.id] ? tracks.saved[track.id].status : 'NOT-SAVED'}
track={track}
play={this.play}
Expand Down
Loading

0 comments on commit 2bfcfdb

Please sign in to comment.