-
Notifications
You must be signed in to change notification settings - Fork 689
Expand file tree
/
Copy pathClipPreview.tsx
More file actions
186 lines (174 loc) · 6.23 KB
/
Copy pathClipPreview.tsx
File metadata and controls
186 lines (174 loc) · 6.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import { TClip } from 'services/highlighter/models/highlighter.models';
import {
SCRUB_HEIGHT,
SCRUB_WIDTH,
SCRUB_WIDTH_VERTICAL,
SCRUB_FRAMES,
} from 'services/highlighter/constants';
import React, { useState } from 'react';
import { Services } from 'components-react/service-provider';
import { BoolButtonInput } from 'components-react/shared/inputs/BoolButtonInput';
import styles from './ClipPreview.m.less';
import { Button, Tooltip } from 'antd';
import { $t } from 'services/i18n';
import { isAiClip } from './utils';
import { useVuex } from 'components-react/hooks';
import ClipPreviewInfo from './ClipPreviewInfo';
import { EGame } from 'services/highlighter/models/ai-highlighter.models';
import cx from 'classnames';
export default function ClipPreview(props: {
clipId: string;
streamId: string | undefined;
emitShowTrim: () => void;
emitShowRemove: () => void;
emitOpenFileInLocation: () => void;
game: EGame;
}) {
const { HighlighterService } = Services;
const v = useVuex(() => ({
clip: HighlighterService.views.clipsDictionary[props.clipId] as TClip,
}));
const [scrubFrame, setScrubFrame] = useState<number>(0);
const clipThumbnail = v.clip.scrubSprite || '';
const enabled = v.clip.deleted ? false : v.clip.enabled;
if (!v.clip) {
return <>deleted</>;
}
const width = v.clip.display === 'vertical' ? SCRUB_WIDTH_VERTICAL : SCRUB_WIDTH;
function mouseMove(e: React.MouseEvent) {
const frameIdx = Math.floor((e.nativeEvent.offsetX / width) * SCRUB_FRAMES);
if (scrubFrame !== frameIdx) {
setScrubFrame(frameIdx);
}
}
function setEnabled(enabled: boolean) {
HighlighterService.actions.manuallyEnableClip(v.clip.path, enabled, props.streamId);
}
return (
<div className={styles.previewClip} style={{ opacity: v.clip.enabled ? 1.0 : 0.3 }}>
<div style={{ height: `${SCRUB_HEIGHT}px`, position: 'relative' }}>
{!v.clip.deleted && (
<img
src={clipThumbnail}
className={cx(styles.previewImage, {
[styles.verticalPreview]: v.clip.display === 'vertical',
})}
style={{
width: `${width}px`,
height: `${SCRUB_HEIGHT}px`,
objectPosition: `-${scrubFrame * width}px`,
}}
onMouseMove={mouseMove}
onClick={props.emitShowTrim}
/>
)}
{v.clip.deleted && (
<div
style={{
width: `${SCRUB_WIDTH}px`,
height: `${SCRUB_HEIGHT}px`,
}}
className={styles.deletedPreview}
>
<i className={`icon-trash ${styles.deletedIcon}`} />
</div>
)}
<div className={styles.flameHypescoreWrapper}>
{isAiClip(v.clip) && <FlameHypeScore score={v.clip.aiInfo.score} />}
</div>
<span className={styles.enableButton}>
<BoolButtonInput
tooltip={enabled ? $t('Disable clip') : $t('Enable clip')}
tooltipPlacement="top"
value={enabled}
onChange={setEnabled}
checkboxStyles={{
width: '24px',
height: '24px',
fontSize: '14px',
background: 'white',
borderColor: '#333',
}}
checkboxActiveStyles={{ background: 'var(--teal-hover)' }}
/>
</span>
<div className={styles.previewClipMoving}>
<div className={styles.controlsContainer}>
{/* left */}
<div className={styles.durationInfo}>
<span className={styles.durationLabel}>
{formatSecondsToHMS(v.clip.duration! - (v.clip.startTrim + v.clip.endTrim) || 0)}
</span>
</div>
{/* right */}
<div style={{ display: 'flex', gap: '4px' }}>
<div
style={{
fontSize: '19px',
}}
>
{isAiClip(v.clip) ? (
<ClipPreviewInfo clip={v.clip} game={props.game} />
) : (
<div className={styles.highlighterIcon}>
<i className="icon-highlighter" />
</div>
)}
</div>
</div>
</div>
<div className={styles.previewClipBottomBar}>
<Button size="large" className={styles.actionButton} onClick={props.emitShowRemove}>
<i className="icon-trash" />
</Button>
<div style={{ display: 'flex', gap: '4px' }}>
<Button size="large" className={styles.actionButton} onClick={props.emitShowTrim}>
<i className="icon-trim" style={{ marginRight: '8px' }} /> {$t('Trim')}
</Button>
<Tooltip title={$t('Open file location')} placement="top">
<Button
size="large"
className={styles.actionButton}
onClick={props.emitOpenFileInLocation}
>
<i className="icon-pop-out-2" />
</Button>
</Tooltip>
</div>
</div>
</div>
</div>
</div>
);
}
export function formatSecondsToHMS(seconds: number): string {
const totalSeconds = Math.round(seconds);
if (totalSeconds === 0) {
return '0s';
}
const hours = Math.floor(totalSeconds / 3600);
const minutes = Math.floor((totalSeconds % 3600) / 60);
const remainingSeconds = totalSeconds % 60;
return `${hours !== 0 ? hours.toString() + 'h ' : ''} ${
minutes !== 0 ? minutes.toString() + 'm ' : ''
}${remainingSeconds !== 0 ? remainingSeconds.toString() + 's' : ''}`;
}
function FlameHypeScore({ score }: { score: number }) {
if (score === undefined) {
return <></>;
}
const normalizedScore = Math.min(1, Math.max(0, score));
const fullFlames = Math.ceil(normalizedScore * 5);
return (
<div className="flex items-center gap-1" style={{ fontSize: '19px' }}>
{Array.from({ length: fullFlames }).map((_, index) => (
<React.Fragment key={'on' + index}>🔥</React.Fragment>
))}
{Array.from({ length: 5 - fullFlames }).map((_, index) => (
<span key={'off' + index} style={{ opacity: '0.3' }}>
🔥
</span>
))}
</div>
);
}