Repository URL to install this package:
|
Version:
3.12.11 ▾
|
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 { createSlice } from '@reduxjs/toolkit';
import { PLUGINS_IDS } from '@filerobot/utils/lib/constants';
import { fetchUserAuthState, generateUserKey } from './user.slice';
/**
* The order of the code in slice file is:
* 1. initialState (*No* export needed)
* 2. automated thunks functions -- uses createThunk API-- (export needed)
* 3. createSlice (*No* export needed)
* 4. actions exports
* 5. selectors (export needed)
* 6. default reducer export
*
*/
export var slicePropName = 'common';
var sliceName = "".concat(PLUGINS_IDS.CORE, "/").concat(slicePropName);
var initialState = {
loading: true,
companion: {},
xhrUpload: {},
imageProcessor: {},
videoTranscoding: {},
fromDragging: false,
dndTargetFolderPath: '',
isDragging: false,
isRelevanceAvailable: false,
isDevEnv: false // retrieved from opts.dev
// isRelevanceAvailable: localStorage.getItem('show-relevance') === 'true' (needed in explorer only)
};
var commonSlice = createSlice({
name: sliceName,
initialState: initialState,
reducers: {
loadingSet: function loadingSet(state, action) {
return _objectSpread(_objectSpread({}, state), {}, {
loading: action.payload
});
},
coreCommonStateUpdated: function coreCommonStateUpdated(state, action) {
return _objectSpread(_objectSpread({}, state), action.payload);
}
},
extraReducers: function extraReducers(builder) {
builder
// We don't need to add extraReducer for .pending case, as by default the app starts in loading: true state,
// User might hit the refreshment of sass key generation before getting expired, so we don't need to set loading to true
// to avoid bothering the user, it's better to done in the background.
.addMatcher(function (_ref) {
var type = _ref.type;
return [generateUserKey.fulfilled.type, fetchUserAuthState.fulfilled.type].includes(type);
}, function (state, action) {
return _objectSpread(_objectSpread({}, state), {}, {
loading: false
});
}).addMatcher(function (_ref2) {
var type = _ref2.type;
return [generateUserKey.rejected.type, fetchUserAuthState.rejected.type].includes(type);
}, function (state, action) {
return _objectSpread(_objectSpread({}, state), {}, {
error: action.error,
loading: false
});
});
}
});
var _commonSlice$actions = commonSlice.actions,
loadingSet = _commonSlice$actions.loadingSet,
coreCommonStateUpdated = _commonSlice$actions.coreCommonStateUpdated;
export { loadingSet, coreCommonStateUpdated };
export var selectCommonState = function selectCommonState(state) {
return state[PLUGINS_IDS.CORE][slicePropName];
};
// !TODO: This is not appropriate as it will be undefined in-case explorer isn't there, so maybe better to remove it.
// Local selector "selectCurrentFolderPath" was created because of the error "failed to initialize ..." if we try to import via @filerobot..../slice.. inside core/src/index.js
export var selectCurrentFolderPath = function selectCurrentFolderPath(state) {
var _state$PLUGINS_IDS$EX, _state$PLUGINS_IDS$EX2, _state$PLUGINS_IDS$EX3, _state$PLUGINS_IDS$EX4, _state$PLUGINS_IDS$EX5;
return ((_state$PLUGINS_IDS$EX = state[PLUGINS_IDS.EXPLORER]) === null || _state$PLUGINS_IDS$EX === void 0 ? void 0 : (_state$PLUGINS_IDS$EX2 = _state$PLUGINS_IDS$EX.folders) === null || _state$PLUGINS_IDS$EX2 === void 0 ? void 0 : (_state$PLUGINS_IDS$EX3 = _state$PLUGINS_IDS$EX2.currentFolder) === null || _state$PLUGINS_IDS$EX3 === void 0 ? void 0 : _state$PLUGINS_IDS$EX3.path) || ((_state$PLUGINS_IDS$EX4 = state[PLUGINS_IDS.EXPLORER]) === null || _state$PLUGINS_IDS$EX4 === void 0 ? void 0 : (_state$PLUGINS_IDS$EX5 = _state$PLUGINS_IDS$EX4.folders) === null || _state$PLUGINS_IDS$EX5 === void 0 ? void 0 : _state$PLUGINS_IDS$EX5.baseFolderPath);
};
export var selectCoreLoading = function selectCoreLoading(state) {
return selectCommonState(state).loading;
};
export var selectIsRelevanceAvailable = function selectIsRelevanceAvailable(state) {
return selectCommonState(state).isRelevanceAvailable;
};
export default commonSlice.reducer;