init
This commit is contained in:
1123
src/redux/explorer/action.ts
Normal file
1123
src/redux/explorer/action.ts
Normal file
File diff suppressed because it is too large
Load Diff
88
src/redux/explorer/async.ts
Normal file
88
src/redux/explorer/async.ts
Normal file
@@ -0,0 +1,88 @@
|
||||
import { ThunkAction } from "redux-thunk";
|
||||
import Auth from "../../middleware/Auth";
|
||||
import pathHelper from "../../utils/page";
|
||||
import { closeAllModals, confirmPurchase, toggleSnackbar } from "./index";
|
||||
import { setOptionModal } from "../viewUpdate/action";
|
||||
import i18next from "../../i18n";
|
||||
|
||||
export const askForOption = (
|
||||
options: any,
|
||||
title: string
|
||||
): ThunkAction<any, any, any, any> => {
|
||||
return async (dispatch, getState): Promise<any> => {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
const dialog = {
|
||||
open: true,
|
||||
title: title,
|
||||
options: options,
|
||||
};
|
||||
dispatch(
|
||||
setOptionModal({
|
||||
...dialog,
|
||||
onClose: () => {
|
||||
dispatch(setOptionModal({ ...dialog, open: false }));
|
||||
reject(i18next.t("fileManager.userDenied"));
|
||||
},
|
||||
callback: (option: any) => {
|
||||
resolve(option);
|
||||
dispatch(setOptionModal({ ...dialog, open: false }));
|
||||
},
|
||||
})
|
||||
);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
const purchased = new Map<string, boolean>();
|
||||
|
||||
export const trySharePurchase = (
|
||||
share: any
|
||||
): ThunkAction<any, any, any, any> => {
|
||||
return async (dispatch, getState): Promise<void> => {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
const {
|
||||
router: {
|
||||
location: { pathname },
|
||||
},
|
||||
} = getState();
|
||||
if (pathHelper.isSharePage(pathname) && share && share.score > 0) {
|
||||
if (!Auth.Check()) {
|
||||
dispatch(
|
||||
toggleSnackbar(
|
||||
"top",
|
||||
"right",
|
||||
i18next.t("share.pleaseLogin"),
|
||||
"warning"
|
||||
)
|
||||
);
|
||||
dispatch(closeAllModals());
|
||||
reject(i18next.t("fileManager.userDenied"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
!Auth.GetUser().group.shareFree &&
|
||||
!purchased.has(share.key)
|
||||
) {
|
||||
dispatch(
|
||||
confirmPurchase({
|
||||
score: share.score,
|
||||
onClose: () => {
|
||||
dispatch(confirmPurchase(undefined));
|
||||
reject(i18next.t("fileManager.userDenied"));
|
||||
},
|
||||
callback: () => {
|
||||
purchased.set(share.key, true);
|
||||
resolve();
|
||||
dispatch(confirmPurchase(undefined));
|
||||
},
|
||||
})
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
resolve();
|
||||
});
|
||||
};
|
||||
};
|
300
src/redux/explorer/index.ts
Normal file
300
src/redux/explorer/index.ts
Normal file
@@ -0,0 +1,300 @@
|
||||
import * as actions from "./action";
|
||||
import * as reducers from "./reducer";
|
||||
import { setPagination } from "../viewUpdate/action";
|
||||
|
||||
export default {
|
||||
actions,
|
||||
reducers,
|
||||
};
|
||||
export { selectFile } from "./action";
|
||||
export { openPreview } from "./action";
|
||||
export { setShiftSelectedIds } from "./action";
|
||||
export { setLastSelect } from "./action";
|
||||
export { setSelectedTarget } from "./action";
|
||||
export { addSelectedTargets } from "./action";
|
||||
export { removeSelectedTargets } from "./action";
|
||||
export const setNavigator = (path: any, navigatorLoading: any) => {
|
||||
return {
|
||||
type: "SET_NAVIGATOR",
|
||||
path,
|
||||
navigatorLoading,
|
||||
};
|
||||
};
|
||||
export const navigateTo = (path: any) => {
|
||||
return (dispatch: any, getState: any) => {
|
||||
const state = getState();
|
||||
const navigatorLoading = path !== state.navigator.path;
|
||||
if (navigatorLoading) {
|
||||
dispatch(
|
||||
setPagination({
|
||||
...state.viewUpdate.pagination,
|
||||
page: 1,
|
||||
})
|
||||
);
|
||||
}
|
||||
dispatch(setNavigator(path, navigatorLoading));
|
||||
};
|
||||
};
|
||||
export const navigateUp = () => {
|
||||
return (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const pathSplit = state.navigator.path.split("/");
|
||||
pathSplit.pop();
|
||||
const newPath = pathSplit.length === 1 ? "/" : pathSplit.join("/");
|
||||
const navigatorLoading = newPath !== state.navigator.path;
|
||||
if (navigatorLoading) {
|
||||
dispatch(
|
||||
setPagination({
|
||||
...state.viewUpdate.pagination,
|
||||
page: 1,
|
||||
})
|
||||
);
|
||||
}
|
||||
dispatch(setNavigator(newPath, navigatorLoading));
|
||||
};
|
||||
};
|
||||
export const drawerToggleAction = (open) => {
|
||||
return {
|
||||
type: "DRAWER_TOGGLE",
|
||||
open: open,
|
||||
};
|
||||
};
|
||||
export const dragAndDrop = (source, target) => {
|
||||
return {
|
||||
type: "DRAG_AND_DROP",
|
||||
source: source,
|
||||
target: target,
|
||||
};
|
||||
};
|
||||
export const changeViewMethod = (method) => {
|
||||
return {
|
||||
type: "CHANGE_VIEW_METHOD",
|
||||
method: method,
|
||||
};
|
||||
};
|
||||
export const toggleDaylightMode = () => {
|
||||
return {
|
||||
type: "TOGGLE_DAYLIGHT_MODE",
|
||||
};
|
||||
};
|
||||
// Deprecated
|
||||
export const changeContextMenu = (type, open) => {
|
||||
return {
|
||||
type: "CHANGE_CONTEXT_MENU",
|
||||
menuType: type,
|
||||
open: open,
|
||||
};
|
||||
};
|
||||
export const setNavigatorLoadingStatus = (status) => {
|
||||
return {
|
||||
type: "SET_NAVIGATOR_LOADING_STATUE",
|
||||
status: status,
|
||||
};
|
||||
};
|
||||
export const setNavigatorError = (status, msg) => {
|
||||
return {
|
||||
type: "SET_NAVIGATOR_ERROR",
|
||||
status: status,
|
||||
msg: msg,
|
||||
};
|
||||
};
|
||||
export const openCreateFolderDialog = () => {
|
||||
return {
|
||||
type: "OPEN_CREATE_FOLDER_DIALOG",
|
||||
};
|
||||
};
|
||||
export const openCreateFileDialog = () => {
|
||||
return {
|
||||
type: "OPEN_CREATE_FILE_DIALOG",
|
||||
};
|
||||
};
|
||||
export const setUserPopover = (anchor) => {
|
||||
return {
|
||||
type: "SET_USER_POPOVER",
|
||||
anchor: anchor,
|
||||
};
|
||||
};
|
||||
export const setShareUserPopover = (anchor) => {
|
||||
return {
|
||||
type: "SET_SHARE_USER_POPOVER",
|
||||
anchor: anchor,
|
||||
};
|
||||
};
|
||||
export const openRenameDialog = () => {
|
||||
return {
|
||||
type: "OPEN_RENAME_DIALOG",
|
||||
};
|
||||
};
|
||||
export const openResaveDialog = (key) => {
|
||||
return {
|
||||
type: "OPEN_RESAVE_DIALOG",
|
||||
key: key,
|
||||
};
|
||||
};
|
||||
export const openMoveDialog = () => {
|
||||
return {
|
||||
type: "OPEN_MOVE_DIALOG",
|
||||
};
|
||||
};
|
||||
export const openRemoveDialog = () => {
|
||||
return {
|
||||
type: "OPEN_REMOVE_DIALOG",
|
||||
};
|
||||
};
|
||||
export const openShareDialog = () => {
|
||||
return {
|
||||
type: "OPEN_SHARE_DIALOG",
|
||||
};
|
||||
};
|
||||
export const applyThemes = (theme) => {
|
||||
return {
|
||||
type: "APPLY_THEME",
|
||||
theme: theme,
|
||||
};
|
||||
};
|
||||
export const setSessionStatus = (status) => {
|
||||
return {
|
||||
type: "SET_SESSION_STATUS",
|
||||
status: status,
|
||||
};
|
||||
};
|
||||
export const openMusicDialog = () => {
|
||||
return {
|
||||
type: "OPEN_MUSIC_DIALOG",
|
||||
};
|
||||
};
|
||||
export const openRemoteDownloadDialog = () => {
|
||||
return {
|
||||
type: "OPEN_REMOTE_DOWNLOAD_DIALOG",
|
||||
};
|
||||
};
|
||||
export const openTorrentDownloadDialog = (selected) => {
|
||||
return {
|
||||
type: "OPEN_TORRENT_DOWNLOAD_DIALOG",
|
||||
selected:selected,
|
||||
};
|
||||
};
|
||||
export const openDecompressDialog = () => {
|
||||
return {
|
||||
type: "OPEN_DECOMPRESS_DIALOG",
|
||||
};
|
||||
};
|
||||
export const openCompressDialog = () => {
|
||||
return {
|
||||
type: "OPEN_COMPRESS_DIALOG",
|
||||
};
|
||||
};
|
||||
export const openRelocateDialog = () => {
|
||||
return {
|
||||
type: "OPEN_RELOCATE_DIALOG",
|
||||
};
|
||||
};
|
||||
export const openGetSourceDialog = (source) => {
|
||||
return {
|
||||
type: "OPEN_GET_SOURCE_DIALOG",
|
||||
source,
|
||||
};
|
||||
};
|
||||
export const openCopyDialog = () => {
|
||||
return {
|
||||
type: "OPEN_COPY_DIALOG",
|
||||
};
|
||||
};
|
||||
// Deprecated
|
||||
export const openLoadingDialog = (text) => {
|
||||
return {
|
||||
type: "OPEN_LOADING_DIALOG",
|
||||
text: text,
|
||||
};
|
||||
};
|
||||
// Deprecated
|
||||
export const closeAllModals = () => {
|
||||
return {
|
||||
type: "CLOSE_ALL_MODALS",
|
||||
};
|
||||
};
|
||||
export const toggleSnackbar = (vertical, horizontal, msg, color) => {
|
||||
return {
|
||||
type: "TOGGLE_SNACKBAR",
|
||||
vertical: vertical,
|
||||
horizontal: horizontal,
|
||||
msg: msg,
|
||||
color: color,
|
||||
};
|
||||
};
|
||||
export const setModalsLoading = (status) => {
|
||||
return {
|
||||
type: "SET_MODALS_LOADING",
|
||||
status: status,
|
||||
};
|
||||
};
|
||||
export const refreshFileList = () => {
|
||||
return {
|
||||
type: "REFRESH_FILE_LIST",
|
||||
};
|
||||
};
|
||||
export const searchMyFile = (keywords, path) => {
|
||||
return {
|
||||
type: "SEARCH_MY_FILE",
|
||||
keywords: keywords,
|
||||
path: path,
|
||||
};
|
||||
};
|
||||
export const showImgPreivew = (first) => {
|
||||
return {
|
||||
type: "SHOW_IMG_PREIVEW",
|
||||
first: first,
|
||||
};
|
||||
};
|
||||
export const showAudioPreview = (first) => {
|
||||
return {
|
||||
type: "SHOW_AUDIO_PREVIEW",
|
||||
first: first,
|
||||
};
|
||||
};
|
||||
export const audioPreviewSetIsOpen = (isOpen) => {
|
||||
return {
|
||||
type: "AUDIO_PREVIEW_SET_IS_OPEN",
|
||||
isOpen,
|
||||
};
|
||||
};
|
||||
export const audioPreviewSetPlaying = (playingName, paused) => {
|
||||
return {
|
||||
type: "AUDIO_PREVIEW_SET_PLAYING",
|
||||
playingName, //the playing content name
|
||||
paused,
|
||||
};
|
||||
};
|
||||
export const refreshStorage = () => {
|
||||
return {
|
||||
type: "REFRESH_STORAGE",
|
||||
};
|
||||
};
|
||||
export const saveFile = () => {
|
||||
return {
|
||||
type: "SAVE_FILE",
|
||||
};
|
||||
};
|
||||
|
||||
export const setSiteConfig = (config) => {
|
||||
return {
|
||||
type: "SET_SITE_CONFIG",
|
||||
config: config,
|
||||
};
|
||||
};
|
||||
|
||||
export const openDirectoryDownloadDialog = (downloading, log, done) => {
|
||||
return {
|
||||
type: "OPEN_DIRECTORY_DOWNLOAD_DIALOG",
|
||||
downloading,
|
||||
log,
|
||||
done,
|
||||
};
|
||||
};
|
||||
|
||||
export const confirmPurchase = (purchase) => {
|
||||
return {
|
||||
type: "CONFIRM_PURCHASE",
|
||||
purchase: purchase,
|
||||
};
|
||||
};
|
278
src/redux/explorer/reducer.ts
Normal file
278
src/redux/explorer/reducer.ts
Normal file
@@ -0,0 +1,278 @@
|
||||
/* eslint-disable no-case-declarations */
|
||||
import { AnyAction } from "redux";
|
||||
import { CloudreveFile } from "../../types";
|
||||
import { Policy } from "../../component/Uploader/core/types";
|
||||
|
||||
interface SelectProps {
|
||||
isMultiple: boolean;
|
||||
withFolder: boolean;
|
||||
withFile: boolean;
|
||||
withSourceEnabled: boolean;
|
||||
}
|
||||
|
||||
export interface ExplorerState {
|
||||
dndSignal: boolean;
|
||||
dndTarget: any;
|
||||
dndSource: any;
|
||||
fileList: CloudreveFile[];
|
||||
dirList: CloudreveFile[];
|
||||
selected: CloudreveFile[];
|
||||
selectProps: SelectProps;
|
||||
lastSelect: {
|
||||
file: CloudreveFile;
|
||||
index: number;
|
||||
};
|
||||
shiftSelectedIds: string[];
|
||||
imgPreview: {
|
||||
first: CloudreveFile;
|
||||
other: [];
|
||||
};
|
||||
audioPreview: {
|
||||
first: CloudreveFile;
|
||||
other: [];
|
||||
playingName: any;
|
||||
paused: boolean;
|
||||
isOpen: boolean;
|
||||
};
|
||||
search?: {
|
||||
keywords: string;
|
||||
searchPath: string;
|
||||
};
|
||||
fileSave: boolean;
|
||||
sideBarOpen: boolean;
|
||||
currentPolicy?: Policy;
|
||||
purchase?: {
|
||||
callback: any;
|
||||
onClose: any;
|
||||
score: number;
|
||||
};
|
||||
}
|
||||
|
||||
export const initState: ExplorerState = {
|
||||
dndSignal: false,
|
||||
dndTarget: null,
|
||||
dndSource: null,
|
||||
fileList: [],
|
||||
dirList: [],
|
||||
selected: [],
|
||||
selectProps: {
|
||||
isMultiple: false,
|
||||
withFolder: false,
|
||||
withFile: false,
|
||||
withSourceEnabled: false,
|
||||
},
|
||||
lastSelect: {
|
||||
file: {
|
||||
id: "",
|
||||
name: "",
|
||||
size: 0,
|
||||
type: "file",
|
||||
date: "",
|
||||
path: "",
|
||||
create_date: "",
|
||||
},
|
||||
index: -1,
|
||||
},
|
||||
shiftSelectedIds: [],
|
||||
imgPreview: {
|
||||
first: {
|
||||
id: "",
|
||||
name: "",
|
||||
size: 0,
|
||||
type: "file",
|
||||
date: "",
|
||||
path: "",
|
||||
create_date: "",
|
||||
},
|
||||
other: [],
|
||||
},
|
||||
audioPreview: {
|
||||
first: {
|
||||
id: "",
|
||||
name: "",
|
||||
size: 0,
|
||||
type: "file",
|
||||
date: "",
|
||||
path: "",
|
||||
create_date: "",
|
||||
},
|
||||
other: [],
|
||||
playingName: null,
|
||||
paused: false,
|
||||
isOpen: false,
|
||||
},
|
||||
fileSave: false,
|
||||
sideBarOpen: false,
|
||||
};
|
||||
|
||||
const checkSelectedProps = (selected: CloudreveFile[]): SelectProps => {
|
||||
const isMultiple = selected.length > 1;
|
||||
let withFolder = false;
|
||||
let withFile = false;
|
||||
let withSourceEnabled = false;
|
||||
selected.forEach((value) => {
|
||||
if (value.type === "dir") {
|
||||
withFolder = true;
|
||||
withSourceEnabled = true;
|
||||
} else if (value.type === "file") {
|
||||
withFile = true;
|
||||
if (value.source_enabled) {
|
||||
withSourceEnabled = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
return {
|
||||
isMultiple,
|
||||
withFolder,
|
||||
withFile,
|
||||
withSourceEnabled,
|
||||
};
|
||||
};
|
||||
|
||||
const explorer = (
|
||||
state: ExplorerState = initState,
|
||||
action: AnyAction
|
||||
): ExplorerState => {
|
||||
switch (action.type) {
|
||||
case "DRAG_AND_DROP":
|
||||
return Object.assign({}, state, {
|
||||
dndSignal: !state.dndSignal,
|
||||
dndTarget: action.target,
|
||||
dndSource: action.source,
|
||||
});
|
||||
case "SET_FILE_LIST":
|
||||
return Object.assign({}, state, {
|
||||
fileList: action.list,
|
||||
});
|
||||
case "SET_DIR_LIST":
|
||||
return Object.assign({}, state, {
|
||||
dirList: action.list,
|
||||
});
|
||||
case "ADD_SELECTED_TARGETS":
|
||||
const addedSelected = [...state.selected, ...action.targets];
|
||||
return Object.assign({}, state, {
|
||||
selected: addedSelected,
|
||||
selectProps: checkSelectedProps(addedSelected),
|
||||
});
|
||||
case "SET_SELECTED_TARGET":
|
||||
const newSelected = action.targets;
|
||||
return Object.assign({}, state, {
|
||||
selected: newSelected,
|
||||
selectProps: checkSelectedProps(newSelected),
|
||||
});
|
||||
case "RMOVE_SELECTED_TARGETS":
|
||||
const { fileIds } = action;
|
||||
const filteredSelected = state.selected.filter((file) => {
|
||||
return !fileIds.includes(file.id);
|
||||
});
|
||||
return Object.assign({}, state, {
|
||||
selected: filteredSelected,
|
||||
selectProps: checkSelectedProps(filteredSelected),
|
||||
});
|
||||
case "REFRESH_FILE_LIST":
|
||||
return Object.assign({}, state, {
|
||||
selected: [],
|
||||
selectProps: {
|
||||
isMultiple: false,
|
||||
withFolder: false,
|
||||
withFile: false,
|
||||
withSourceEnabled: false,
|
||||
},
|
||||
});
|
||||
case "SEARCH_MY_FILE":
|
||||
return Object.assign({}, state, {
|
||||
selected: [],
|
||||
selectProps: {
|
||||
isMultiple: false,
|
||||
withFolder: false,
|
||||
withFile: false,
|
||||
withSourceEnabled: false,
|
||||
},
|
||||
search: {
|
||||
keywords: action.keywords,
|
||||
searchPath: action.path,
|
||||
},
|
||||
});
|
||||
case "SHOW_IMG_PREIVEW":
|
||||
return Object.assign({}, state, {
|
||||
imgPreview: {
|
||||
first: action.first,
|
||||
other: state.fileList,
|
||||
},
|
||||
});
|
||||
case "SHOW_AUDIO_PREVIEW":
|
||||
return Object.assign({}, state, {
|
||||
audioPreview: {
|
||||
...state.audioPreview,
|
||||
first: action.first,
|
||||
other: state.fileList,
|
||||
},
|
||||
});
|
||||
case "AUDIO_PREVIEW_SET_IS_OPEN":
|
||||
return Object.assign({}, state, {
|
||||
audioPreview: {
|
||||
...state.audioPreview,
|
||||
isOpen: action.isOpen,
|
||||
},
|
||||
});
|
||||
case "AUDIO_PREVIEW_SET_PLAYING":
|
||||
return Object.assign({}, state, {
|
||||
audioPreview: {
|
||||
...state.audioPreview,
|
||||
playingName: action.playingName,
|
||||
paused: action.paused,
|
||||
},
|
||||
});
|
||||
case "SAVE_FILE":
|
||||
return {
|
||||
...state,
|
||||
fileSave: !state.fileSave,
|
||||
};
|
||||
case "SET_LAST_SELECT":
|
||||
const { file, index } = action;
|
||||
return {
|
||||
...state,
|
||||
lastSelect: {
|
||||
file,
|
||||
index,
|
||||
},
|
||||
};
|
||||
case "SET_SHIFT_SELECTED_IDS":
|
||||
const { shiftSelectedIds } = action;
|
||||
return {
|
||||
...state,
|
||||
shiftSelectedIds,
|
||||
};
|
||||
case "SET_NAVIGATOR":
|
||||
return {
|
||||
...state,
|
||||
selected: [],
|
||||
selectProps: {
|
||||
isMultiple: false,
|
||||
withFolder: false,
|
||||
withFile: false,
|
||||
withSourceEnabled: false,
|
||||
},
|
||||
search: undefined,
|
||||
};
|
||||
case "SET_SIDE_BAR":
|
||||
return {
|
||||
...state,
|
||||
sideBarOpen: action.open,
|
||||
};
|
||||
case "SET_CURRENT_POLICY":
|
||||
return {
|
||||
...state,
|
||||
currentPolicy: action.policy,
|
||||
};
|
||||
case "CONFIRM_PURCHASE":
|
||||
return {
|
||||
...state,
|
||||
purchase: action.purchase,
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export default explorer;
|
Reference in New Issue
Block a user