Skip to content
Snippets Groups Projects
Select Git revision
  • 58aad63768df57764358ccd60f199faa04d53df9
  • mui5-annotation-on-video-stable default
  • get_setter_canvasSizeInformations
  • fix-error-div-into-p
  • annotation-on-video-v2
  • detached
  • annotation-on-video-r17
  • mui5
  • mui5-react-18
  • jacob-test
  • annotation-on-video protected
  • master
  • test-antoinev1
  • 20-fetch-thumbnail-on-annotation
  • add-research-field
  • Save
  • add-plugin
  • 14-wip-no-seek-to
  • 14-bug-on-video-time-control
  • 9_wip_videotests
  • _upgrade_material_ui
  • latest-tetras-16
  • v3.3.0
  • v3.2.0
  • v3.1.1
  • v3.1.0
  • v3.0.0
  • v3.0.0-rc.7
  • v3.0.0-rc.6
  • v3.0.0-rc.5
  • v3.0.0-rc.4
  • v3.0.0-rc.3
  • v3.0.0-rc.2
  • v3.0.0-rc.1
  • v3.0.0-beta.10
  • v3.0.0-beta.9
  • v3.0.0-beta.8
  • v3.0.0-beta.7
  • v3.0.0-beta.6
  • v3.0.0-beta.5
  • v3.0.0-beta.3
41 results

workspace.js

Blame
  • workspace.js 2.97 KiB
    import uuid from 'uuid/v4';
    import ActionTypes from '../actions/action-types';
    
    /** Check if the viewport dimensions are fully specified */
    function hasViewportPosition(viewportPosition) {
      return viewportPosition.x !== undefined
        && viewportPosition.y !== undefined
        && viewportPosition.width !== undefined
        && viewportPosition.height !== undefined;
    }
    
    /** Check if the containee is fully within the bounds on the container */
    function contains(container, containee) {
      return containee.x - containee.width / 2 > container.x - container.width / 2
        && containee.y - containee.height / 2 > container.y - container.height / 2
        && containee.x + containee.width / 2 < container.x + container.width / 2
        && containee.y + containee.height / 2 < container.y + container.height / 2;
    }
    
    /**
     * workspaceReducer
     */
    export const workspaceReducer = (
      state = { // we'll need to abstract this more, methinks.
        draggingEnabled: true,
        exposeModeOn: false,
        height: 5000,
        id: uuid(),
        viewportPosition: {
          x: 0,
          y: 0,
        },
        width: 5000,
      },
      action,
    ) => {
      let newWorkspaceDimensions;
      let viewportPosition;
      switch (action.type) {
        case ActionTypes.FOCUS_WINDOW:
          return {
            ...state,
            focusedWindowId: action.windowId,
            viewportPosition: {
              ...state.viewportPosition,
              ...action.position,
            },
          };
        case ActionTypes.ADD_WINDOW:
          return {
            ...state,
            focusedWindowId: action.window.id,
          };
        case ActionTypes.REMOVE_WINDOW:
          if (Object.keys(action.windows).length > 2) return state;
          return {
            ...state,
            focusedWindowId: Object.keys(action.windows).find(e => e !== action.windowId),
          };
        case ActionTypes.SET_WORKSPACE_FULLSCREEN:
          return { ...state, isFullscreenEnabled: action.isFullscreenEnabled };
        case ActionTypes.TOGGLE_ZOOM_CONTROLS:
          return { ...state, showZoomControls: action.showZoomControls };
        case ActionTypes.UPDATE_WORKSPACE_MOSAIC_LAYOUT:
          return { ...state, layout: action.layout };
        case ActionTypes.SET_WORKSPACE_VIEWPORT_POSITION:
          newWorkspaceDimensions = {};
    
          viewportPosition = {
            ...state.viewportPosition,
            ...action.payload.position,
          };
    
          if (
            hasViewportPosition(viewportPosition)
            && !contains({
              height: state.height, width: state.width, x: 0, y: 0,
            }, viewportPosition)
          ) {
            newWorkspaceDimensions = {
              height: state.height * 2,
              width: state.width * 2,
            };
          }
    
          return {
            ...state,
            ...newWorkspaceDimensions,
            viewportPosition,
          };
        case ActionTypes.TOGGLE_WORKSPACE_EXPOSE_MODE:
          return { ...state, exposeModeOn: !state.exposeModeOn };
        case ActionTypes.IMPORT_MIRADOR_STATE:
          return action.state.workspace;
        case ActionTypes.TOGGLE_DRAGGING:
          return { ...state, draggingEnabled: !state.draggingEnabled };
        default:
          return state;
      }
    };