import { AvatarDirectionAngle } from '@nitrots/nitro-renderer'; import { FC, useCallback, useEffect, useState } from 'react'; import { Base } from '../../../../common/Base'; import { Column } from '../../../../common/Column'; import { AvatarImageView } from '../../../../views/shared/avatar-image/AvatarImageView'; import { FigureData } from '../../common/FigureData'; import { AvatarEditorIcon } from '../AvatarEditorIcon'; export interface AvatarEditorFigurePreviewViewProps { figureData: FigureData; } export const AvatarEditorFigurePreviewView: FC = props => { const { figureData = null } = props; const [ updateId, setUpdateId ] = useState(-1); const rerender = useCallback(() => { setUpdateId(prevValue => (prevValue + 1)); }, []); const rotateFigure = useCallback((direction: number) => { if(direction < AvatarDirectionAngle.MIN_DIRECTION) { direction = (AvatarDirectionAngle.MAX_DIRECTION + (direction + 1)); } if(direction > AvatarDirectionAngle.MAX_DIRECTION) { direction = (direction - (AvatarDirectionAngle.MAX_DIRECTION + 1)); } figureData.direction = direction; }, [ figureData ]); useEffect(() => { if(!figureData) return; figureData.notify = rerender; return () => { figureData.notify = null; } }, [ figureData, rerender ] ); return ( rotateFigure(figureData.direction + 1) } /> rotateFigure(figureData.direction - 1) } /> ); }