mirror of
https://github.com/streamyfin/streamyfin.git
synced 2025-08-20 18:37:18 +02:00
Co-authored-by: lostb1t <coding-mosses0z@icloud.com> Co-authored-by: Fredrik Burmester <fredrik.burmester@gmail.com> Co-authored-by: Gauvain <68083474+Gauvino@users.noreply.github.com> Co-authored-by: Gauvino <uruknarb20@gmail.com> Co-authored-by: storm1er <le.storm1er@gmail.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Chris <182387676+whoopsi-daisy@users.noreply.github.com> Co-authored-by: arch-fan <55891793+arch-fan@users.noreply.github.com> Co-authored-by: Alex Kim <alexkim@Alexs-MacBook-Pro.local>
48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client/models";
|
|
import React, { useMemo } from "react";
|
|
import { View } from "react-native";
|
|
|
|
interface ProgressBarProps {
|
|
item: BaseItemDto;
|
|
}
|
|
|
|
export const ProgressBar: React.FC<ProgressBarProps> = ({ item }) => {
|
|
const progress = useMemo(() => {
|
|
if (item.Type === "Program") {
|
|
if (!item.StartDate || !item.EndDate) {
|
|
return 0;
|
|
}
|
|
const startDate = new Date(item.StartDate);
|
|
const endDate = new Date(item.EndDate);
|
|
const now = new Date();
|
|
const total = endDate.getTime() - startDate.getTime();
|
|
if (total <= 0) {
|
|
return 0;
|
|
}
|
|
const elapsed = now.getTime() - startDate.getTime();
|
|
return (elapsed / total) * 100;
|
|
}
|
|
return item.UserData?.PlayedPercentage || 0;
|
|
}, [item]);
|
|
|
|
if (progress <= 0) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<View
|
|
className={
|
|
"absolute bottom-0 left-0 h-1 bg-neutral-700 opacity-80 w-full"
|
|
}
|
|
/>
|
|
<View
|
|
style={{
|
|
width: `${progress}%`,
|
|
}}
|
|
className={"absolute bottom-0 left-0 h-1 bg-purple-600 w-full"}
|
|
/>
|
|
</>
|
|
);
|
|
};
|