import { Localization } from "@Component/Localization/Localization"; import { Theme } from "@Component/Theme/Theme"; import { Icon } from "@fluentui/react"; import { Clip } from "@Model/Clip"; import { Component, ReactNode } from "react"; import "./ClipList.scss"; interface IClipListProps { clips: Clip[]; focus?: Clip; disable?: boolean; add?: () => any; click?: (clip: Clip) => any; delete?: (clip: Clip) => any; } class ClipList extends Component { private isInnerClick: boolean = false; private resolveCallback(fn?: (p: any) => any, p?: any): any { if (this.props.disable) { return false; } if (fn) { return fn(p); } } private parseTime(time?: number): string { if (time === undefined) { return "0:0:0:0"; } const h = Math.floor(time / 3600); const m = Math.floor((time % 3600) / 60); const s = Math.floor((time % 3600) % 60); const ms = Math.floor((time % 1) * 1000); return `${h}:${m}:${s}:${ms}`; } private getClipInfo(clip: Clip): string { let fps = Math.floor(clip.frames.length / clip.time); if (isNaN(fps)) fps = 0; return `${this.parseTime(clip.time)} ${fps}fps`; } private renderClip(clip: Clip) { const focus = clip.equal(this.props.focus); const disable = this.props.disable; const classList = ["clip-item"]; if (focus) { classList.push("focus"); } if (disable) { classList.push("disable"); } else { classList.push("able"); } return
{ if (this.isInnerClick) { this.isInnerClick = false; } else { this.resolveCallback(this.props.click, clip); } }} >
{new Array(4).fill(0).map((_, index) => { return
})}
{ this.isInnerClick = true; this.resolveCallback(this.props.delete, clip); }} />
{clip.name}
{ clip.isRecording ? : this.getClipInfo(clip) }
; } private renderAddButton(): ReactNode { const classList = ["clip-item", "add-button"]; if (this.props.disable) { classList.push("disable"); } else { classList.push("able"); } return
this.resolveCallback(this.props.add)} >
} public render(): ReactNode { return { this.props.clips.map((clip => { return this.renderClip(clip); })) } { this.renderAddButton() } ; } } export { ClipList };