Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update recently used view #6487

Merged
merged 2 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions frontend/src/components/file-chooser/file-chooser.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Utils } from '../../utils/utils';
import toaster from '../toast';
import RepoInfo from '../../models/repo-info';
import RepoListView from './repo-list-view';
import RecentlyUsedListView from './recently-used-list-view';
import Loading from '../loading';
import SearchedListView from './searched-list-view';

Expand Down Expand Up @@ -416,7 +417,7 @@ class FileChooser extends React.Component {
renderRepoListView = () => {
const { mode, currentPath, isShowFile, fileSuffixes } = this.props;
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 (
<div className='scroll-wrapper' onScroll={this.onScroll}>
Expand Down Expand Up @@ -520,16 +521,10 @@ class FileChooser extends React.Component {
)}
{mode === 'recently_used' && (
<div className="list-view">
<RepoListView
initToShowChildren={false}
repoList={recentlyUsedRepos}
<RecentlyUsedListView
recentlyUsedList={recentlyUsedList}
selectedRepo={selectedRepo}
selectedPath={selectedPath}
onRepoItemClick={this.onRepoItemClick}
onDirentItemClick={this.onDirentItemClick}
isShowFile={isShowFile}
fileSuffixes={fileSuffixes}
selectedItemInfo={selectedItemInfo}
/>
</div>
)}
Expand Down
26 changes: 26 additions & 0 deletions frontend/src/components/file-chooser/recently-used-list-item.js
Original file line number Diff line number Diff line change
@@ -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;
28 changes: 28 additions & 0 deletions frontend/src/components/file-chooser/recently-used-list-view.js
Original file line number Diff line number Diff line change
@@ -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;
4 changes: 4 additions & 0 deletions frontend/src/css/file-chooser.css
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
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 {
position: absolute;
top: -0.5rem;
Expand Down
18 changes: 9 additions & 9 deletions frontend/src/pages/lib-content-view/lib-content-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -715,16 +715,16 @@ class LibContentView extends React.Component {
});
};

updateRecentlyUsedRepos = (destRepo) => {
const recentlyUsed = JSON.parse(localStorage.getItem('recently-used-repos')) || [];
const updatedRecentlyUsed = [destRepo, ...recentlyUsed.filter(repo => repo.repo_id !== destRepo.repo_id)];
updateRecentlyUsedRepos = (destPath) => {
const recentlyUsed = JSON.parse(localStorage.getItem('recently-used-list')) || [];
const updatedRecentlyUsed = [destPath, ...recentlyUsed.filter(path => path !== destPath)];

const seen = new Set();
const filteredRecentlyUsed = updatedRecentlyUsed.filter(repo => {
if (seen.has(repo.repo_id)) {
const filteredRecentlyUsed = updatedRecentlyUsed.filter(path => {
if (seen.has(path)) {
return false;
} else {
seen.add(repo.repo_id);
seen.add(path);
return true;
}
});
Expand All @@ -733,7 +733,7 @@ class LibContentView extends React.Component {
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
Expand Down Expand Up @@ -775,7 +775,7 @@ class LibContentView extends React.Component {
toaster.success(message);
}

this.updateRecentlyUsedRepos(destRepo);
this.updateRecentlyUsedRepos(destDirentPath);

}).catch((error) => {
if (!error.response.data.lib_need_decrypt) {
Expand Down Expand Up @@ -1247,7 +1247,7 @@ class LibContentView extends React.Component {
toaster.success(message);
}

this.updateRecentlyUsedRepos(destRepo);
this.updateRecentlyUsedRepos(moveToDirentPath);

}).catch((error) => {
if (!error.response.data.lib_need_decrypt) {
Expand Down
Loading