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

React UI, data streaming: Fixed preview position #1312

Merged
merged 5 commits into from
Mar 25, 2020
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
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