Skip to content

Commit

Permalink
Add sharing bgColor
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-drozd-it committed Oct 2, 2024
1 parent 81933d8 commit a52cf80
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/components/drawing/DrawingView.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useRef, useEffect, useState } from 'react';
import { useAppDispatch, useAppSelector } from '../../store/hooks';
import { drawingActions } from '../../store/slices/drawingSlice';
import { setDrawingBgColor } from '../../store/actions/drawingActions';
import { DrawingState } from '../../store/slices/drawingSlice';

import { fabric } from 'fabric';
Expand Down Expand Up @@ -411,7 +412,7 @@ const DrawingView = ({ width, height }: DrawingViewProps): JSX.Element => {
};

const handleUseBgColor = (selectedColor: DrawingState['bgColor']) => {
dispatch(drawingActions.setDrawingBgColor(selectedColor));
dispatch(setDrawingBgColor(selectedColor));

setCanvas((prevState) => {
if (prevState) {
Expand Down
24 changes: 23 additions & 1 deletion src/store/actions/drawingActions.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Logger } from '../../utils/Logger';
import { drawingActions } from '../slices/drawingSlice';
import { drawingActions, DrawingState } from '../slices/drawingSlice';
import { AppThunk } from '../store';

const logger = new Logger('DrawingActions');
Expand Down Expand Up @@ -41,4 +41,26 @@ AppThunk<Promise<void>> => async (
} catch (error) {
logger.error('moderator:disableDrawing() [error:"%o"]', error);
}
};

/**
* This thunk action set background color of drawing.
*
* @returns {AppThunk<Promise<void>>} Promise.
*/
export const setDrawingBgColor = (bgColor: DrawingState['bgColor']):
AppThunk<Promise<void>> => async (
dispatch,
getState,
{ signalingService }
): Promise<void> => {
logger.debug('setDrawingBgColor()');

try {
await signalingService.sendRequest('setDrawingBgColor', bgColor);

dispatch(drawingActions.setDrawingBgColor(bgColor));
} catch (error) {
logger.error('setDrawingBgColor() [error:"%o"]', error);
}
};
1 change: 1 addition & 0 deletions src/store/actions/roomActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export const joinRoom = (): AppThunk<Promise<void>> => async (
drawingActions.enableDrawing(true) :
drawingActions.disableDrawing(false)
);
dispatch(drawingActions.setDrawingBgColor(drawing.bgColor));
});

if (!getState().me.audioMuted) dispatch(updateMic());
Expand Down
9 changes: 9 additions & 0 deletions src/store/middlewares/drawingMiddleware.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ const createDrawingMiddleware = ({

break;
}

case 'settedDrawingBgColor': {

const bgColor = notification.data.bgColor;

dispatch(drawingActions.setDrawingBgColor(bgColor));

break;
}
}
} catch (error) {
logger.error('error on signalService "notification" event [error:%o]', error);
Expand Down

0 comments on commit a52cf80

Please sign in to comment.