mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-07 03:32:06 +00:00
45 lines
1.5 KiB
TypeScript
45 lines
1.5 KiB
TypeScript
|
|
import type { MediaFile } from "@/domain/work-orders/types/work-order-media";
|
||
|
|
|
||
|
|
const COMPLETION_PURPOSES = new Set(["Before", "After", "Completion"]);
|
||
|
|
|
||
|
|
export type MediaSurfaceOwnership = {
|
||
|
|
completionOwnedIds: ReadonlySet<string>;
|
||
|
|
extraOwnedIds: ReadonlySet<string>;
|
||
|
|
};
|
||
|
|
|
||
|
|
const EMPTY_OWNERSHIP: MediaSurfaceOwnership = {
|
||
|
|
completionOwnedIds: new Set(),
|
||
|
|
extraOwnedIds: new Set(),
|
||
|
|
};
|
||
|
|
|
||
|
|
function isPhotoOrVideo(item: MediaFile): boolean {
|
||
|
|
return item.fileType === "image" || item.fileType === "video";
|
||
|
|
}
|
||
|
|
|
||
|
|
function isInFlight(item: MediaFile): boolean {
|
||
|
|
return item.uploadStatus === "uploading" || item.uploadStatus === "failed";
|
||
|
|
}
|
||
|
|
|
||
|
|
/** Extra photo/video from Completion Doc POST (no category) until Extra is chosen. */
|
||
|
|
export function isCompletionSurfaceMedia(
|
||
|
|
item: MediaFile,
|
||
|
|
ownership: MediaSurfaceOwnership = EMPTY_OWNERSHIP,
|
||
|
|
): boolean {
|
||
|
|
if (isInFlight(item)) return true;
|
||
|
|
if (COMPLETION_PURPOSES.has(item.purpose ?? "")) return true;
|
||
|
|
if (ownership.completionOwnedIds.has(item.id)) return true;
|
||
|
|
if (ownership.extraOwnedIds.has(item.id)) return false;
|
||
|
|
return item.purpose === "Extra" && isPhotoOrVideo(item);
|
||
|
|
}
|
||
|
|
|
||
|
|
export function isExtrasSurfaceMedia(
|
||
|
|
item: MediaFile,
|
||
|
|
ownership: MediaSurfaceOwnership = EMPTY_OWNERSHIP,
|
||
|
|
): boolean {
|
||
|
|
if (item.purpose === "Aveta") return true;
|
||
|
|
if (item.purpose !== "Extra") return false;
|
||
|
|
if (ownership.completionOwnedIds.has(item.id)) return false;
|
||
|
|
if (ownership.extraOwnedIds.has(item.id)) return true;
|
||
|
|
return !isPhotoOrVideo(item);
|
||
|
|
}
|