Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

reducer.ts 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import ReducerRegistry from '../base/redux/ReducerRegistry';
  2. import {
  3. REMOVE_TRANSCRIPT_MESSAGE,
  4. SET_REQUESTING_SUBTITLES, UPDATE_TRANSCRIPT_MESSAGE, UPDATE_TRANSLATION_LANGUAGE
  5. } from './actionTypes';
  6. /**
  7. * Default State for 'features/transcription' feature.
  8. */
  9. const defaultState = {
  10. _transcriptMessages: new Map(),
  11. _requestingSubtitles: false,
  12. _language: 'transcribing.subtitlesOff'
  13. };
  14. interface ITranscriptMessage {
  15. final: string;
  16. participantName: string;
  17. stable: string;
  18. unstable: string;
  19. }
  20. export interface ISubtitlesState {
  21. _language: string;
  22. _requestingSubtitles: boolean;
  23. _transcriptMessages: Map<string, ITranscriptMessage> | any;
  24. }
  25. /**
  26. * Listen for actions for the transcription feature to be used by the actions
  27. * to update the rendered transcription subtitles.
  28. */
  29. ReducerRegistry.register<ISubtitlesState>('features/subtitles', (
  30. state = defaultState, action): ISubtitlesState => {
  31. switch (action.type) {
  32. case REMOVE_TRANSCRIPT_MESSAGE:
  33. return _removeTranscriptMessage(state, action);
  34. case UPDATE_TRANSCRIPT_MESSAGE:
  35. return _updateTranscriptMessage(state, action);
  36. case UPDATE_TRANSLATION_LANGUAGE:
  37. return {
  38. ...state,
  39. _language: action.value
  40. };
  41. case SET_REQUESTING_SUBTITLES:
  42. return {
  43. ...state,
  44. _requestingSubtitles: action.enabled
  45. };
  46. }
  47. return state;
  48. });
  49. /**
  50. * Reduces a specific Redux action REMOVE_TRANSCRIPT_MESSAGE of the feature
  51. * transcription.
  52. *
  53. * @param {Object} state - The Redux state of the feature transcription.
  54. * @param {Action} action -The Redux action REMOVE_TRANSCRIPT_MESSAGE to reduce.
  55. * @returns {Object} The new state of the feature transcription after the
  56. * reduction of the specified action.
  57. */
  58. function _removeTranscriptMessage(state: ISubtitlesState, { transcriptMessageID }: { transcriptMessageID: string; }) {
  59. const newTranscriptMessages = new Map(state._transcriptMessages);
  60. // Deletes the key from Map once a final message arrives.
  61. newTranscriptMessages.delete(transcriptMessageID);
  62. return {
  63. ...state,
  64. _transcriptMessages: newTranscriptMessages
  65. };
  66. }
  67. /**
  68. * Reduces a specific Redux action UPDATE_TRANSCRIPT_MESSAGE of the feature
  69. * transcription.
  70. *
  71. * @param {Object} state - The Redux state of the feature transcription.
  72. * @param {Action} action -The Redux action UPDATE_TRANSCRIPT_MESSAGE to reduce.
  73. * @returns {Object} The new state of the feature transcription after the
  74. * reduction of the specified action.
  75. */
  76. function _updateTranscriptMessage(state: ISubtitlesState, { transcriptMessageID, newTranscriptMessage }:
  77. { newTranscriptMessage: ITranscriptMessage; transcriptMessageID: string; }) {
  78. const newTranscriptMessages = new Map(state._transcriptMessages);
  79. // Updates the new message for the given key in the Map.
  80. newTranscriptMessages.set(transcriptMessageID, newTranscriptMessage);
  81. return {
  82. ...state,
  83. _transcriptMessages: newTranscriptMessages
  84. };
  85. }