Files
spacedrive/interface/app/$libraryId/Layout/Sidebar/JobManager/useJobTimeText.tsx
ameer2468 0a4c1f41e7 Job Manager improvement & refactor (#783)
* d

* wip

* Nit: margin and padding tweak

* UI design tweaks

* Update Job.tsx

* Improve UI

* [WIP] - Refactor job manager

* remove invalidate explorer event on thumb generation. the event above performs atomic updates on the front end when new thumbnails are generated, now just need to make that work

* prettier formatting + removed unused imports

* UI tweaks

* progress bar width adjustment

* tweaks

* fix em

* fix thumbnail generation

* fix progress bar

* fix time

---------

Co-authored-by: Jamie Pine <ijamespine@me.com>
Co-authored-by: Brendan Allan <brendonovich@outlook.com>
Co-authored-by: Oscar Beaumont <oscar@otbeaumont.me>
2023-05-08 22:31:49 +00:00

30 lines
891 B
TypeScript

import dayjs from 'dayjs';
import { useEffect, useMemo } from 'react';
import { JobReport } from '@sd/client';
import { useForceUpdate } from '~/util';
export function useJobTimeText(job: JobReport): string | null {
const forceUpdate = useForceUpdate();
const elapsedTimeText = useMemo(() => {
let newText: string;
if (job.status === 'Running') {
newText = `Elapsed in ${dayjs(job.started_at).fromNow(true)}`;
} else if (job.completed_at) {
newText = `Took ${dayjs(job.started_at).from(job.completed_at, true)}`;
} else {
newText = `Took ${dayjs(job.started_at).fromNow(true)}`;
}
return newText;
}, [job]);
useEffect(() => {
if (job.status === 'Running') {
const interval = setInterval(forceUpdate, 1000);
return () => clearInterval(interval);
}
}, [job.status, forceUpdate]);
return elapsedTimeText === 'Took NaN years' ? null : elapsedTimeText;
}