Skip to content

Commit

Permalink
cache-files
Browse files Browse the repository at this point in the history
  • Loading branch information
yinjianfei-user committed Jan 6, 2024
1 parent a24e8c6 commit bfb8fde
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions frontend/src/pages/sdoc/sdoc-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default class SdocEditor extends React.Component {

componentDidMount() {
this.getDirentList();
this.cacheHistoryfiles();
const { docName } = window.seafile;
const fileIcon = Utils.getFileIconUrl(docName, 192);
document.getElementById('favicon').href = fileIcon;
Expand All @@ -32,6 +33,25 @@ export default class SdocEditor extends React.Component {
this.setState({isDraft: false});
};

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('/');
Expand Down

0 comments on commit bfb8fde

Please sign in to comment.