From 99209b4fad25378d60769c349d5302080d052040 Mon Sep 17 00:00:00 2001 From: Quinn Casey Date: Wed, 10 Jul 2019 12:33:44 -0700 Subject: [PATCH 1/2] Begin date-added --- src/shared/types/interfaces.ts | 4 +++- src/ui/constants/sort-orders.ts | 24 ++++++++++++++++++++++++ src/ui/utils/utils.ts | 5 ++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/shared/types/interfaces.ts b/src/shared/types/interfaces.ts index 774ea856d..777425983 100644 --- a/src/shared/types/interfaces.ts +++ b/src/shared/types/interfaces.ts @@ -18,7 +18,8 @@ export enum SortBy { ALBUM = 'album', TITLE = 'title', DURATION = 'duration', - GENRE = 'genre' + GENRE = 'genre', + DATE_ADDED = 'date added' } export enum SortOrder { @@ -87,6 +88,7 @@ export interface Track { of: number }; year: number | null; + dateAdded: Date | null; } export interface Playlist { diff --git a/src/ui/constants/sort-orders.ts b/src/ui/constants/sort-orders.ts index fc992af19..28b5ebe48 100644 --- a/src/ui/constants/sort-orders.ts +++ b/src/ui/constants/sort-orders.ts @@ -122,6 +122,30 @@ const sortOrders = { ], ['desc'] ] + }, + [SortBy.DATE_ADDED]: { + [SortOrder.ASC]: [ + [ + parseGenre, + parseArtist, + 'year', + 'loweredMetas.album', + 'disk.no', + 'track.no' + ], + null + ], + [SortOrder.DSC]: [ + [ + parseGenre, + parseArtist, + 'year', + 'loweredMetas.album', + 'disk.no', + 'track.no' + ], + ['desc'] + ] } }; diff --git a/src/ui/utils/utils.ts b/src/ui/utils/utils.ts index 9936029f6..9dbbc116a 100644 --- a/src/ui/utils/utils.ts +++ b/src/ui/utils/utils.ts @@ -123,7 +123,8 @@ export const getDefaultMetadata = (): Track => ({ no: 0, of: 0 }, - year: null + year: null, + dateAdded: null }); export const parseMusicMetadata = (data: mmd.IAudioMetadata, trackPath: string): Partial => { @@ -208,6 +209,8 @@ export const getMetadata = async (trackPath: string): Promise => { } } + metadata.dateAdded = new Date(); + return metadata; } catch (err) { console.warn(`An error occured while reading ${trackPath} id3 tags: ${err}`); From 4d6fcba3d892b1126aa5069b0fd1b49e3ec3c5d1 Mon Sep 17 00:00:00 2001 From: Quinn Casey Date: Mon, 15 Jul 2019 20:33:22 -0700 Subject: [PATCH 2/2] Finishing Date Added, adding File Size sorts --- src/shared/types/interfaces.ts | 4 ++- src/ui/components/TrackRow/TrackRow.tsx | 7 +++-- .../TracksListHeader/TracksListHeader.css | 2 +- .../TracksListHeader/TracksListHeader.tsx | 12 +++++-- src/ui/constants/sort-orders.ts | 31 +++++++++++++++++-- src/ui/utils/utils.ts | 13 +++++++- 6 files changed, 58 insertions(+), 11 deletions(-) diff --git a/src/shared/types/interfaces.ts b/src/shared/types/interfaces.ts index 777425983..ecd624ee1 100644 --- a/src/shared/types/interfaces.ts +++ b/src/shared/types/interfaces.ts @@ -19,7 +19,8 @@ export enum SortBy { TITLE = 'title', DURATION = 'duration', GENRE = 'genre', - DATE_ADDED = 'date added' + DATE_ADDED = 'date added', + FILESIZE = 'filesize' } export enum SortOrder { @@ -89,6 +90,7 @@ export interface Track { }; year: number | null; dateAdded: Date | null; + filesize: number | null; // in MB } export interface Playlist { diff --git a/src/ui/components/TrackRow/TrackRow.tsx b/src/ui/components/TrackRow/TrackRow.tsx index 5d1ead561..0bdb7e8be 100644 --- a/src/ui/components/TrackRow/TrackRow.tsx +++ b/src/ui/components/TrackRow/TrackRow.tsx @@ -147,8 +147,11 @@ export default class TrackRow extends React.PureComponent {
{ track.album }
-
- { track.genre.join(', ') } +
+ { track.filesize ? track.filesize.toString() + ' MB' : '-' } +
+
+ { track.dateAdded ? track.dateAdded.toLocaleString() : 'Unknown' }
); diff --git a/src/ui/components/TracksListHeader/TracksListHeader.css b/src/ui/components/TracksListHeader/TracksListHeader.css index 9f3c87068..8430dce1b 100644 --- a/src/ui/components/TracksListHeader/TracksListHeader.css +++ b/src/ui/components/TracksListHeader/TracksListHeader.css @@ -12,7 +12,7 @@ } .cell-track { - flex: 1; + width: calc(26% - 30px); } .cell-duration { diff --git a/src/ui/components/TracksListHeader/TracksListHeader.tsx b/src/ui/components/TracksListHeader/TracksListHeader.tsx index 29127ed68..5e269f374 100644 --- a/src/ui/components/TracksListHeader/TracksListHeader.tsx +++ b/src/ui/components/TracksListHeader/TracksListHeader.tsx @@ -66,11 +66,17 @@ class TracksListHeader extends React.Component { sortBy={enableSort ? SortBy.ALBUM : null} icon={TracksListHeader.getIcon(sort, SortBy.ALBUM)} /> + ); diff --git a/src/ui/constants/sort-orders.ts b/src/ui/constants/sort-orders.ts index 28b5ebe48..91ac8bb7a 100644 --- a/src/ui/constants/sort-orders.ts +++ b/src/ui/constants/sort-orders.ts @@ -4,6 +4,7 @@ import { Track, SortOrder, SortBy } from '../../shared/types/interfaces'; // the is far more resource/time impactful const parseArtist = (t: Track): string => t.loweredMetas.artist.toString(); const parseGenre = (t: Track): string => t.loweredMetas.genre.toString(); +const parseDateAdded = (t: Track): string => t.dateAdded ? t.dateAdded.getTime().toString() : '0'; // Declarations const sortOrders = { @@ -113,7 +114,7 @@ const sortOrders = { ], [SortOrder.DSC]: [ [ - parseGenre, + parseDateAdded, parseArtist, 'year', 'loweredMetas.album', @@ -126,7 +127,7 @@ const sortOrders = { [SortBy.DATE_ADDED]: { [SortOrder.ASC]: [ [ - parseGenre, + parseDateAdded, parseArtist, 'year', 'loweredMetas.album', @@ -137,7 +138,31 @@ const sortOrders = { ], [SortOrder.DSC]: [ [ - parseGenre, + parseDateAdded, + parseArtist, + 'year', + 'loweredMetas.album', + 'disk.no', + 'track.no' + ], + ['desc'] + ] + }, + [SortBy.FILESIZE]: { + [SortOrder.ASC]: [ + [ + 'filesize', + parseArtist, + 'year', + 'loweredMetas.album', + 'disk.no', + 'track.no' + ], + null + ], + [SortOrder.DSC]: [ + [ + 'filesize', parseArtist, 'year', 'loweredMetas.album', diff --git a/src/ui/utils/utils.ts b/src/ui/utils/utils.ts index 9dbbc116a..df9175a3d 100644 --- a/src/ui/utils/utils.ts +++ b/src/ui/utils/utils.ts @@ -78,6 +78,15 @@ export const stripAccents = (str: string): string => { return str.replace(reg, replacement).toLowerCase(); }; +export const roundNumber = (num: number, scale: number): number => { + let arr = ('' + num).split('e'); + let sig = ''; + if (+arr[1] + scale > 0) { + sig = '+'; + } + return +(Math.round(parseFloat(+arr[0] + 'e' + sig + (+arr[1] + scale))) + 'e-' + scale); +} + /** * Remove duplicates (realpath) and useless children folders */ @@ -124,7 +133,8 @@ export const getDefaultMetadata = (): Track => ({ of: 0 }, year: null, - dateAdded: null + dateAdded: null, + filesize: null }); export const parseMusicMetadata = (data: mmd.IAudioMetadata, trackPath: string): Partial => { @@ -210,6 +220,7 @@ export const getMetadata = async (trackPath: string): Promise => { } metadata.dateAdded = new Date(); + metadata.filesize = Math.round(stats.size / 1000000.0); return metadata; } catch (err) {