From 994b1cf9f5a4e5245a150aae34d0dfa9f803ee1b Mon Sep 17 00:00:00 2001 From: 4gray Date: Fri, 28 Aug 2020 21:42:52 +0200 Subject: [PATCH] refactor: code improvements --- api.ts | 36 +++++++++---------- package-lock.json | 36 +++++-------------- package.json | 4 +-- .../channel-list-container.component.scss | 3 ++ .../playlist-uploader.component.html | 4 +-- .../playlist-uploader.component.ts | 8 +++-- src/styles.scss | 2 +- 7 files changed, 37 insertions(+), 56 deletions(-) diff --git a/api.ts b/api.ts index 08cd1b551..c72c4eba4 100644 --- a/api.ts +++ b/api.ts @@ -3,9 +3,9 @@ import { parse } from 'iptv-playlist-parser'; import axios from 'axios'; import { guid } from '@datorama/akita'; import { Playlist } from './src/app/playlist-uploader/playlist.interface'; +import Nedb from 'nedb-promises-ts'; -const Datastore = require('nedb'); -const db = new Datastore({ filename: 'data.db', autoload: true }); +const db = new Nedb({ filename: 'data.db', autoload: true }); export class Api { constructor() { @@ -34,31 +34,27 @@ export class Api { event.sender.send('parse-response', { payload: playlistObject }); }); - ipcMain.on('playlists-all', (event, args) => { - db.find({}, { count: 1, title: 1, _id: 1 }, function ( - err, - playlists - ) { - event.sender.send('playlist-all-result', { - payload: playlists, - }); + ipcMain.on('playlists-all', async (event, args) => { + const playlists = await db.find({}, { count: 1, title: 1, _id: 1 }); + event.sender.send('playlist-all-result', { + payload: playlists, }); }); - ipcMain.on('playlist-by-id', (event, args) => { - db.findOne({ _id: args.id }, function (err, playlist) { - event.sender.send('playlist-by-id-result', { - payload: playlist, - }); + ipcMain.on('playlist-by-id', async (event, args) => { + const playlist = await db.findOne({ _id: args.id }); + event.sender.send('playlist-by-id-result', { + payload: playlist, }); }); - ipcMain.on('playlist-remove-by-id', (event, args) => { - db.remove({ _id: args.id }, function (err, playlist) { + ipcMain.on('playlist-remove-by-id', async (event, args) => { + const removed = await db.remove({ _id: args.id }); + if (removed) { event.sender.send('playlist-remove-by-id-result', { message: 'playlist was removed', }); - }); + } }); } @@ -95,8 +91,8 @@ export class Api { * @param playlist playlist to add */ insertToDb(playlist) { - db.insert(playlist, function (err, newrec) { - console.log('playlist was saved...', newrec._id); + db.insert(playlist).then((response) => { + console.log('playlist was saved...', response._id); }); } } diff --git a/package-lock.json b/package-lock.json index c0be06e6b..fc2cfd389 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7755,29 +7755,6 @@ "extract-zip": "^1.0.3" } }, - "electron-better-ipc": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/electron-better-ipc/-/electron-better-ipc-1.1.1.tgz", - "integrity": "sha512-Y8Ty54HJtzT6aWNTyE092W/7q8y3+yJz0XvRpOKGIsLDL2H7oWIFkUegmB+6h5SszjtBiQFpmNmHOKfkDZ8HbQ==", - "requires": { - "serialize-error": "^5.0.0" - }, - "dependencies": { - "serialize-error": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/serialize-error/-/serialize-error-5.0.0.tgz", - "integrity": "sha512-/VtpuyzYf82mHYTtI4QKtwHa79vAdU5OQpNPAmE/0UDdlGT0ZxHwC+J6gXkw29wwoVI8fMPsfcVHOwXtUQYYQA==", - "requires": { - "type-fest": "^0.8.0" - } - }, - "type-fest": { - "version": "0.8.1", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz", - "integrity": "sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==" - } - } - }, "electron-builder": { "version": "22.7.0", "resolved": "https://registry.npmjs.org/electron-builder/-/electron-builder-22.7.0.tgz", @@ -13398,6 +13375,14 @@ } } }, + "nedb-promises-ts": { + "version": "0.0.1-4", + "resolved": "https://registry.npmjs.org/nedb-promises-ts/-/nedb-promises-ts-0.0.1-4.tgz", + "integrity": "sha512-vEYqn9pyf7RrLiC9yfnCq/kn3I/bPH0bRwDK8tF3HqcqX9I0wrbMI12pxZbz79QZdlyOVjeYvu7JY9yl4sL0yw==", + "requires": { + "nedb": "^1.8.0" + } + }, "negotiator": { "version": "0.6.2", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz", @@ -13431,11 +13416,6 @@ } } }, - "ngx-indexed-db": { - "version": "5.0.5", - "resolved": "https://registry.npmjs.org/ngx-indexed-db/-/ngx-indexed-db-5.0.5.tgz", - "integrity": "sha512-MRqtL51HoZp9CUEaQQEQY4pjuwDJmG5/ucHfxy8LaPEyW+HOL+kvAgXKumDiUH5Q/K0WNQwoQwSxPUFnsUQrdQ==" - }, "ngx-uploader": { "version": "10.0.0", "resolved": "https://registry.npmjs.org/ngx-uploader/-/ngx-uploader-10.0.0.tgz", diff --git a/package.json b/package.json index 09ba0c5ce..44def5913 100644 --- a/package.json +++ b/package.json @@ -104,14 +104,14 @@ "@types/hls.js": "0.13.0", "axios": "0.19.2", "custom-electron-titlebar": "3.2.3", - "electron-better-ipc": "1.1.1", "hls.js": "0.14.8", "iptv-playlist-parser": "0.5.0", "lodash": "4.17.19", "material-icons": "0.3.1", "nedb": "1.8.0", + "nedb-promises-ts": "0.0.1-4", "ngx-filter-pipe": "2.1.2", "ngx-uploader": "10.0.0", "uuid": "8.3.0" } -} \ No newline at end of file +} diff --git a/src/app/channel-list-container/channel-list-container.component.scss b/src/app/channel-list-container/channel-list-container.component.scss index afa7f4d06..61fbc19f5 100644 --- a/src/app/channel-list-container/channel-list-container.component.scss +++ b/src/app/channel-list-container/channel-list-container.component.scss @@ -28,6 +28,9 @@ ::ng-deep { + .mat-tab-group { + height: 100%; + } .mat-tab-label { height: 63px !important; } diff --git a/src/app/playlist-uploader/playlist-uploader.component.html b/src/app/playlist-uploader/playlist-uploader.component.html index 2b855c678..84b328083 100644 --- a/src/app/playlist-uploader/playlist-uploader.component.html +++ b/src/app/playlist-uploader/playlist-uploader.component.html @@ -30,14 +30,14 @@ - +
- Recently added playlists ({{playlists.length}}) + Added playlists ({{playlists.length}}) diff --git a/src/app/playlist-uploader/playlist-uploader.component.ts b/src/app/playlist-uploader/playlist-uploader.component.ts index a7e00afd2..78390098f 100644 --- a/src/app/playlist-uploader/playlist-uploader.component.ts +++ b/src/app/playlist-uploader/playlist-uploader.component.ts @@ -34,13 +34,12 @@ export class PlaylistUploaderComponent { concurrency: 1, maxUploads: 1, }; - playlists: Playlist[] = []; + playlists: { count: number; title: string; _id: string }[] = []; isLoading = false; /** * Creates an instanceof PlaylistUploaderComponent * @param channelStore channels store - * @param m3uService m3u service * @param router angulars router * @param snackBar snackbars with notification messages */ @@ -155,7 +154,10 @@ export class PlaylistUploaderComponent { this.router.navigateByUrl('/iptv', { skipLocationChange: true }); } - sendUrl(): void { + /** + * Sends url of the playlist to the renderer process + */ + sendPlaylistsUrl(): void { this.renderer.send('parse-playlist-by-url', { title: this.getLastUrlSegment(this.playlistUrl), url: this.playlistUrl, diff --git a/src/styles.scss b/src/styles.scss index 56bc82ba6..e72c9f54a 100644 --- a/src/styles.scss +++ b/src/styles.scss @@ -7,7 +7,7 @@ $material-icons-font-path: '~material-icons/iconfont/'; body, html { - background: #56598e; + background: #011627; font-family: caption; }