File size: 1,046 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { IconButton, Tooltip } from '@mui/material';
import ScaleIcon from '@mui/icons-material/AspectRatio';
import React from 'react';
import { useUiTranslator } from '../../core/components/hooks';
const SCALING_FACTORS = [1, 0.8, 0.6, 1.2];
let lastScale = SCALING_FACTORS[0]; // poor mans redux

export const ScaleButton: React.FC<{
  scale: number;
  setScale: (s: number) => void;
}> = ({ scale, setScale }) => {
  const { t } = useUiTranslator();
  const toggleScale = React.useCallback(() => {
    const newScalingFactor =
      SCALING_FACTORS[
        (SCALING_FACTORS.indexOf(lastScale ?? scale) + 1) %
          SCALING_FACTORS.length
      ];
    setScale(newScalingFactor);
    // poor man's redux
    lastScale = newScalingFactor;
  }, [scale, lastScale, setScale]);
  return (
    <Tooltip title={t('Change size of this window') ?? ''}>
      <IconButton
        onClick={toggleScale}
        aria-label="Change size of this window"
        color="primary"
      >
        <ScaleIcon />
      </IconButton>
    </Tooltip>
  );
};