Skip to content

Commit

Permalink
Add button to move layer to background, return to align icons
Browse files Browse the repository at this point in the history
  • Loading branch information
lutzhelm committed Jan 16, 2025
1 parent ebd45b8 commit b33ede3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
27 changes: 23 additions & 4 deletions src/components/CanvasLayers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import ListItem from '@mui/material/ListItem';
import Slider from '@mui/material/Slider';
import Tooltip from '@mui/material/Tooltip';
import DragHandleIcon from '@mui/icons-material/DragHandleSharp';
import MoveDownSharp from '@mui/icons-material/MoveDownSharp';
import VerticalAlignTopSharp from '@mui/icons-material/VerticalAlignTopSharp';
import VerticalAlignBottomSharp from '@mui/icons-material/VerticalAlignBottomSharp';
import VisibilityIcon from '@mui/icons-material/VisibilitySharp';
import VisibilityOffIcon from '@mui/icons-material/VisibilityOffSharp';
import OpacityIcon from '@mui/icons-material/OpacitySharp';
Expand Down Expand Up @@ -43,10 +44,10 @@ const reorder = (list, startIndex, endIndex) => {

/** @private */
function Layer({
resource, layerMetadata = {}, index, handleOpacityChange, setLayerVisibility, moveToBackground,
resource, layerMetadata = {}, index, handleOpacityChange, setLayerVisibility, moveToBackground, moveToFront,
}) {
const { t } = useTranslation();
const { width, height } = { height: undefined, width: 50 };
const { width, height } = { height: undefined, width: 40 };

const layer = {
opacity: 1,
Expand Down Expand Up @@ -77,7 +78,12 @@ function Layer({
</MiradorMenuButton>
{ layer.index !== 0 && (
<MiradorMenuButton aria-label={t('layer_moveToBackground')} size="small" onClick={() => { moveToBackground(resource.id); }}>
<MoveDownSharp />
<VerticalAlignTopSharp />
</MiradorMenuButton>
)}
{ layer.index !== layerMetadata && (
<MiradorMenuButton aria-label={t('layer_moveToFront')} size="small" onClick={() => { moveToFront(resource.id); }}>
<VerticalAlignBottomSharp />
</MiradorMenuButton>
)}
</div>
Expand Down Expand Up @@ -134,6 +140,7 @@ Layer.propTypes = {
visibility: PropTypes.bool,
})), // eslint-disable-line react/forbid-prop-types
moveToBackground: PropTypes.func.isRequired,
moveToFront: PropTypes.func.isRequired,
resource: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
setLayerVisibility: PropTypes.func.isRequired,
};
Expand Down Expand Up @@ -246,6 +253,17 @@ export function CanvasLayers({
updateLayers(windowId, canvasId, payload);
}, [canvasId, layers, updateLayers, windowId]);

const moveToFront = useCallback((layerId) => {
const sortedLayers = reorder(layers.map(l => l.id), layers.findIndex(l => l.id === layerId), layers.length - 1);

Check warning on line 257 in src/components/CanvasLayers.js

View check run for this annotation

Codecov / codecov/patch

src/components/CanvasLayers.js#L257

Added line #L257 was not covered by tests

const payload = layers.reduce((acc, layer) => {
acc[layer.id] = { index: sortedLayers.indexOf(layer.id) };
return acc;
}, {});

Check warning on line 262 in src/components/CanvasLayers.js

View check run for this annotation

Codecov / codecov/patch

src/components/CanvasLayers.js#L259-L262

Added lines #L259 - L262 were not covered by tests

updateLayers(windowId, canvasId, payload);

Check warning on line 264 in src/components/CanvasLayers.js

View check run for this annotation

Codecov / codecov/patch

src/components/CanvasLayers.js#L264

Added line #L264 was not covered by tests
}, [canvasId, layers, updateLayers, windowId]);

return (
<>
{ totalSize > 1 && (
Expand Down Expand Up @@ -280,6 +298,7 @@ export function CanvasLayers({
handleOpacityChange={handleOpacityChange}
setLayerVisibility={setLayerVisibility}
moveToBackground={moveToBackground}
moveToFront={moveToFront}
/>
</DraggableLayer>
))
Expand Down
2 changes: 1 addition & 1 deletion src/locales/de/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
"language": "Sprache",
"layer_hide": "Ebene verbergen",
"layer_move": "Ebene verschieben",
"layer_moveToTop": "Ebene ganz nach vorn bringen",
"layer_moveToBackground": "Ebene in der Hintergrund verschieben",
"layer_moveToFront": "Ebene ganz nach vorn bringen",
"layer_opacity": "Ebenendeckkraft",
"layer_show": "Ebene anzeigen",
"layers": "Ebenen",
Expand Down
2 changes: 1 addition & 1 deletion src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
"language": "Language",
"layer_hide": "Hide layer",
"layer_move": "Move layer",
"layer_moveToTop": "Move layer to top",
"layer_moveToBackground": "Move layer to background",
"layer_moveToFront": "Move layer to front",
"layer_opacity": "Layer opacity",
"layer_show": "Show layer",
"layers": "Layers",
Expand Down

0 comments on commit b33ede3

Please sign in to comment.