Skip to content

Commit

Permalink
Merge pull request #3821 from fstoe/fix_sizing_addBar
Browse files Browse the repository at this point in the history
Bug: sizing of workspaceAdd
  • Loading branch information
lutzhelm authored Jan 27, 2025
2 parents 88cc3f9 + 0089f95 commit af09363
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/components/WorkspaceAdd.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useRef, useState } from 'react';
import { useRef, useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import { styled } from '@mui/material/styles';
import classNames from 'classnames';
Expand Down Expand Up @@ -44,6 +44,14 @@ export function WorkspaceAdd({
const { t } = useTranslation();
const [addResourcesOpen, setAddResourcesVisibility] = useState(false);
const ref = useRef();
const [refWidth, setRefWidth] = useState('100%');

/** */
const updateRefWidth = () => {
if (ref.current) {
setRefWidth(ref.current.offsetWidth);
}
};

/** */
const handleDrop = ({ manifestId, manifestJson }, props, monitor) => {
Expand Down Expand Up @@ -84,9 +92,19 @@ export function WorkspaceAdd({
addResource, catalog, setWorkspaceAddVisibility, t, ...rest,
};

useEffect(() => {
window.addEventListener('resize', updateRefWidth);

updateRefWidth();

return () => {
window.removeEventListener('resize', updateRefWidth);
};
}, []);

return (
<IIIFDropTarget onDrop={handleDrop}>
<StyledWorkspaceAdd ref={ref} className={classNames(ns('workspace-add'))}>
<StyledWorkspaceAdd className={classNames(ns('workspace-add'))} ref={ref}>
{catalog.length < 1 ? (
<Grid
alignItems="center"
Expand Down Expand Up @@ -138,10 +156,8 @@ export function WorkspaceAdd({
sx={theme => ({
'.MuiDrawer-paper': {
borderTop: '0',
left: '0',
[theme.breakpoints.up('sm')]: {
left: '65px',
},
left: 'unset',
width: refWidth,
},
...(!addResourcesOpen && {
display: 'none',
Expand Down

0 comments on commit af09363

Please sign in to comment.