Skip to content

Commit

Permalink
Fixed preview position
Browse files Browse the repository at this point in the history
  • Loading branch information
bsekachev committed Mar 24, 2020
1 parent 0d9f4d4 commit f1488fc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
30 changes: 25 additions & 5 deletions cvat-ui/src/components/task-page/details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,17 @@ interface State {

export default class DetailsComponent extends React.PureComponent<Props, State> {
private mounted: boolean;
private previewImageElement: HTMLImageElement;
private previewWrapperRef: React.RefObject<HTMLDivElement>;

constructor(props: Props) {
super(props);

const { taskInstance } = props;

this.mounted = false;
this.previewImageElement = new Image();
this.previewWrapperRef = React.createRef<HTMLDivElement>();
this.state = {
name: taskInstance.name,
bugTracker: taskInstance.bugTracker,
Expand All @@ -60,9 +64,25 @@ export default class DetailsComponent extends React.PureComponent<Props, State>
}

public componentDidMount(): void {
const { taskInstance } = this.props;
const { taskInstance, previewImage } = this.props;
const { previewImageElement, previewWrapperRef } = this;
this.mounted = true;

previewImageElement.onload = () => {
const { height, width } = previewImageElement;
if (width > height) {
previewImageElement.style.width = '100%';
} else {
previewImageElement.style.height = '100%';
}
};

previewImageElement.src = previewImage;
previewImageElement.alt = 'Preview';
if (previewWrapperRef.current) {
previewWrapperRef.current.appendChild(previewImageElement);
}

getReposData(taskInstance.id)
.then((data): void => {
if (data !== null && this.mounted) {
Expand Down Expand Up @@ -135,11 +155,11 @@ export default class DetailsComponent extends React.PureComponent<Props, State>
}

private renderPreview(): JSX.Element {
const { previewImage } = this.props;
const { previewWrapperRef } = this;

// Add image on mount after get its width and height to fit it into wrapper
return (
<div className='cvat-task-preview-wrapper'>
<img alt='Preview' className='cvat-task-preview' src={previewImage} />
</div>
<div ref={previewWrapperRef} className='cvat-task-preview-wrapper' />
);
}

Expand Down
13 changes: 6 additions & 7 deletions cvat-ui/src/components/task-page/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,14 @@
}

.cvat-task-preview-wrapper {
display: flex;
justify-content: flex-start;
overflow: hidden;
margin-bottom: 20px;

> .cvat-task-preview {
max-width: 252px;
max-height: 144px;
}
width: 252px;
height: 144px;
display: table-cell;
text-align: center;
vertical-align: middle;
background-color: $background-color-2;
}

.cvat-user-selector {
Expand Down

0 comments on commit f1488fc

Please sign in to comment.