Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@filerobot/explorer / lib / slices / views.slice.js
Size: Mime:
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
import { VIEW_IDS, AUTH_STATE, PLUGINS_IDS, LAYOUTS_IDS } from '@filerobot/utils/lib/constants';
import { createSlice, isAnyOf } from '@reduxjs/toolkit';
import { fetchUserAuthState, generateUserKey } from '@filerobot/core/lib/slices/user.slice';
import createThunk from '@filerobot/utils/lib/createThunk';
import { URL_PARAM_VIEW, VIEW_OPTIONS } from '../components/Views/Views.constants';
import { selectSearchQuery } from './search.slice';
import { selectIsFiltersActive } from './filters.slice';
import { fetchFoldersPreviews, selectFoldersArray } from './folders.slice';
var slicePropName = 'views';
var sliceName = "".concat(PLUGINS_IDS.EXPLORER, "/").concat(slicePropName);
var initialState = {
  layout: LAYOUTS_IDS.GRID,
  activeView: VIEW_IDS.FOLDERS,
  list: Object.values(VIEW_IDS)
};
export var changeView = createThunk(function (_ref, thunkApi) {
  var view = _ref.view,
    _ref$triggerActivate = _ref.triggerActivate,
    triggerActivate = _ref$triggerActivate === void 0 ? false : _ref$triggerActivate,
    activateOptions = _ref.activateOptions;
  var viewBeforeChange = selectActiveView(thunkApi.getState());
  var newlyActivatedView = viewBeforeChange;
  if (viewBeforeChange !== view) {
    thunkApi.dispatch(viewChanged(view));
    newlyActivatedView = selectActiveView(thunkApi.getState());
    var isViewChanged = viewBeforeChange !== newlyActivatedView; // double checking that the view is changed, as there is possibility for otherwise if wrong view id is provided
    if (isViewChanged) {
      thunkApi.extra.filerobot.getPlugin(PLUGINS_IDS.EXPLORER).deleteUrlQueryParams();
      if (triggerActivate && typeof VIEW_OPTIONS[newlyActivatedView].activateAction === 'function') {
        thunkApi.dispatch(VIEW_OPTIONS[newlyActivatedView].activateAction(_objectSpread({
          skipViewDispatch: true
        }, activateOptions)));
      }
      thunkApi.extra.filerobot.emit('view-changed', newlyActivatedView);
    }
  }
  return newlyActivatedView;
});
export var changeLayout = createThunk(function (newLayout, thunkApi) {
  thunkApi.dispatch(layoutChanged(newLayout));
  var isFoldersView = selectIsFoldersView(thunkApi.getState());
  if (isFoldersView && newLayout === LAYOUTS_IDS.GRID) {
    // If the first folder of current loaded folders doesn't contain value for previews property
    // means no previews request triggered before, so we are triggering it now.
    var firstFolder = selectFoldersArray(thunkApi.getState())[0];
    if (!firstFolder.previews) {
      thunkApi.dispatch(fetchFoldersPreviews({
        abortSignal: thunkApi.signal
      }));
    }
  }
});
export var activateViewFromUrl = createThunk(function (_, thunkApi) {
  var dispatch = thunkApi.dispatch,
    filerobot = thunkApi.extra.filerobot;
  var _filerobot$getPlugin = filerobot.getPlugin(PLUGINS_IDS.EXPLORER),
    getUrlQueryParam = _filerobot$getPlugin.getUrlQueryParam;
  Object.keys(URL_PARAM_VIEW).some(function (paramName) {
    var paramValue = getUrlQueryParam(paramName);
    if (paramValue) {
      URL_PARAM_VIEW[paramName].activateAction({
        dispatch: dispatch,
        paramValue: paramValue
      });
    }
    return paramValue;
  });
});
var viewsSlice = createSlice({
  name: sliceName,
  initialState: initialState,
  reducers: {
    viewChanged: function viewChanged(state, action) {
      var newView = action.payload;
      var currentViews = state.list;
      if (newView === state.activeView || !currentViews.includes(newView)) return state;
      return _objectSpread(_objectSpread({}, state), {}, {
        activeView: newView
      });
    },
    viewsChanged: function viewsChanged(state, action) {
      var newViews = action.payload.views || state.list;
      var isUserAuth = action.payload.authState === AUTH_STATE.AUTH;
      var viewsRequireUserAuth = [VIEW_IDS.FAVORITES, VIEW_IDS.LABELS, VIEW_IDS.COLLECTIONS];
      var allowedViews = isUserAuth ? newViews : newViews.filter(function (view) {
        return !viewsRequireUserAuth.includes(view);
      });
      return _objectSpread(_objectSpread({}, state), {}, {
        list: allowedViews
      });
    },
    layoutChanged: function layoutChanged(state, action) {
      return _objectSpread(_objectSpread({}, state), {}, {
        layout: action.payload
      });
    },
    viewsStateUpdated: function viewsStateUpdated(state, action) {
      return _objectSpread(_objectSpread({}, state), action.payload);
    }
  },
  extraReducers: function extraReducers(builder) {
    builder.addMatcher(isAnyOf(generateUserKey.fulfilled, fetchUserAuthState.fulfilled), viewsSlice.caseReducers.viewsChanged);
  }
});
var _viewsSlice$actions = viewsSlice.actions,
  viewChanged = _viewsSlice$actions.viewChanged,
  viewsChanged = _viewsSlice$actions.viewsChanged,
  layoutChanged = _viewsSlice$actions.layoutChanged,
  viewsStateUpdated = _viewsSlice$actions.viewsStateUpdated;
export { viewChanged, viewsChanged, layoutChanged, viewsStateUpdated };
export var selectViewsState = function selectViewsState(state) {
  return state[PLUGINS_IDS.EXPLORER][slicePropName];
};
export var selectActiveView = function selectActiveView(state) {
  return selectViewsState(state).activeView;
};
var checkViewActivation = function checkViewActivation(state, viewId) {
  return selectActiveView(state) === viewId;
};
var checkViewLayoutActivation = function checkViewLayoutActivation(state, layout) {
  return selectViewLayout(state) === layout;
};
export var selectAllViews = function selectAllViews(state) {
  return selectViewsState(state).list;
};
var checkViewAvailability = function checkViewAvailability(state, viewId) {
  return selectAllViews(state).includes(viewId);
};
export var selectIsLabelsViewAvailable = function selectIsLabelsViewAvailable(state) {
  return checkViewAvailability(state, VIEW_IDS.LABELS);
};
export var selectIsAssetsViewAvailable = function selectIsAssetsViewAvailable(state) {
  return checkViewAvailability(state, VIEW_IDS.ASSETS);
};
export var selectIsFavoritesViewAvailable = function selectIsFavoritesViewAvailable(state) {
  return checkViewAvailability(state, VIEW_IDS.FAVORITES);
};
export var selectIsCollectionsViewAvailable = function selectIsCollectionsViewAvailable(state) {
  return checkViewAvailability(state, VIEW_IDS.COLLECTIONS);
};
export var selectIsFoldersViewAvailable = function selectIsFoldersViewAvailable(state) {
  return checkViewAvailability(state, VIEW_IDS.FOLDERS);
};
export var selectIsSearchView = function selectIsSearchView(state) {
  return selectSearchQuery(state);
};
export var selectIsSearchOrFiltersView = function selectIsSearchOrFiltersView(state) {
  return !!selectSearchQuery(state) || !!selectIsFiltersActive(state);
};
export var selectIsLabelsView = function selectIsLabelsView(state) {
  return checkViewActivation(state, VIEW_IDS.LABELS);
};
export var selectIsCollectionsView = function selectIsCollectionsView(state) {
  return checkViewActivation(state, VIEW_IDS.COLLECTIONS);
};
export var selectIsAssetsView = function selectIsAssetsView(state) {
  return checkViewActivation(state, VIEW_IDS.ASSETS);
};
export var selectIsFavoritesView = function selectIsFavoritesView(state) {
  return checkViewActivation(state, VIEW_IDS.FAVORITES);
};
export var selectIsFoldersView = function selectIsFoldersView(state) {
  return checkViewActivation(state, VIEW_IDS.FOLDERS);
};
export var selectIsProductView = function selectIsProductView(state) {
  return checkViewActivation(state, VIEW_IDS.PRODUCTS);
};
export var selectIsShareboxView = function selectIsShareboxView(state) {
  return checkViewActivation(state, VIEW_IDS.SHAREBOX);
};
export var selectViewLayout = function selectViewLayout(state) {
  return selectViewsState(state).layout;
};
export var selectIsListLayout = function selectIsListLayout(state) {
  return checkViewLayoutActivation(state, LAYOUTS_IDS.LIST);
};
export var selectIsGridLayout = function selectIsGridLayout(state) {
  return checkViewLayoutActivation(state, LAYOUTS_IDS.GRID);
};
export var selectIsTilesLayout = function selectIsTilesLayout(state) {
  return checkViewLayoutActivation(state, LAYOUTS_IDS.TILES);
};
export default viewsSlice.reducer;