Skip to content

Commit

Permalink
format + notif
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlevy0 committed Dec 2, 2023
1 parent 269e580 commit 50c66c3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
11 changes: 8 additions & 3 deletions src/app/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,10 @@ const Clip = () => {
const [processDurationSecond, setProcessDurationSecond] = useState('')
const [status, setStatus] = useState(STANDBY)

useEffect(() => {
Notification.requestPermission()
}, []);

const onReady = () => {
setStatus(READY)
}
Expand All @@ -400,7 +404,8 @@ const Clip = () => {
const urlEdited = await retry({ fn: async () => await getData(key) })
setUrlEdited(urlEdited)
})
setProcessDurationSecond(`⏱️ ${durationSecond}s `)
setProcessDurationSecond(`⏱️ ${durationSecond}`)
new Notification(`⏱️ ${durationSecond}`)
} catch (error) {
console.error(`onSuccess ERROR : ${error}`);
}
Expand Down Expand Up @@ -476,15 +481,15 @@ const Clip = () => {
>
<ReactPlayer
style={{ backgroundColor: 'black' }}
playing={true}
playing={false}
controls={true}
url={url}
width={"100%"}
/>
<ReactPlayer
style={{ backgroundColor: 'grey' }}
onReady={onReady}
playing={true}
playing={false}
controls={true}
url={urlEdited}
width={"100%"}
Expand Down
9 changes: 6 additions & 3 deletions src/app/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@ export const getData = async (key: string, prefix = '_edited') => {
}
}

export async function measurePromise(fn: () => Promise<any>): Promise<number> {
export async function measurePromise(fn: () => Promise<any>): Promise<string> {
const start = performance.now()
await fn()
const durationInMilliseconds = performance.now() - start
return parseFloat((durationInMilliseconds / 1000).toFixed(2))
const durationInMinutes = (performance.now() - start) / 60000
const wholeMinutes = Math.floor(durationInMinutes)
const seconds = Math.round((durationInMinutes - wholeMinutes) * 60)
const formattedSeconds = seconds.toString().padStart(2, '0');
return `${wholeMinutes}mn ${formattedSeconds}s`
}

0 comments on commit 50c66c3

Please sign in to comment.