11import React , { FunctionComponent , useMemo } from "react" ;
22import { useNavigate } from "react-router" ;
3- import { Badge , Text , TextProps } from "@mantine/core" ;
3+ import { Badge , Group , Text , TextProps } from "@mantine/core" ;
44import { faEllipsis } from "@fortawesome/free-solid-svg-icons" ;
55import { ColumnDef } from "@tanstack/react-table" ;
66import { isString } from "lodash" ;
77import { useMovieSubtitleModification } from "@/apis/hooks" ;
88import { useShowOnlyDesired } from "@/apis/hooks/site" ;
99import { Action } from "@/components" ;
10+ import { HistoryIcon } from "@/components/bazarr" ;
1011import Language from "@/components/bazarr/Language" ;
1112import SubtitleToolsMenu from "@/components/SubtitleToolsMenu" ;
1213import SimpleTable from "@/components/tables/SimpleTable" ;
@@ -19,8 +20,28 @@ interface Props {
1920 movie : Item . Movie | null ;
2021 disabled ?: boolean ;
2122 profile ?: Language . Profile ;
23+ history ?: History . Movie [ ] ;
2224}
2325
26+ const ScoreBadge : React . FC < { score ?: string | number | null } > = ( {
27+ score,
28+ } ) => {
29+ if ( score === undefined || score === null || score === "" ) {
30+ return (
31+ < Text c = "dimmed" size = "xs" >
32+ —
33+ </ Text >
34+ ) ;
35+ }
36+ const pct = typeof score === "string" ? parseFloat ( score ) : score ;
37+ const color = pct >= 90 ? "green" : pct >= 70 ? "yellow" : "red" ;
38+ return (
39+ < Badge color = { color } size = "sm" variant = "light" >
40+ { typeof score === "number" ? `${ score } %` : score }
41+ </ Badge >
42+ ) ;
43+ } ;
44+
2445function isSubtitleTrack ( path : string | undefined | null ) {
2546 return ! isString ( path ) || path . length === 0 ;
2647}
@@ -36,7 +57,7 @@ function buildLanguageKey(sub: Subtitle): string {
3657 return key ;
3758}
3859
39- const Table : FunctionComponent < Props > = ( { movie, profile } ) => {
60+ const Table : FunctionComponent < Props > = ( { movie, profile, history } ) => {
4061 const onlyDesired = useShowOnlyDesired ( ) ;
4162
4263 const profileItems = useProfileItemsToLanguages ( profile ) ;
@@ -52,6 +73,29 @@ const Table: FunctionComponent<Props> = ({ movie, profile }) => {
5273 [ movie ?. subtitles ] ,
5374 ) ;
5475
76+ const historyMap = useMemo ( ( ) => {
77+ const map = new Map < string , History . Movie > ( ) ;
78+ history ?. forEach ( ( h ) => {
79+ if ( ! h . subtitles_path ) return ;
80+ if ( [ 1 , 2 , 3 ] . includes ( h . action ) ) {
81+ if ( ! map . has ( h . subtitles_path ) ) map . set ( h . subtitles_path , h ) ;
82+ }
83+ } ) ;
84+ return map ;
85+ } , [ history ] ) ;
86+
87+ const statusMap = useMemo ( ( ) => {
88+ const map = new Map < string , Set < number > > ( ) ;
89+ history ?. forEach ( ( h ) => {
90+ if ( ! h . subtitles_path ) return ;
91+ if ( [ 5 , 6 ] . includes ( h . action ) ) {
92+ if ( ! map . has ( h . subtitles_path ) ) map . set ( h . subtitles_path , new Set ( ) ) ;
93+ map . get ( h . subtitles_path ) ! . add ( h . action ) ;
94+ }
95+ } ) ;
96+ return map ;
97+ } , [ history ] ) ;
98+
5599 const navigate = useNavigate ( ) ;
56100
57101 const CodeCell = React . memo ( ( { item } : { item : Subtitle } ) => {
@@ -192,14 +236,56 @@ const Table: FunctionComponent<Props> = ({ movie, profile }) => {
192236 }
193237 } ,
194238 } ,
239+ {
240+ id : "score" ,
241+ header : "Score" ,
242+ cell : ( { row : { original } } ) => {
243+ const record = historyMap . get ( original . path ?? "" ) ;
244+ return < ScoreBadge score = { record ?. score } /> ;
245+ } ,
246+ } ,
247+ {
248+ id : "provider" ,
249+ header : "Provider" ,
250+ cell : ( { row : { original } } ) => {
251+ const record = historyMap . get ( original . path ?? "" ) ;
252+ if ( ! record ?. provider )
253+ return (
254+ < Text c = "dimmed" size = "xs" >
255+ —
256+ </ Text >
257+ ) ;
258+ return < Text size = "xs" > { record . provider } </ Text > ;
259+ } ,
260+ } ,
261+ {
262+ id : "status" ,
263+ header : "Status" ,
264+ cell : ( { row : { original } } ) => {
265+ const actions = statusMap . get ( original . path ?? "" ) ;
266+ if ( ! actions ?. size )
267+ return (
268+ < Text c = "dimmed" size = "xs" >
269+ —
270+ </ Text >
271+ ) ;
272+ return (
273+ < Group gap = { 4 } >
274+ { Array . from ( actions ) . map ( ( action ) => (
275+ < HistoryIcon key = { action } action = { action } />
276+ ) ) }
277+ </ Group >
278+ ) ;
279+ } ,
280+ } ,
195281 {
196282 id : "code2" ,
197283 cell : ( { row : { original } } ) => {
198284 return < CodeCell item = { original } /> ;
199285 } ,
200286 } ,
201287 ] ,
202- [ CodeCell ] ,
288+ [ CodeCell , historyMap , statusMap ] ,
203289 ) ;
204290
205291 const data : Subtitle [ ] = useMemo ( ( ) => {
0 commit comments