mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-17 15:53:28 +00:00
[shared dir view] improved 'switch view mode': don't refresh the whole page (#7257)
This commit is contained in:
@@ -42,6 +42,7 @@ body {
|
|||||||
.sf-view-mode-btn.current-mode {
|
.sf-view-mode-btn.current-mode {
|
||||||
background-color: #ccc;
|
background-color: #ccc;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
|
box-shadow: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.shared-dir-op-btn {
|
.shared-dir-op-btn {
|
||||||
|
@@ -6,7 +6,8 @@ import { Button, Dropdown, DropdownToggle, DropdownItem, UncontrolledTooltip } f
|
|||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import relativeTime from 'dayjs/plugin/relativeTime';
|
import relativeTime from 'dayjs/plugin/relativeTime';
|
||||||
import Account from './components/common/account';
|
import Account from './components/common/account';
|
||||||
import { useGoFileserver, fileServerRoot, gettext, siteRoot, mediaUrl, logoPath, logoWidth, logoHeight, siteTitle, thumbnailSizeForOriginal } from './utils/constants';
|
import { useGoFileserver, fileServerRoot, gettext, siteRoot, mediaUrl, logoPath, logoWidth, logoHeight, siteTitle,
|
||||||
|
thumbnailSizeForOriginal, thumbnailDefaultSize, thumbnailSizeForGrid } from './utils/constants';
|
||||||
import { Utils } from './utils/utils';
|
import { Utils } from './utils/utils';
|
||||||
import { seafileAPI } from './utils/seafile-api';
|
import { seafileAPI } from './utils/seafile-api';
|
||||||
import Loading from './components/loading';
|
import Loading from './components/loading';
|
||||||
@@ -48,6 +49,8 @@ class SharedDirView extends React.Component {
|
|||||||
errorMsg: '',
|
errorMsg: '',
|
||||||
items: [],
|
items: [],
|
||||||
|
|
||||||
|
currentMode: mode,
|
||||||
|
|
||||||
isAllItemsSelected: false,
|
isAllItemsSelected: false,
|
||||||
selectedItems: [],
|
selectedItems: [],
|
||||||
|
|
||||||
@@ -81,6 +84,11 @@ class SharedDirView extends React.Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.listItems(thumbnailSize);
|
||||||
|
this.getShareLinkRepoTags();
|
||||||
|
}
|
||||||
|
|
||||||
|
listItems = (thumbnailSize) => {
|
||||||
seafileAPI.listSharedDir(token, relativePath, thumbnailSize).then((res) => {
|
seafileAPI.listSharedDir(token, relativePath, thumbnailSize).then((res) => {
|
||||||
const items = res.data['dirent_list'].map(item => {
|
const items = res.data['dirent_list'].map(item => {
|
||||||
item.isSelected = false;
|
item.isSelected = false;
|
||||||
@@ -91,7 +99,7 @@ class SharedDirView extends React.Component {
|
|||||||
errorMsg: '',
|
errorMsg: '',
|
||||||
items: Utils.sortDirentsInSharedDir(items, this.state.sortBy, this.state.sortOrder)
|
items: Utils.sortDirentsInSharedDir(items, this.state.sortBy, this.state.sortOrder)
|
||||||
});
|
});
|
||||||
this.getThumbnails();
|
this.getThumbnails(thumbnailSize);
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
let errorMsg = Utils.getErrorMsg(error);
|
let errorMsg = Utils.getErrorMsg(error);
|
||||||
this.setState({
|
this.setState({
|
||||||
@@ -99,9 +107,7 @@ class SharedDirView extends React.Component {
|
|||||||
errorMsg: errorMsg
|
errorMsg: errorMsg
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
};
|
||||||
this.getShareLinkRepoTags();
|
|
||||||
}
|
|
||||||
|
|
||||||
sortItems = (sortBy, sortOrder) => {
|
sortItems = (sortBy, sortOrder) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
@@ -111,7 +117,7 @@ class SharedDirView extends React.Component {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
getThumbnails = () => {
|
getThumbnails = (thumbnailSize) => {
|
||||||
let items = this.state.items.filter((item) => {
|
let items = this.state.items.filter((item) => {
|
||||||
return !item.is_dir &&
|
return !item.is_dir &&
|
||||||
(Utils.imageCheck(item.file_name) ||
|
(Utils.imageCheck(item.file_name) ||
|
||||||
@@ -437,7 +443,23 @@ class SharedDirView extends React.Component {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
switchMode = (mode) => {
|
||||||
|
const { currentMode } = this.state;
|
||||||
|
if (mode == currentMode) {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
this.setState({
|
||||||
|
currentMode: mode,
|
||||||
|
isLoading: true
|
||||||
|
}, () => {
|
||||||
|
const thumbnailSize = mode == LIST_MODE ? thumbnailDefaultSize : thumbnailSizeForGrid;
|
||||||
|
this.listItems(thumbnailSize);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
const { currentMode: mode } = this.state;
|
||||||
const isDesktop = Utils.isDesktop();
|
const isDesktop = Utils.isDesktop();
|
||||||
const modeBaseClass = 'btn btn-secondary btn-icon sf-view-mode-btn';
|
const modeBaseClass = 'btn btn-secondary btn-icon sf-view-mode-btn';
|
||||||
return (
|
return (
|
||||||
@@ -458,20 +480,20 @@ class SharedDirView extends React.Component {
|
|||||||
<div className="flex-none">
|
<div className="flex-none">
|
||||||
{isDesktop &&
|
{isDesktop &&
|
||||||
<div className="view-mode btn-group">
|
<div className="view-mode btn-group">
|
||||||
<a
|
<button
|
||||||
href={`?p=${encodeURIComponent(relativePath)}&mode=list`}
|
|
||||||
className={`${modeBaseClass} sf2-icon-list-view ${mode == LIST_MODE ? 'current-mode' : ''}`}
|
className={`${modeBaseClass} sf2-icon-list-view ${mode == LIST_MODE ? 'current-mode' : ''}`}
|
||||||
title={gettext('List')}
|
title={gettext('List')}
|
||||||
aria-label={gettext('List')}
|
aria-label={gettext('List')}
|
||||||
|
onClick={this.switchMode.bind(this, LIST_MODE)}
|
||||||
>
|
>
|
||||||
</a>
|
</button>
|
||||||
<a
|
<button
|
||||||
href={`?p=${encodeURIComponent(relativePath)}&mode=grid`}
|
|
||||||
className={`${modeBaseClass} sf2-icon-grid-view ${mode == GRID_MODE ? 'current-mode' : ''}`}
|
className={`${modeBaseClass} sf2-icon-grid-view ${mode == GRID_MODE ? 'current-mode' : ''}`}
|
||||||
title={gettext('Grid')}
|
title={gettext('Grid')}
|
||||||
aria-label={gettext('Grid')}
|
aria-label={gettext('Grid')}
|
||||||
|
onClick={this.switchMode.bind(this, GRID_MODE)}
|
||||||
>
|
>
|
||||||
</a>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
{canUpload && (
|
{canUpload && (
|
||||||
@@ -529,6 +551,7 @@ class SharedDirView extends React.Component {
|
|||||||
isDesktop={isDesktop}
|
isDesktop={isDesktop}
|
||||||
isLoading={this.state.isLoading}
|
isLoading={this.state.isLoading}
|
||||||
errorMsg={this.state.errorMsg}
|
errorMsg={this.state.errorMsg}
|
||||||
|
mode={mode}
|
||||||
items={this.state.items}
|
items={this.state.items}
|
||||||
sortBy={this.state.sortBy}
|
sortBy={this.state.sortBy}
|
||||||
sortOrder={this.state.sortOrder}
|
sortOrder={this.state.sortOrder}
|
||||||
@@ -616,7 +639,7 @@ class Content extends React.Component {
|
|||||||
render() {
|
render() {
|
||||||
const {
|
const {
|
||||||
isDesktop,
|
isDesktop,
|
||||||
isLoading, errorMsg, items,
|
isLoading, errorMsg, mode, items,
|
||||||
sortBy, sortOrder,
|
sortBy, sortOrder,
|
||||||
isAllItemsSelected
|
isAllItemsSelected
|
||||||
} = this.props;
|
} = this.props;
|
||||||
@@ -635,6 +658,7 @@ class Content extends React.Component {
|
|||||||
return <Item
|
return <Item
|
||||||
key={index}
|
key={index}
|
||||||
isDesktop={isDesktop}
|
isDesktop={isDesktop}
|
||||||
|
mode={mode}
|
||||||
item={item}
|
item={item}
|
||||||
zipDownloadFolder={this.props.zipDownloadFolder}
|
zipDownloadFolder={this.props.zipDownloadFolder}
|
||||||
showImagePopup={this.props.showImagePopup}
|
showImagePopup={this.props.showImagePopup}
|
||||||
@@ -684,6 +708,7 @@ class Content extends React.Component {
|
|||||||
{items.map((item, index) => {
|
{items.map((item, index) => {
|
||||||
return <GridItem
|
return <GridItem
|
||||||
key={index}
|
key={index}
|
||||||
|
mode={mode}
|
||||||
item={item}
|
item={item}
|
||||||
zipDownloadFolder={this.props.zipDownloadFolder}
|
zipDownloadFolder={this.props.zipDownloadFolder}
|
||||||
showImagePopup={this.props.showImagePopup}
|
showImagePopup={this.props.showImagePopup}
|
||||||
@@ -699,6 +724,7 @@ Content.propTypes = {
|
|||||||
isLoading: PropTypes.bool,
|
isLoading: PropTypes.bool,
|
||||||
isAllItemsSelected: PropTypes.bool,
|
isAllItemsSelected: PropTypes.bool,
|
||||||
errorMsg: PropTypes.string,
|
errorMsg: PropTypes.string,
|
||||||
|
mode: PropTypes.string,
|
||||||
items: PropTypes.array,
|
items: PropTypes.array,
|
||||||
sortItems: PropTypes.func,
|
sortItems: PropTypes.func,
|
||||||
sortBy: PropTypes.string,
|
sortBy: PropTypes.string,
|
||||||
@@ -751,7 +777,7 @@ class Item extends React.Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { item, isDesktop } = this.props;
|
const { item, isDesktop, mode } = this.props;
|
||||||
const { isIconShown } = this.state;
|
const { isIconShown } = this.state;
|
||||||
|
|
||||||
let toolTipID = '';
|
let toolTipID = '';
|
||||||
@@ -899,6 +925,7 @@ class Item extends React.Component {
|
|||||||
|
|
||||||
Item.propTypes = {
|
Item.propTypes = {
|
||||||
isDesktop: PropTypes.bool,
|
isDesktop: PropTypes.bool,
|
||||||
|
mode: PropTypes.string,
|
||||||
item: PropTypes.object,
|
item: PropTypes.object,
|
||||||
sortItems: PropTypes.func,
|
sortItems: PropTypes.func,
|
||||||
sortBy: PropTypes.string,
|
sortBy: PropTypes.string,
|
||||||
@@ -942,7 +969,7 @@ class GridItem extends React.Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const item = this.props.item;
|
const { item, mode } = this.props;
|
||||||
const { isIconShown } = this.state;
|
const { isIconShown } = this.state;
|
||||||
|
|
||||||
if (item.is_dir) {
|
if (item.is_dir) {
|
||||||
@@ -982,6 +1009,7 @@ class GridItem extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
GridItem.propTypes = {
|
GridItem.propTypes = {
|
||||||
|
mode: PropTypes.string,
|
||||||
item: PropTypes.object,
|
item: PropTypes.object,
|
||||||
zipDownloadFolder: PropTypes.func,
|
zipDownloadFolder: PropTypes.func,
|
||||||
showImagePopup: PropTypes.func,
|
showImagePopup: PropTypes.func,
|
||||||
|
Reference in New Issue
Block a user