Web: Files: fixed files creation

This commit is contained in:
Nikita Gopienko 2021-03-04 18:44:30 +03:00
parent 63fec5b296
commit 4c1913c28a
5 changed files with 75 additions and 75 deletions

View File

@ -22,7 +22,6 @@ import FileActionsLockedIcon from "../../../../../../../public/images/file.actio
import CheckIcon from "../../../../../../../public/images/check.react.svg";
import CrossIcon from "../../../../../../../../../../public/images/cross.react.svg";
import { TIMEOUT } from "../../../../../../helpers/constants";
import { setEncryptionAccess } from "../../../../../../helpers/desktop";
import { getTitleWithoutExst } from "../../../../../../helpers/files-helpers";
import { NewFilesPanel } from "../../../../../panels";
import { ConvertDialog } from "../../../../../dialogs";
@ -130,8 +129,61 @@ class FilesRowContent extends React.PureComponent {
};
}
onSelectItem = (item) => {
const { selected, setSelected, setSelection } = this.props;
selected === "close" && setSelected("none");
setSelection([item]);
};
//TODO: move to actions, used in files row content and tile
onEditComplete = (id, isFolder) => {
const {
selectedFolderId,
fileAction,
filter,
folders,
files,
treeFolders,
setTreeFolders,
setIsLoading,
fetchFiles,
setAction,
} = this.props;
const selectedItem = this.props.item;
const items = [...folders, ...files];
const item = items.find((o) => o.id === id && !o.fileExst); //TODO maybe need files find and folders find, not at one function?
if (
fileAction.type === FileAction.Create ||
fileAction.type === FileAction.Rename
) {
setIsLoading(true);
fetchFiles(selectedFolderId, filter)
.then((data) => {
const newItem = (item && item.id) === -1 ? null : item; //TODO not add new folders?
if (isFolder) {
const path = data.selectedFolder.pathParts;
const newTreeFolders = treeFolders;
const folders = data.selectedFolder.folders;
loopTreeFolders(path, newTreeFolders, folders, null, newItem);
setTreeFolders(newTreeFolders);
}
})
.finally(() => {
setAction({ type: null, id: null, extension: null });
setIsLoading(false);
fileAction.type === FileAction.Rename &&
this.onSelectItem(selectedItem);
});
}
//this.setState({ editingId: null }, () => {
// setAction({type: null});
//});
};
completeAction = (id) => {
this.props.onEditComplete(id, !this.props.item.fileExst);
this.onEditComplete(id, !this.props.item.fileExst);
};
updateItem = (e) => {
@ -502,7 +554,6 @@ class FilesRowContent extends React.PureComponent {
canWebEdit,
/* canConvert,*/
sectionWidth,
editingId,
} = this.props;
const {
itemTitle,
@ -534,7 +585,7 @@ class FilesRowContent extends React.PureComponent {
const accessToEdit =
item.access === ShareAccessRights.FullAccess ||
item.access === ShareAccessRights.None; // TODO: fix access type for owner (now - None)
const isEdit = id === editingId && fileExst === fileAction.extension;
const isEdit = id === fileAction.id && fileExst === fileAction.extension;
const linkStyles =
isTrashFolder || window.innerWidth <= 1024
@ -785,6 +836,7 @@ export default inject(
} = formatsStore;
const {
files,
folders,
fetchFiles,
filter,
@ -795,6 +847,9 @@ export default inject(
renameFolder,
createFolder,
openDocEditor,
selected,
setSelected,
setSelection
} = filesStore;
const {
@ -806,7 +861,7 @@ export default inject(
addExpandedKeys,
} = treeFoldersStore;
const { type, extension, id, editingId } = filesStore.fileActionStore;
const { type, extension, id, setAction } = filesStore.fileActionStore;
const fileAction = { type, extension, id };
const {
@ -826,6 +881,7 @@ export default inject(
viewer: auth.userStore.user,
culture,
fileAction,
files,
folders,
selectedFolderId: selectedFolderStore.id,
selectedFolderPathParts: selectedFolderStore.pathParts,
@ -843,7 +899,7 @@ export default inject(
isSound,
newRowItems,
expandedKeys,
editingId,
selected,
setIsLoading,
fetchFiles,
@ -860,6 +916,9 @@ export default inject(
setEncryptionAccess,
addExpandedKeys,
openDocEditor,
setAction,
setSelected,
setSelection
};
}
)(withRouter(withTranslation("Home")(observer(FilesRowContent))));

View File

@ -103,13 +103,12 @@ const SimpleFilesRow = (props) => {
setIsVerHistoryPanel,
setVerHistoryFileId,
setAction,
setEditingId,
setSecondaryProgressBarData,
markItemAsFavorite,
removeItemFromFavorite,
getFileInfo,
fetchFavoritesFolder,
editingId,
actionId
} = props;
const {
@ -301,8 +300,6 @@ const SimpleFilesRow = (props) => {
};
const onClickRename = () => {
setEditingId(id);
setAction({
type: FileAction.Rename,
extension: fileExst,
@ -532,7 +529,7 @@ const SimpleFilesRow = (props) => {
const isMobile = sectionWidth < 500;
const isEdit =
!!actionType && editingId === id && fileExst === actionExtension;
!!actionType && actionId === id && fileExst === actionExtension;
const contextOptionsProps =
!isEdit && contextOptions && contextOptions.length > 0
@ -572,7 +569,6 @@ const SimpleFilesRow = (props) => {
element={element}
contentElement={sharedButton}
onSelect={onContentRowSelect}
editing={editingId}
isPrivacy={isPrivacy}
{...checkedProps}
{...contextOptionsProps}
@ -642,7 +638,7 @@ export default inject(
const { isRootFolder } = selectedFolderStore;
const { providers, capabilities } = settingsStore.thirdPartyStore;
const { setIsVerHistoryPanel, setVerHistoryFileId } = versionHistoryStore;
const { editingId, setAction, setEditingId } = fileActionStore;
const { setAction } = fileActionStore;
const {
setSecondaryProgressBarData,
} = uploadDataStore.secondaryProgressDataStore;
@ -678,7 +674,7 @@ export default inject(
isTabletView,
filter,
selectedFolderId: selectedFolderStore.id,
editingId,
actionId: fileActionStore.id,
fetchFiles,
setSharingPanelVisible,
@ -693,7 +689,6 @@ export default inject(
setIsLoading,
setIsVerHistoryPanel,
setVerHistoryFileId,
setEditingId,
setAction,
setSecondaryProgressBarData,
markItemAsFavorite,

View File

@ -341,55 +341,6 @@ class SectionBodyContent extends React.Component {
this.setState({ connectItem, connectDialogVisible: true });
}; */
//TODO: move to actions, used in files row content and tile
// onEditComplete = (id, isFolder) => {
// const {
// selectedFolderId,
// fileActionType,
// filter,
// folders,
// files,
// treeFolders,
// setTreeFolders,
// setIsLoading,
// fetchFiles,
// setAction,
// selection,
// } = this.props;
// const selectedItem = selection[0];
// const items = [...folders, ...files];
// const item = items.find((o) => o.id === id && !o.fileExst); //TODO maybe need files find and folders find, not at one function?
// if (
// fileActionType === FileAction.Create ||
// fileActionType === FileAction.Rename
// ) {
// setIsLoading(true);
// fetchFiles(selectedFolderId, filter)
// .then((data) => {
// const newItem = (item && item.id) === -1 ? null : item; //TODO not add new folders?
// if (isFolder) {
// const path = data.selectedFolder.pathParts;
// const newTreeFolders = treeFolders;
// const folders = data.selectedFolder.folders;
// loopTreeFolders(path, newTreeFolders, folders, null, newItem);
// setTreeFolders(newTreeFolders);
// }
// })
// .finally(() => {
// this.setState({ editingId: null }, () => {
// setAction({ type: null, id: null, extension: null });
// setIsLoading(false);
// });
// fileActionType === FileAction.Rename &&
// this.onSelectItem(selectedItem);
// });
// }
// //this.setState({ editingId: null }, () => {
// // setAction({type: null});
// //});
// };
/* onClickDelete = (e) => {
const { isThirdParty, id, title } = e.currentTarget.dataset;
const splitItem = id.split("-");
@ -1634,11 +1585,11 @@ class SectionBodyContent extends React.Component {
}
};
onSelectItem = (item) => {
const { selected, setSelected, setSelection } = this.props;
selected === "close" && setSelected("none");
setSelection([item]);
};
// onSelectItem = (item) => {
// const { selected, setSelected, setSelection } = this.props;
// selected === "close" && setSelected("none");
// setSelection([item]);
// };
/* getSharedButton = (shared) => {
const color = shared ? "#657077" : "#a3a9ae";

View File

@ -4,17 +4,14 @@ class FileActionStore {
id = null;
type = null;
extension = null;
editingId = null;
constructor() {
makeObservable(this, {
type: observable,
extension: observable,
id: observable,
editingId: observable,
setAction: action,
setEditingId: action,
});
}
@ -26,8 +23,6 @@ class FileActionStore {
}
}
};
setEditingId = (editingId) => (this.editingId = editingId);
}
export default FileActionStore;

View File

@ -17,7 +17,7 @@ class FilesActionStore {
makeAutoObservable(this);
}
onDeleteAction = (translations) => {
deleteAction = (translations) => {
if (confirmDelete) {
dialogsStore.setDeleteDialogVisible(false);
} else {