File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
frontend/src/pages/sdoc/sdoc-editor Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ export default class SdocEditor extends React.Component {
1919
2020 componentDidMount ( ) {
2121 this . getDirentList ( ) ;
22+ this . cacheHistoryfiles ( ) ;
2223 const { docName } = window . seafile ;
2324 const fileIcon = Utils . getFileIconUrl ( docName , 192 ) ;
2425 document . getElementById ( 'favicon' ) . href = fileIcon ;
@@ -32,6 +33,25 @@ export default class SdocEditor extends React.Component {
3233 this . setState ( { isDraft : false } ) ;
3334 } ;
3435
36+ cacheHistoryfiles = ( ) => {
37+ const { docName, docUuid } = window . seafile ;
38+ const rencentFiles = localStorage . getItem ( 'sdoc-recent-files' ) ? JSON . parse ( localStorage . getItem ( 'sdoc-recent-files' ) ) : [ ] ;
39+ let arr = [ ] ;
40+ const newFile = { file_uuid : docUuid , file_name : docName } ;
41+ if ( rencentFiles . length > 0 ) {
42+ const isExist = rencentFiles . find ( ( item ) => item . file_uuid === docUuid ) ;
43+ if ( isExist ) return ;
44+ if ( ! isExist ) {
45+ let newRencentFiles = rencentFiles . slice ( 0 ) ;
46+ if ( rencentFiles . length === 10 ) { newRencentFiles . shift ( ) ; }
47+ arr = [ newFile , ...newRencentFiles ] ;
48+ }
49+ } else {
50+ arr . push ( newFile ) ;
51+ }
52+ localStorage . setItem ( 'sdoc-recent-files' , JSON . stringify ( arr ) ) ;
53+ } ;
54+
3555 getDirPath = ( ) => {
3656 const { docPath } = window . seafile ;
3757 const index = docPath . lastIndexOf ( '/' ) ;
You can’t perform that action at this time.
0 commit comments