Skip to content

Commit

Permalink
Unify names
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-drozd-it committed Aug 28, 2024
1 parent b8ff6b2 commit 7b5372e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 31 deletions.
18 changes: 9 additions & 9 deletions src/components/drawing/DrawingBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import AddCircleOutlineIcon from '@mui/icons-material/AddCircleOutline';
import RemoveCircleOutlineIcon from '@mui/icons-material/RemoveCircleOutline';

import ErasingAllConfirmationButton from './ErasingAllConfirmationButton';
import DrawingColorsPalette from './DrawingColorsPalette';
import DrawingColors from './DrawingColors';
import { RoomState } from '../../store/slices/roomSlice';

const DrawingBoard: React.FC = () => {
Expand Down Expand Up @@ -42,7 +42,7 @@ const DrawingBoard: React.FC = () => {
const [ sizeLabel, setSizeLabel ] = useState<number>();

// colors
const isColorMenuRow = useMediaQuery(theme.breakpoints.between('xs', 'md'));
const isColorsMenuRow = useMediaQuery(theme.breakpoints.between('xs', 'md'));
const colorsMenu = useAppSelector((state) => state.room.drawing.colorsMenu);
const colors = useAppSelector((state) => state.room.drawing.colors);
const color = useAppSelector((state) => state.room.drawing.color);
Expand Down Expand Up @@ -161,12 +161,12 @@ const DrawingBoard: React.FC = () => {

/* colors menu */
useEffect(() => {
if (isColorMenuRow) {
if (isColorsMenuRow) {
dispatch(roomActions.setDrawingColorsMenu('Menu'));
} else {
dispatch(roomActions.setDrawingColorsMenu('Row'));
}
}, [ isColorMenuRow ]);
}, [ isColorsMenuRow ]);

/* history */
useEffect(() => {
Expand Down Expand Up @@ -389,7 +389,7 @@ const DrawingBoard: React.FC = () => {
}
};

const handleUsePaletteColor = (selectedColor: RoomState['drawing']['color']) => {
const handleUseColor = (selectedColor: RoomState['drawing']['color']) => {
dispatch(roomActions.setDrawingColor(selectedColor));

};
Expand Down Expand Up @@ -567,11 +567,11 @@ const DrawingBoard: React.FC = () => {
container
xs='auto'
>
<DrawingColorsPalette
<DrawingColors
type={colorsMenu}
paletteColors={colors}
paletteColor={color}
handleUsePaletteColor={handleUsePaletteColor}
colors={colors}
color={color}
handleUseColor={handleUseColor}
/>
</Grid>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import { RoomState } from '../../store/slices/roomSlice';

interface Props {
type: RoomState['drawing']['colorsMenu'];
paletteColors: RoomState['drawing']['colors'];
paletteColor: RoomState['drawing']['color'];
handleUsePaletteColor: (selectedColor: RoomState['drawing']['color']) => void; // eslint-disable-line
colors: RoomState['drawing']['colors'];
color: RoomState['drawing']['color'];
handleUseColor: (selectedColor: RoomState['drawing']['color']) => void; // eslint-disable-line
}

const DrawingColorsPalette: React.FC<Props> = (props) => {
const DrawingColors: React.FC<Props> = (props) => {

const Component = { Row, Menu }[props.type] || null;

return Component ? <Component {...props} /> : null;

};

export default DrawingColorsPalette;
export default DrawingColors;
20 changes: 10 additions & 10 deletions src/components/drawing/colorsMenus/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { useState } from 'react';
import { RoomState } from '../../../store/slices/roomSlice';

interface Props {
paletteColors: RoomState['drawing']['colors'];
paletteColor: RoomState['drawing']['color'];
handleUsePaletteColor: (selectedColor: RoomState['drawing']['color']) => void; // eslint-disable-line
colors: RoomState['drawing']['colors'];
color: RoomState['drawing']['color'];
handleUseColor: (selectedColor: RoomState['drawing']['color']) => void; // eslint-disable-line
}

const Menu: React.FC<Props> = (props) => {

const { paletteColors, paletteColor, handleUsePaletteColor } = props;
const { colors, color, handleUseColor } = props;

const [ anchorEl, setAnchorEl ] = useState<HTMLButtonElement | null>(null);

Expand All @@ -29,7 +29,7 @@ const Menu: React.FC<Props> = (props) => {
return <>
<IconButton
onClick={handleClick}
style={{ color: paletteColor, borderRadius: '50%' }}
style={{ color: color, borderRadius: '50%' }}
size='small'
>
<CircleIcon />
Expand Down Expand Up @@ -61,20 +61,20 @@ const Menu: React.FC<Props> = (props) => {
border={0}
>

{paletteColors.map((color) => (
{colors.map((value) => (
<Grid
item
key={color}
key={value}
>
{color !== paletteColor &&
{value !== color &&
<IconButton
onClick={() => {
handleClose();
handleUsePaletteColor(color);
handleUseColor(value);
}}
size='small'
>
<CircleIcon style={{ color: color, borderRadius: '50%' }} />
<CircleIcon style={{ color: value, borderRadius: '50%' }} />
</IconButton>
}
</Grid>
Expand Down
14 changes: 7 additions & 7 deletions src/components/drawing/colorsMenus/Row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ import CircleIcon from '@mui/icons-material/Circle';
import { RoomState } from '../../../store/slices/roomSlice';

interface Props {
paletteColors: RoomState['drawing']['colors'];
paletteColor: RoomState['drawing']['color'];
handleUsePaletteColor: (selectedColor: RoomState['drawing']['color']) => void; // eslint-disable-line
colors: RoomState['drawing']['colors'];
color: RoomState['drawing']['color'];
handleUseColor: (selectedColor: RoomState['drawing']['color']) => void; // eslint-disable-line
}

const Row: React.FC<Props> = (props) => {

const { paletteColors, paletteColor, handleUsePaletteColor } = props;
const { colors, color, handleUseColor } = props;

return <>
{paletteColors.map((value) => (
{colors.map((value) => (
<IconButton
key={value}
aria-label={`Use ${value} color`}
title={value}
onClick={() => handleUsePaletteColor(value)}
style={{ border: paletteColor === value ? '2px solid gray' : '2px solid lightgray' }}
onClick={() => handleUseColor(value)}
style={{ border: color === value ? '2px solid gray' : '2px solid lightgray' }}
size='small'
>
<CircleIcon
Expand Down

0 comments on commit 7b5372e

Please sign in to comment.