replayPlayPauseButton.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import type {BaseButtonProps} from 'sentry/components/button';
  2. import {Button} from 'sentry/components/button';
  3. import {IconPause, IconPlay, IconRefresh} from 'sentry/icons';
  4. import {t} from 'sentry/locale';
  5. import {
  6. useReplayPlayerState,
  7. useReplayUserAction,
  8. } from 'sentry/utils/replays/playback/providers/replayPlayerStateContext';
  9. export default function ReplayPlayPauseButton(props: BaseButtonProps) {
  10. const userAction = useReplayUserAction();
  11. const {playerState, isFinished} = useReplayPlayerState();
  12. const isPlaying = playerState === 'playing';
  13. return isFinished ? (
  14. <Button
  15. title={t('Restart Replay')}
  16. icon={<IconRefresh />}
  17. onClick={() => {
  18. userAction({type: 'jumpToOffset', offsetMs: 0});
  19. userAction({type: 'play'});
  20. }}
  21. aria-label={t('Restart Replay')}
  22. priority="primary"
  23. {...props}
  24. />
  25. ) : (
  26. <Button
  27. title={isPlaying ? t('Pause') : t('Play')}
  28. icon={isPlaying ? <IconPause /> : <IconPlay />}
  29. onClick={() => userAction(isPlaying ? {type: 'pause'} : {type: 'play'})}
  30. aria-label={isPlaying ? t('Pause') : t('Play')}
  31. priority="primary"
  32. {...props}
  33. />
  34. );
  35. }