Skip to content

Commit

Permalink
#1 design form
Browse files Browse the repository at this point in the history
  • Loading branch information
moshfeu committed Nov 16, 2018
1 parent b67ce50 commit 8e5c121
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 21 deletions.
2 changes: 1 addition & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const isDev = require('electron-is-dev');
function createWindow () {
// Create the browser window.
// win = new BrowserWindow({ width: 800, height: 600 })
win = new BrowserWindow({ width: 800, height: 600, webPreferences: {
win = new BrowserWindow({ width: 1600, height: 1200, webPreferences: {
additionalArguments: [`--appData=${app.getPath('appData')}`]
} });

Expand Down
33 changes: 26 additions & 7 deletions src/components/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as React from 'react';
interface IFormProps {
onSubmit: (url: string) => void;
onClear: () => void;
hasResult: boolean;
}

interface IFormState {
Expand All @@ -11,15 +12,24 @@ interface IFormState {
}

export class Form extends React.Component<IFormProps, IFormState> {
private clear() {
constructor(props) {
super(props);

this.state = {
terms: 'https://www.youtube.com/playlist?list=PLtKALR6MChBz1gYizYPwjggc5BGAmYRRK',
containerActive: true
}
}

private clear = (): void => {
this.setState({
containerActive: false,
terms: ''
});
this.props.onClear();
}

private searchClick() {
private searchClick = (): void => {
const { onSubmit } = this.props;
const { containerActive, terms } = this.state;

Expand All @@ -30,16 +40,25 @@ export class Form extends React.Component<IFormProps, IFormState> {
}
}

render() {
private onSubmit = (e: React.FormEvent): void => {
const { terms } = this.state;
const { onSubmit } = this.props;
e.preventDefault();
if (terms && onSubmit) {
onSubmit(terms);
}
}

render() {
const { terms, containerActive } = this.state;
const { hasResult } = this.props;

return (
<form onSubmit={() => terms && onSubmit(terms)}>
<div className="search-wrapper">
<form onSubmit={this.onSubmit}>
<div className={['search-wrapper', containerActive && 'active' || '', hasResult && '-has-result' || ''].join(' ')}>
<div className="input-holder">
<input type="text" className="search-input" placeholder="Type to search" />
<button className="search-icon" onClick={this.searchClick}><span></span></button>
<input className="search-input" type="url" id="playlistUrl" placeholder="Type to search" value={terms} onChange={e => this.setState({terms: e.target.value})} />
<button type="button" className="search-icon" onClick={this.searchClick}><span></span></button>
</div>
<span className="close" onClick={this.clear}></span>
<div className="result-container">
Expand Down
46 changes: 35 additions & 11 deletions src/components/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { IVideoEntity, EVideoStatus } from '../types';
import { Video } from './video';
import { IVideoTask } from 'youtube-mp3-downloader';
import { installFfmpeg, isFFMpegInstalled } from '../services/ffmpeg-installer';
import { Form } from './form';

interface IMainState {
playlistUrl: string;
Expand All @@ -32,6 +33,26 @@ class Main extends React.Component<any, IMainState> {

componentDidMount() {
this.listenToDownloader();

this.setState({
videos: [
{
"id": "JvKKd32Yw2E",
"progress": 0,
"status": EVideoStatus.NOT_STARTED
},
{
"id": "tPEE9ZwTmy0",
"progress": 0,
"status": EVideoStatus.NOT_STARTED
},
{
"id": "cdwal5Kw3Fc",
"progress": 0,
"status": EVideoStatus.NOT_STARTED
}
]
})
}

private fetchVideosClick = async () => {
Expand Down Expand Up @@ -110,17 +131,20 @@ class Main extends React.Component<any, IMainState> {
return (
<div>
<div className={isFFMpegInstalled() ? '' : 'hidden'}>
<input type="url" id="playlistUrl" placeholder="playlist url" value={playlistUrl} onChange={e => this.setState({playlistUrl: e.target.value})} />
<button onClick={this.fetchVideosClick} disabled={process}>Fetch</button>
<hr />
<div>
{videos.length ?
<button onClick={this.downloadAll}>Download All</button> : ''
}
{videos.map(video => (
<Video key={video.id} video={video} onVideoStartClick={this.downloadVideo} />
))}
</div>
<Form
hasResult={!!videos.length}
onSubmit={this.fetchVideosClick}
onClear={() => this.setState({videos: []})}
>
<div>
{videos.length ?
<button onClick={this.downloadAll}>Download All</button> : ''
}
{videos.map(video => (
<Video key={video.id} video={video} onVideoStartClick={this.downloadVideo} />
))}
</div>
</Form>
</div>
<div className={isFFMpegInstalled() ? 'hidden' : ''}>
ffMpeg is not install :(<br />
Expand Down
7 changes: 6 additions & 1 deletion src/styles/form.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
transform: translate(-50%, -50%);
top:50%;
left:50%;

&.-has-result {
top: 30px;
transform: translate(-50%, 0);
}
}

.search-wrapper .input-holder {
Expand Down Expand Up @@ -182,7 +187,7 @@
text-align: center;
font-family: "Open Sans", Arial, Verdana;
font-size: 14px;
display:none;
// display:none;
color:#B7B7B7;
}

Expand Down
3 changes: 2 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module.exports = {
}
},
],
exclude: /node_modules/
}
]
},
Expand All @@ -46,7 +47,7 @@ module.exports = {
sourceMapFilename: 'maps/app.[chunkhash].map.js',
path: __dirname
},
mode: 'production',
mode: 'development',
target: 'node',
plugins: [
new DefinePlugin({
Expand Down

0 comments on commit 8e5c121

Please sign in to comment.