Skip to content

Commit

Permalink
fix durations
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyshankman committed Nov 2, 2023
1 parent 6c657bc commit 7507329
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/renderer/App.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import { MemoryRouter as Router, Routes, Route } from 'react-router-dom';
import { IAudioMetadata } from 'music-metadata';
import { useState } from 'react';
import placeholder from '../../assets/placeholder.svg';
import './App.css';
import { useState } from 'react';

function MainDash() {
const [songMapping, setSongMapping] = useState<{
[key: string]: IAudioMetadata;
}>();

function convertToMMSS(timeInSeconds: number) {
const minutes = Math.floor(timeInSeconds / 60);
const seconds = Math.floor(timeInSeconds % 60);
// Ensuring the format is two-digits both for minutes and seconds
return `${minutes.toString().padStart(2, '0')}:${seconds
.toString()
.padStart(2, '0')}`;
}

return (
<div className="h-full flex flex-col">
<div className="flex justify-center p-4 space-x-4 md:flex-row">
Expand Down Expand Up @@ -59,7 +68,7 @@ function MainDash() {
{songMapping?.[song].common.album}
</td>
<td className="py-1.5 px-4 align-middle [&amp;:has([role=checkbox])]:pr-0 text-xs">
{songMapping?.[song].format.duration}
{convertToMMSS(songMapping?.[song].format.duration || 0)}
</td>
</tr>
))}
Expand Down

0 comments on commit 7507329

Please sign in to comment.