Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions packages/webamp/js/reducers/tracks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,35 @@
[id: string]: PlaylistTrack;
}

function massageKhz(khz: number) {
let finalKhz: String;
const khzNum: number = Math.round(khz / 1000);

// there is no real need to run a condition for below 100khz
// when the other conditions (hopefully) take over
// ...also to make CI happy
finalKhz = String(khzNum);
if (khzNum <= 10) finalKhz = String(khzNum).slice(0, 1).padStart(2, " ");
if (khzNum >= 100) finalKhz = String(khzNum).slice(1, 3);
return finalKhz;
}

function massageKbps(kbps: number) {
let finalKbps: String;
const bitrateNum: number = Math.round(kbps / 1000);

finalKbps = String(bitrateNum); // present as is
if (bitrateNum <= 100) finalKbps = String(bitrateNum).padStart(3, " ");
if (bitrateNum <= 10) finalKbps = String(bitrateNum).padStart(3, " ");
// from Justin Frankel directly:
// IIRC H was for "hundred" and "C" was thousand,
// though why it was for thousand I have no idea lol, maybe it was a mistake...
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic comment

if (bitrateNum >= 1000) finalKbps = String(bitrateNum).slice(0, 2) + "H";

Check warning on line 32 in packages/webamp/js/reducers/tracks.ts

View workflow job for this annotation

GitHub Actions / ci

Unexpected string concatenation
if (bitrateNum >= 10000)
finalKbps = String(bitrateNum).slice(0, 1).padStart(2, " ") + "C";

Check warning on line 34 in packages/webamp/js/reducers/tracks.ts

View workflow job for this annotation

GitHub Actions / ci

Unexpected string concatenation
return finalKbps;
}

const defaultPlaylistState: TracksState = {};

const tracks = (
Expand Down Expand Up @@ -80,8 +109,8 @@
artist,
album,
albumArtUrl,
kbps: bitrate != null ? String(Math.round(bitrate / 1000)) : kbps,
khz: sampleRate != null ? String(Math.round(sampleRate / 1000)) : khz,
kbps: bitrate != null ? massageKbps(bitrate) : kbps,
khz: sampleRate != null ? massageKhz(sampleRate) : khz,
channels: numberOfChannels != null ? numberOfChannels : channels,
},
};
Expand Down
4 changes: 2 additions & 2 deletions packages/webamp/js/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -686,14 +686,14 @@ export const getMarqueeText = (state: AppState): string => {
export const getKbps = createSelector(
getCurrentTrack,
(track: PlaylistTrack | null): string | null => {
return track != null ? track.kbps || null : null;
return track != null ? track.kbps || "0".padStart(3, " ") : null;
}
);

export const getKhz = createSelector(
getCurrentTrack,
(track: PlaylistTrack | null): string | null => {
return track != null ? track.khz || null : null;
return track != null ? track.khz || "0".padStart(2, " ") : null;
}
);

Expand Down
Loading