1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-03 16:10:26 +00:00

Update recently used view (#6487)

* improve recently used item list ui

* update view in recently used from repo list to folder list
This commit is contained in:
Aries
2024-08-05 16:08:05 +08:00
committed by GitHub
parent 093d8b180a
commit 3747b8acfc
5 changed files with 71 additions and 18 deletions

View File

@@ -7,6 +7,7 @@ import { Utils } from '../../utils/utils';
import toaster from '../toast'; import toaster from '../toast';
import RepoInfo from '../../models/repo-info'; import RepoInfo from '../../models/repo-info';
import RepoListView from './repo-list-view'; import RepoListView from './repo-list-view';
import RecentlyUsedListView from './recently-used-list-view';
import Loading from '../loading'; import Loading from '../loading';
import SearchedListView from './searched-list-view'; import SearchedListView from './searched-list-view';
@@ -416,7 +417,7 @@ class FileChooser extends React.Component {
renderRepoListView = () => { renderRepoListView = () => {
const { mode, currentPath, isShowFile, fileSuffixes } = this.props; const { mode, currentPath, isShowFile, fileSuffixes } = this.props;
const { isCurrentRepoShow, isOtherRepoShow, currentRepoInfo, repoList, selectedRepo, selectedPath, selectedItemInfo } = this.state; const { isCurrentRepoShow, isOtherRepoShow, currentRepoInfo, repoList, selectedRepo, selectedPath, selectedItemInfo } = this.state;
const recentlyUsedRepos = JSON.parse(localStorage.getItem('recently-used-repos')) || []; const recentlyUsedList = JSON.parse(localStorage.getItem('recently-used-list')) || [];
return ( return (
<div className='scroll-wrapper' onScroll={this.onScroll}> <div className='scroll-wrapper' onScroll={this.onScroll}>
@@ -520,16 +521,10 @@ class FileChooser extends React.Component {
)} )}
{mode === 'recently_used' && ( {mode === 'recently_used' && (
<div className="list-view"> <div className="list-view">
<RepoListView <RecentlyUsedListView
initToShowChildren={false} recentlyUsedList={recentlyUsedList}
repoList={recentlyUsedRepos}
selectedRepo={selectedRepo} selectedRepo={selectedRepo}
selectedPath={selectedPath}
onRepoItemClick={this.onRepoItemClick}
onDirentItemClick={this.onDirentItemClick} onDirentItemClick={this.onDirentItemClick}
isShowFile={isShowFile}
fileSuffixes={fileSuffixes}
selectedItemInfo={selectedItemInfo}
/> />
</div> </div>
)} )}

View File

@@ -0,0 +1,26 @@
import React from 'react';
const RecentlyUsedListItem = ({ path, isSelected, onItemClick }) => {
const title = path.split('/').pop();
const handleItemClick = () => {
onItemClick(path);
};
return (
<li>
<div className={`${isSelected ? 'item-active' : ''} item-info recently-used`} onClick={handleItemClick}>
<div className="item-left-icon">
<i className="tree-node-icon">
<span className="icon sf3-font sf3-font-folder tree-node-icon"></span>
</i>
</div>
<div className="item-text">
<span className="name user-select-none ellipsis" title={title}>{title}</span>
</div>
</div>
</li>
);
};
export default RecentlyUsedListItem;

View File

@@ -0,0 +1,28 @@
import React, { useState } from 'react';
import RecentlyUsedListItem from './recently-used-list-item';
const RecentlyUsedListView = ({ recentlyUsedList, selectedRepo, onDirentItemClick }) => {
const [selectedItem, setSelectedItem] = useState(null);
const onItemClick = (path) => {
setSelectedItem(path);
onDirentItemClick(selectedRepo, path);
};
return (
<ul className="list-view-content file-chooser-item" >
{recentlyUsedList.length > 0 && recentlyUsedList.map((path, index) => {
return (
<RecentlyUsedListItem
key={index}
path={path}
isSelected={selectedItem === path}
onItemClick={onItemClick}
/>
);
})}
</ul>
);
};
export default RecentlyUsedListView;

View File

@@ -63,6 +63,10 @@
transition: color 0.3s ease, background-color 0.3s ease; transition: color 0.3s ease, background-color 0.3s ease;
} }
.file-chooser-item .recently-used .item-left-icon {
padding: 0 0.25rem 0 0.5rem;
}
.file-chooser-search-close { .file-chooser-search-close {
position: absolute; position: absolute;
top: -0.5rem; top: -0.5rem;

View File

@@ -715,16 +715,16 @@ class LibContentView extends React.Component {
}); });
}; };
updateRecentlyUsedRepos = (destRepo) => { updateRecentlyUsedRepos = (destPath) => {
const recentlyUsed = JSON.parse(localStorage.getItem('recently-used-repos')) || []; const recentlyUsed = JSON.parse(localStorage.getItem('recently-used-list')) || [];
const updatedRecentlyUsed = [destRepo, ...recentlyUsed.filter(repo => repo.repo_id !== destRepo.repo_id)]; const updatedRecentlyUsed = [destPath, ...recentlyUsed.filter(path => path !== destPath)];
const seen = new Set(); const seen = new Set();
const filteredRecentlyUsed = updatedRecentlyUsed.filter(repo => { const filteredRecentlyUsed = updatedRecentlyUsed.filter(path => {
if (seen.has(repo.repo_id)) { if (seen.has(path)) {
return false; return false;
} else { } else {
seen.add(repo.repo_id); seen.add(path);
return true; return true;
} }
}); });
@@ -733,7 +733,7 @@ class LibContentView extends React.Component {
updatedRecentlyUsed.pop(); // Limit to 10 recent directories updatedRecentlyUsed.pop(); // Limit to 10 recent directories
} }
localStorage.setItem('recently-used-repos', JSON.stringify(filteredRecentlyUsed)); localStorage.setItem('recently-used-list', JSON.stringify(filteredRecentlyUsed));
}; };
// toolbar operations // toolbar operations
@@ -775,7 +775,7 @@ class LibContentView extends React.Component {
toaster.success(message); toaster.success(message);
} }
this.updateRecentlyUsedRepos(destRepo); this.updateRecentlyUsedRepos(destDirentPath);
}).catch((error) => { }).catch((error) => {
if (!error.response.data.lib_need_decrypt) { if (!error.response.data.lib_need_decrypt) {
@@ -1247,7 +1247,7 @@ class LibContentView extends React.Component {
toaster.success(message); toaster.success(message);
} }
this.updateRecentlyUsedRepos(destRepo); this.updateRecentlyUsedRepos(moveToDirentPath);
}).catch((error) => { }).catch((error) => {
if (!error.response.data.lib_need_decrypt) { if (!error.response.data.lib_need_decrypt) {