Skip to content

Commit

Permalink
resolve #13 Display not supported URL invalid or unsupported links
Browse files Browse the repository at this point in the history
  • Loading branch information
moshfeu committed Jan 6, 2019
1 parent 1e8e8bc commit 5b706eb
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"coveralls": "jest --coverage && cat ./coverage/lcov.info | coveralls"
},
"dependencies": {
"classnames": "^2.2.6",
"downloads-folder": "^1.0.1",
"electron-is-dev": "^1.0.1",
"enzyme": "^3.7.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { observer } from 'mobx-react';
import { ipcRenderer } from '../../services/electron-adapter';
import { openAbout, openPreferences } from '../../services/modals';
import { openAbout, openPreferences } from '../../services/modalsAndAlerts';

@observer
export class ElectronEventsListener extends React.Component {
Expand Down
7 changes: 6 additions & 1 deletion src/components/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import { InstallFFMpeg } from './install-ffmpeg';
import { AboutModal } from './about-modal';
import { PreferencesModal } from './preferences-modal/preferences-modal';
import { ElectronEventsListener } from './electron-events-listener';
import { closeModal} from '../services/modals';
import { closeModal} from '../services/modalsAndAlerts';
import { Message } from 'semantic-ui-react';
import * as classNames from 'classNames';

@observer
class Main extends React.Component<{}, {}> {
Expand Down Expand Up @@ -63,6 +65,9 @@ class Main extends React.Component<{}, {}> {
}
<AboutModal open={store.isAboutOpen} onClose={closeModal} />
<PreferencesModal open={store.isPreferencesOpen} onClose={closeModal} />
<div className={classNames('errors', {'-has-errors': store.termsIsInvalid})}>
<Message color="red" compact>Can't find media (url is not supported or invalid)</Message>
</div>
</div>
);
}
Expand Down
6 changes: 6 additions & 0 deletions src/mobx/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { IVideoEntity, EVideoStatus } from '../types';
import { fetchVideos } from '../services/api';
import { IVideoTask } from 'youtube-mp3-downloader';
import { isFFMpegInstalled } from '../services/ffmpeg-installer';
import { showTermsIsInvalid } from '../services/modalsAndAlerts';

class Store {
@observable searchTerm: string;
Expand All @@ -11,6 +12,7 @@ class Store {
@observable isFFMpegInstalled: boolean;
@observable isAboutOpen: boolean;
@observable isPreferencesOpen: boolean;
@observable termsIsInvalid: boolean;

constructor() {
this.isFFMpegInstalled = isFFMpegInstalled();
Expand All @@ -19,7 +21,11 @@ class Store {
@action search = async (term: string): Promise<void> => {
this.searchTerm = term;
this.searchInProgress = true;
this.termsIsInvalid = false;
this.videos = await fetchVideos(this.searchTerm);
if (!this.videos.length) {
showTermsIsInvalid();
}
this.searchInProgress = false;
}

Expand Down
3 changes: 3 additions & 0 deletions src/services/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export function setFfmpegPath() {
export function fetchVideos(term: string): Promise<IVideoEntity[]> {
try {
const parsedTerm = urlParser.parse(term);
if (!parsedTerm) {
return Promise.resolve([]);
}
if (parsedTerm.list) {
return fetchVideosFromList(term);
}
Expand Down
7 changes: 7 additions & 0 deletions src/services/modals.ts → src/services/modalsAndAlerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,11 @@ export function closeModal() {
store.isPreferencesOpen = false;
break;``
}
}

export function showTermsIsInvalid() {
store.termsIsInvalid = true;
setTimeout(() => {
store.termsIsInvalid = false;
}, 3000);
}
14 changes: 14 additions & 0 deletions src/styles/components/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,18 @@
.videos {
margin-top: 10px;
}

.errors {
position: fixed;
opacity: 0;
width: 100%;
text-align: center;
transition: opacity .3s ease;
bottom: 10px;

&.-has-errors {
pointer-events: none;
opacity: 1;
}
}
}

0 comments on commit 5b706eb

Please sign in to comment.