Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thumbnail make boxes same size #1210

Merged
merged 3 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions src/main/Thumbnail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ const Thumbnail : React.FC = () => {

const bottomStyle = css({
display: 'flex',
width: '100%',
flexDirection: 'column',
alignItems: 'center',
})
Expand All @@ -100,13 +101,15 @@ const Thumbnail : React.FC = () => {
<div css={[titleStyle(theme), titleStyleBold(theme)]}>{t('thumbnail.title')}</div>
<ThumbnailTable
inputRefs={inputRefs}
generateRefs={generateRefs}
generate={generate}
upload={upload}
uploadCallback={uploadCallback}
discard={discardThumbnail}
/>
<div css={bottomStyle}>
<VideoPlayers refs={generateRefs} widthInPercent={100}/>
{/* use maxHeightInPixel to make video players the same size*/}
<VideoPlayers refs={generateRefs} widthInPercent={100} maxHeightInPixel={420}/>
<div css={videosStyle(theme)}>
<Timeline
timelineHeight={125}
Expand Down Expand Up @@ -139,16 +142,18 @@ const Thumbnail : React.FC = () => {
*/
const ThumbnailTable : React.FC<{
inputRefs: any,
generateRefs: React.MutableRefObject<any>,
generate: any,
upload: any,
uploadCallback: any,
discard: any,
}> = ({inputRefs, generate, upload, uploadCallback, discard}) => {
}> = ({inputRefs, generateRefs, generate, upload, uploadCallback, discard}) => {

const videoTracks = useSelector(selectVideos)

const thumbnailTableStyle = css({
display: 'flex',
width: '100%',
flexDirection: 'row',
justifyContent: 'center',
...(flexGapReplacementStyle(10, false)),
Expand Down Expand Up @@ -182,6 +187,7 @@ const ThumbnailTable : React.FC<{
track={track}
index={index}
inputRefs={inputRefs}
generateRef={generateRefs.current[index]}
generate={generate}
upload={upload}
uploadCallback={uploadCallback}
Expand All @@ -207,15 +213,19 @@ const ThumbnailTableRow: React.FC<{
track: Track,
index: number,
inputRefs: any,
generateRef: any,
generate: any,
upload: any,
uploadCallback: any,
discard: any,
}> = ({track, index, inputRefs, generate, upload, uploadCallback, discard}) => {
}> = ({track, index, inputRefs, generateRef, generate, upload, uploadCallback, discard}) => {

const { t } = useTranslation()
const theme = useTheme();

// The "+40" comes from padding that is not included in the "getWidth" function
const videoWidth = generateRef ? generateRef.getWidth() + 40 : undefined
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would using offsetWidth instead of clientWidth remove the need to add 40 manually?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It did not

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sad 🤷


const renderPriority = (thumbnailPriority: number) => {
if (isNaN(thumbnailPriority)) {
return ""
Expand All @@ -231,7 +241,7 @@ const ThumbnailTableRow: React.FC<{
}

return (
<div key={index} css={[backgroundBoxStyle(theme), thumbnailTableRowStyle]}>
<div key={index} css={[backgroundBoxStyle(theme), thumbnailTableRowStyle(videoWidth)]}>
<div css={thumbnailTableRowTitleStyle}>
{track.flavor.type + renderPriority(track.thumbnailPriority)}
</div>
Expand Down Expand Up @@ -497,7 +507,7 @@ const ThumbnailTableSingleRow: React.FC<{
const theme = useTheme();

return (
<div key={index} css={[backgroundBoxStyle(theme), thumbnailTableRowStyle]}>
<div key={index} css={[backgroundBoxStyle(theme), thumbnailTableRowStyle(500)]}>
<div css={thumbnailTableRowTitleStyle}>
{t("thumbnailSimple.rowTitle")}
</div>
Expand Down Expand Up @@ -580,9 +590,11 @@ const ThumbnailButtonsSimple : React.FC<{
/**
* CSS shared between multi and simple display mode
*/
const thumbnailTableRowStyle = css({
const thumbnailTableRowStyle = (maxWidth: number) => css({
display: 'flex',
flexDirection: 'column',
width: '100%',
maxWidth: `${maxWidth}px`,
})

const thumbnailTableRowTitleStyle = css({
Expand Down
7 changes: 5 additions & 2 deletions src/main/VideoPlayers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { useTheme } from "../themes";

import { backgroundBoxStyle, flexGapReplacementStyle } from '../cssStyles'

const VideoPlayers: React.FC<{refs: any, widthInPercent?: number}> = ({refs, widthInPercent = 100}) => {
const VideoPlayers: React.FC<{refs: any, widthInPercent?: number, maxHeightInPixel?: number}> = ({refs, widthInPercent = 100, maxHeightInPixel = 300}) => {

const videoURLs = useSelector(selectVideoURL)
const videoCount = useSelector(selectVideoCount)
Expand All @@ -37,7 +37,7 @@ const VideoPlayers: React.FC<{refs: any, widthInPercent?: number}> = ({refs, wid
borderRadius: '5px',
...(flexGapReplacementStyle(10, false)),

maxHeight: '300px',
maxHeight: maxHeightInPixel + 'px',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Editor is also using emotion-js, right? You should be able to just pass integers here. Also the borderRadius: 5 above should just work. But if the whole codebase uses + 'px' already, then it's probably not necessary to fix this for this one PR now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does use Emotion, but not emotion-js specifically I think? Anyway, I like being specific about my units :D

});

// Initialize video players
Expand Down Expand Up @@ -325,6 +325,9 @@ export const VideoPlayer = React.forwardRef(
canvasContext.drawImage(video, 0, 0);
return canvas.toDataURL('image/png')
}
},
getWidth() {
return (ref.current?.getInternalPlayer() as HTMLVideoElement).clientWidth
}
}));

Expand Down
Loading