Files
spacedrive/interface/app/$libraryId/Layout/Sidebar/JobManager/useGroupedJobs.ts
ameer2468 2a5d5be4c0 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

26 lines
637 B
TypeScript

import { useMemo } from 'react';
import { JobReport } from '@sd/client';
export interface IJobGroup extends JobReport {
childJobs: JobReport[];
runningJobs: JobReport[];
}
export function useGroupedJobs(jobs: JobReport[] = [], runningJobs: JobReport[] = []) {
return useMemo(() => {
return jobs.reduce((arr, job) => {
const childJobs = jobs.filter((j) => j.parent_id === job.id);
if (!jobs.some((j) => j.id === job.parent_id)) {
arr.push({
...job,
childJobs,
runningJobs: runningJobs.filter((j) => j.parent_id === job.id)
});
}
return arr;
}, [] as IJobGroup[]);
}, [jobs, runningJobs]);
}