From ae49bed70f0b333b28ff1f7a437cb4f0909752ba Mon Sep 17 00:00:00 2001
From: yinjianfei <1358009667@qq.com>
Date: Sat, 6 Jan 2024 14:17:43 +0800
Subject: [PATCH 1/6] add-external
---
.../sdoc/sdoc-editor/external-operations.js | 41 ++++++++++++++++++-
frontend/src/pages/sdoc/sdoc-editor/index.js | 37 ++++++++++++++++-
2 files changed, 74 insertions(+), 4 deletions(-)
diff --git a/frontend/src/pages/sdoc/sdoc-editor/external-operations.js b/frontend/src/pages/sdoc/sdoc-editor/external-operations.js
index 878e6a6addb..aef441c760e 100644
--- a/frontend/src/pages/sdoc/sdoc-editor/external-operations.js
+++ b/frontend/src/pages/sdoc/sdoc-editor/external-operations.js
@@ -6,6 +6,7 @@ import { Utils } from '../../../utils/utils';
import toaster from '../../../components/toast';
import InternalLinkDialog from '../../../components/dialog/internal-link-dialog';
import ShareDialog from '../../../components/dialog/share-dialog';
+import CreateFile from '../../../components/dialog/create-file-dialog';
const propTypes = {
repoID: PropTypes.string.isRequired,
@@ -13,6 +14,8 @@ const propTypes = {
docName: PropTypes.string.isRequired,
docPerm: PropTypes.string.isRequired,
isStarred: PropTypes.bool.isRequired,
+ direntList: PropTypes.array.isRequired,
+ dirPath: PropTypes.string.isRequired,
toggleStar: PropTypes.func.isRequired,
unmarkDraft: PropTypes.func.isRequired,
onNewNotification: PropTypes.func.isRequired
@@ -26,6 +29,7 @@ class ExternalOperations extends React.Component {
isShowInternalLinkDialog: false,
isShowShareDialog: false,
internalLink: '',
+ isShowCreateFileDialog: false,
};
}
@@ -38,6 +42,7 @@ class ExternalOperations extends React.Component {
this.unsubscribeFreezeDocument = eventBus.subscribe(EXTERNAL_EVENT.FREEZE_DOCUMENT, this.onFreezeDocument);
this.unsubscribeUnfreeze = eventBus.subscribe(EXTERNAL_EVENT.UNFREEZE, this.unFreeze);
this.unsubscribeNewNotification = eventBus.subscribe(EXTERNAL_EVENT.NEW_NOTIFICATION, this.onNewNotification);
+ this.unsubscribeCreateSdocFile = eventBus.subscribe(EXTERNAL_EVENT.CREATE_SDOC_FILE, this.onCreateSdocFile);
}
componentWillUnmount() {
@@ -48,6 +53,7 @@ class ExternalOperations extends React.Component {
this.unsubscribeFreezeDocument();
this.unsubscribeUnfreeze();
this.unsubscribeNewNotification();
+ this.unsubscribeCreateSdocFile();
}
onInternalLinkToggle = (options) => {
@@ -116,9 +122,31 @@ class ExternalOperations extends React.Component {
this.props.onNewNotification();
};
+ onCreateSdocFile = () => {
+ this.setState({
+ isShowCreateFileDialog: !this.state.isShowCreateFileDialog
+ });
+ };
+
+ checkDuplicatedName = (newName) => {
+ let direntList = this.props.direntList;
+ let isDuplicated = direntList.some(object => {
+ return object.name === newName;
+ });
+ return isDuplicated;
+ };
+
+ onAddFile = (filePath, isMarkdownDraft, isSdocDraft) => {
+ let repoID = this.props.repoID;
+ seafileAPI.createFile(repoID, filePath, isMarkdownDraft).catch((error) => {
+ let errMessage = Utils.getErrorMsg(error);
+ toaster.danger(errMessage);
+ });
+ };
+
render() {
- const { repoID, docPath, docName, docPerm } = this.props;
- const { isShowInternalLinkDialog, isShowShareDialog, internalLink } = this.state;
+ const { repoID, docPath, docName, docPerm, dirPath } = this.props;
+ const { isShowInternalLinkDialog, isShowShareDialog, internalLink, isShowCreateFileDialog } = this.state;
return (
<>
{isShowInternalLinkDialog && (
@@ -139,6 +167,15 @@ class ExternalOperations extends React.Component {
toggleDialog={this.onShareToggle}
/>
)}
+ {isShowCreateFileDialog && (
+
+ )}
>
);
}
diff --git a/frontend/src/pages/sdoc/sdoc-editor/index.js b/frontend/src/pages/sdoc/sdoc-editor/index.js
index 622aabde8b5..f95f5bcb30f 100644
--- a/frontend/src/pages/sdoc/sdoc-editor/index.js
+++ b/frontend/src/pages/sdoc/sdoc-editor/index.js
@@ -1,6 +1,8 @@
import React, { Fragment } from 'react';
import { SimpleEditor } from '@seafile/sdoc-editor';
import ExternalOperations from './external-operations';
+import { seafileAPI } from '../../../utils/seafile-api';
+import Dirent from '../../../models/dirent';
import { Utils } from '../../../utils/utils';
export default class SdocEditor extends React.Component {
@@ -10,12 +12,14 @@ export default class SdocEditor extends React.Component {
const { isStarred, isSdocDraft } = window.app.pageOptions;
this.state = {
isStarred: isStarred,
- isDraft: isSdocDraft
+ isDraft: isSdocDraft,
+ direntList: []
};
}
componentDidMount() {
this.onSetFavicon();
+ this.getDirentList();
}
toggleStar = (isStarred) => {
@@ -39,9 +43,36 @@ export default class SdocEditor extends React.Component {
this.onSetFavicon('_notification');
};
+ getDirPath = () => {
+ const { docPath } = window.seafile;
+ const index = docPath.lastIndexOf('/');
+ if (index) {
+ return docPath.slice(0, index);
+ }
+ return '/';
+ };
+
+ getDirentList = () => {
+ const { repoID } = window.seafile;
+ const path = this.getDirPath();
+ seafileAPI.listDir(repoID, path, {'with_thumbnail': true}).then(res => {
+ let direntList = [];
+ res.data.dirent_list.forEach(item => {
+ let dirent = new Dirent(item);
+ direntList.push(dirent);
+ });
+ this.setState({
+ direntList: direntList
+ });
+ }).catch((err) => {
+ Utils.getErrorMsg(err, true);
+ });
+ };
+
render() {
const { repoID, docPath, docName, docPerm } = window.seafile;
- const { isStarred, isDraft } = this.state;
+ const { isStarred, isDraft, direntList } = this.state;
+ const dirPath = this.getDirPath();
return (
@@ -51,6 +82,8 @@ export default class SdocEditor extends React.Component {
docName={docName}
docPerm={docPerm}
isStarred={isStarred}
+ direntList={direntList}
+ dirPath={dirPath}
toggleStar={this.toggleStar}
unmarkDraft={this.unmarkDraft}
onNewNotification={this.onNewNotification}
From 4bb038656f77ef51d4df555d91120e101e262208 Mon Sep 17 00:00:00 2001
From: yinjianfei <1358009667@qq.com>
Date: Sat, 6 Jan 2024 15:37:47 +0800
Subject: [PATCH 2/6] cache-files
---
frontend/src/pages/sdoc/sdoc-editor/index.js | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/frontend/src/pages/sdoc/sdoc-editor/index.js b/frontend/src/pages/sdoc/sdoc-editor/index.js
index f95f5bcb30f..09073c1d203 100644
--- a/frontend/src/pages/sdoc/sdoc-editor/index.js
+++ b/frontend/src/pages/sdoc/sdoc-editor/index.js
@@ -20,6 +20,7 @@ export default class SdocEditor extends React.Component {
componentDidMount() {
this.onSetFavicon();
this.getDirentList();
+ this.cacheHistoryfiles();
}
toggleStar = (isStarred) => {
@@ -43,6 +44,25 @@ export default class SdocEditor extends React.Component {
this.onSetFavicon('_notification');
};
+ cacheHistoryfiles = () => {
+ const { docName, docUuid } = window.seafile;
+ const rencentFiles = localStorage.getItem('sdoc-recent-files') ? JSON.parse(localStorage.getItem('sdoc-recent-files')) : [];
+ let arr = [];
+ const newFile = { file_uuid: docUuid, file_name: docName };
+ if (rencentFiles.length > 0) {
+ const isExist = rencentFiles.find((item) => item.file_uuid === docUuid);
+ if (isExist) return;
+ if (!isExist) {
+ let newRencentFiles = rencentFiles.slice(0);
+ if (rencentFiles.length === 10) {newRencentFiles.shift();}
+ arr = [newFile, ...newRencentFiles];
+ }
+ } else {
+ arr.push(newFile);
+ }
+ localStorage.setItem('sdoc-recent-files', JSON.stringify(arr));
+ };
+
getDirPath = () => {
const { docPath } = window.seafile;
const index = docPath.lastIndexOf('/');
From 6ee3992064c97632c6afd8df9efdc39589a7d520 Mon Sep 17 00:00:00 2001
From: yinjianfei <1358009667@qq.com>
Date: Mon, 8 Jan 2024 10:55:34 +0800
Subject: [PATCH 3/6] update-file-type
---
frontend/src/components/dialog/create-file-dialog.js | 2 +-
.../src/pages/sdoc/sdoc-editor/external-operations.js | 10 +++++++---
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/frontend/src/components/dialog/create-file-dialog.js b/frontend/src/components/dialog/create-file-dialog.js
index 560da08cdc9..6eb34293fc3 100644
--- a/frontend/src/components/dialog/create-file-dialog.js
+++ b/frontend/src/components/dialog/create-file-dialog.js
@@ -21,7 +21,7 @@ class CreateFile extends React.Component {
isMarkdownDraft: false,
isSdocDraft: false,
errMessage: '',
- isSubmitBtnActive: false,
+ isSubmitBtnActive: props.fileType.slice(0, -5) ? true : false,
};
this.newInput = React.createRef();
}
diff --git a/frontend/src/pages/sdoc/sdoc-editor/external-operations.js b/frontend/src/pages/sdoc/sdoc-editor/external-operations.js
index aef441c760e..4ef3cdf4493 100644
--- a/frontend/src/pages/sdoc/sdoc-editor/external-operations.js
+++ b/frontend/src/pages/sdoc/sdoc-editor/external-operations.js
@@ -30,6 +30,7 @@ class ExternalOperations extends React.Component {
isShowShareDialog: false,
internalLink: '',
isShowCreateFileDialog: false,
+ fileType: '.sdoc',
};
}
@@ -122,7 +123,10 @@ class ExternalOperations extends React.Component {
this.props.onNewNotification();
};
- onCreateSdocFile = () => {
+ onCreateSdocFile = (params) => {
+ if (params?.newFileName) {
+ this.setState({fileType: `${params.newFileName}.sdoc`});
+ }
this.setState({
isShowCreateFileDialog: !this.state.isShowCreateFileDialog
});
@@ -146,7 +150,7 @@ class ExternalOperations extends React.Component {
render() {
const { repoID, docPath, docName, docPerm, dirPath } = this.props;
- const { isShowInternalLinkDialog, isShowShareDialog, internalLink, isShowCreateFileDialog } = this.state;
+ const { isShowInternalLinkDialog, isShowShareDialog, internalLink, isShowCreateFileDialog, fileType } = this.state;
return (
<>
{isShowInternalLinkDialog && (
@@ -170,7 +174,7 @@ class ExternalOperations extends React.Component {
{isShowCreateFileDialog && (
Date: Tue, 9 Jan 2024 15:56:20 +0800
Subject: [PATCH 4/6] update-addfile
---
frontend/src/pages/sdoc/sdoc-editor/external-operations.js | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/frontend/src/pages/sdoc/sdoc-editor/external-operations.js b/frontend/src/pages/sdoc/sdoc-editor/external-operations.js
index 4ef3cdf4493..ae43f68aa3a 100644
--- a/frontend/src/pages/sdoc/sdoc-editor/external-operations.js
+++ b/frontend/src/pages/sdoc/sdoc-editor/external-operations.js
@@ -140,9 +140,12 @@ class ExternalOperations extends React.Component {
return isDuplicated;
};
- onAddFile = (filePath, isMarkdownDraft, isSdocDraft) => {
+ onAddFile = (filePath, isMarkdownDraft) => {
let repoID = this.props.repoID;
- seafileAPI.createFile(repoID, filePath, isMarkdownDraft).catch((error) => {
+ seafileAPI.createFile(repoID, filePath, isMarkdownDraft).then((res) => {
+ const eventBus = EventBus.getInstance();
+ eventBus.dispatch(EXTERNAL_EVENT.INSERT_LINK, {data: res.data});
+ }).catch((error) => {
let errMessage = Utils.getErrorMsg(error);
toaster.danger(errMessage);
});
From 275724ca470ba614f380953a3fcdc8917b558afa Mon Sep 17 00:00:00 2001
From: yinjianfei <1358009667@qq.com>
Date: Sat, 20 Jan 2024 10:30:11 +0800
Subject: [PATCH 5/6] update-key
---
frontend/src/pages/sdoc/sdoc-editor/index.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/frontend/src/pages/sdoc/sdoc-editor/index.js b/frontend/src/pages/sdoc/sdoc-editor/index.js
index 09073c1d203..daa7edc10ca 100644
--- a/frontend/src/pages/sdoc/sdoc-editor/index.js
+++ b/frontend/src/pages/sdoc/sdoc-editor/index.js
@@ -48,9 +48,9 @@ export default class SdocEditor extends React.Component {
const { docName, docUuid } = window.seafile;
const rencentFiles = localStorage.getItem('sdoc-recent-files') ? JSON.parse(localStorage.getItem('sdoc-recent-files')) : [];
let arr = [];
- const newFile = { file_uuid: docUuid, file_name: docName };
+ const newFile = { doc_uuid: docUuid, name: docName };
if (rencentFiles.length > 0) {
- const isExist = rencentFiles.find((item) => item.file_uuid === docUuid);
+ const isExist = rencentFiles.find((item) => item.doc_uuid === docUuid);
if (isExist) return;
if (!isExist) {
let newRencentFiles = rencentFiles.slice(0);
From 28ee6d411b473a9546b090b53c4c88f9086ed536 Mon Sep 17 00:00:00 2001
From: yinjianfei <1358009667@qq.com>
Date: Sat, 20 Jan 2024 18:17:17 +0800
Subject: [PATCH 6/6] remove-cache
---
frontend/src/pages/sdoc/sdoc-editor/index.js | 20 --------------------
1 file changed, 20 deletions(-)
diff --git a/frontend/src/pages/sdoc/sdoc-editor/index.js b/frontend/src/pages/sdoc/sdoc-editor/index.js
index daa7edc10ca..f95f5bcb30f 100644
--- a/frontend/src/pages/sdoc/sdoc-editor/index.js
+++ b/frontend/src/pages/sdoc/sdoc-editor/index.js
@@ -20,7 +20,6 @@ export default class SdocEditor extends React.Component {
componentDidMount() {
this.onSetFavicon();
this.getDirentList();
- this.cacheHistoryfiles();
}
toggleStar = (isStarred) => {
@@ -44,25 +43,6 @@ export default class SdocEditor extends React.Component {
this.onSetFavicon('_notification');
};
- cacheHistoryfiles = () => {
- const { docName, docUuid } = window.seafile;
- const rencentFiles = localStorage.getItem('sdoc-recent-files') ? JSON.parse(localStorage.getItem('sdoc-recent-files')) : [];
- let arr = [];
- const newFile = { doc_uuid: docUuid, name: docName };
- if (rencentFiles.length > 0) {
- const isExist = rencentFiles.find((item) => item.doc_uuid === docUuid);
- if (isExist) return;
- if (!isExist) {
- let newRencentFiles = rencentFiles.slice(0);
- if (rencentFiles.length === 10) {newRencentFiles.shift();}
- arr = [newFile, ...newRencentFiles];
- }
- } else {
- arr.push(newFile);
- }
- localStorage.setItem('sdoc-recent-files', JSON.stringify(arr));
- };
-
getDirPath = () => {
const { docPath } = window.seafile;
const index = docPath.lastIndexOf('/');