feat: show sub actions in navbar in shared folder

This commit is contained in:
HFO4 2022-04-29 19:48:07 +08:00
parent de63a0b657
commit 4cab055e64
10 changed files with 45 additions and 29 deletions

View File

@ -1,6 +1,6 @@
{
"name": "cloudreve-frontend",
"version": "3.5.2",
"version": "3.5.3",
"private": true,
"dependencies": {
"@babel/core": "7.6.0",

View File

@ -125,6 +125,7 @@ const mapStateToProps = (state) => {
return {
path: state.navigator.path,
selected: state.explorer.selected,
shareInfo: state.viewUpdate.shareInfo,
};
};
@ -200,9 +201,9 @@ class FileIconCompoment extends Component {
)}
src={
baseURL +
(isSharePage
(isSharePage && this.props.shareInfo
? "/share/thumb/" +
window.shareInfo.key +
this.props.shareInfo.key +
"/" +
this.props.file.id +
"?path=" +

View File

@ -475,7 +475,7 @@ class NavigatorComponent extends Component {
))}
</div>
<div className={classes.optionContainer}>
<SubActions isSmall share={this.props.share} />
<SubActions isSmall />
</div>
</div>
<Divider />

View File

@ -33,11 +33,12 @@ const sortOptions = [
const paginationOption = ["50", "100", "200", "500", "1000"];
export default function SubActions({ isSmall, share, inherit }) {
export default function SubActions({ isSmall, inherit }) {
const dispatch = useDispatch();
const viewMethod = useSelector(
(state) => state.viewUpdate.explorerViewMethod
);
const share = useSelector((state) => state.viewUpdate.shareInfo);
const pageSize = useSelector((state) => state.viewUpdate.pagination.size);
const OpenLoadingDialog = useCallback(
(method) => dispatch(changeViewMethod(method)),

View File

@ -36,6 +36,7 @@ const useStyles = makeStyles(() => ({
export default function ObjectIcon(props) {
const path = useSelector((state) => state.navigator.path);
const shareInfo = useSelector((state) => state.viewUpdate.shareInfo);
const selected = useSelector((state) => state.explorer.selected);
const viewMethod = useSelector(
(state) => state.viewUpdate.explorerViewMethod
@ -109,7 +110,12 @@ export default function ObjectIcon(props) {
}
SelectFile(e);
if (props.file.type === "dir" && (!e.ctrlKey && !e.metaKey && !e.shiftKey)) {
if (
props.file.type === "dir" &&
!e.ctrlKey &&
!e.metaKey &&
!e.shiftKey
) {
enterFolder();
}
};
@ -123,7 +129,7 @@ export default function ObjectIcon(props) {
return;
}
OpenPreview(window.shareInfo);
OpenPreview(shareInfo);
};
const handleIconClick = (e) => {

View File

@ -83,6 +83,7 @@ const mapStateToProps = (state) => {
subTitle: state.viewUpdate.subTitle,
loadUploader: state.viewUpdate.loadUploader,
isLogin: state.viewUpdate.isLogin,
shareInfo: state.viewUpdate.shareInfo,
registerEnabled: state.siteConfig.registerEnabled,
audioPreviewPlayingName: state.explorer.audioPreview.playingName,
audioPreviewIsOpen: state.explorer.audioPreview.isOpen,
@ -334,11 +335,11 @@ class NavbarCompoment extends Component {
};
openDownload = () => {
this.props.startDownload(window.shareInfo, this.props.selected[0]);
this.props.startDownload(this.props.shareInfo, this.props.selected[0]);
};
archiveDownload = (e) => {
this.props.startBatchDownload(window.shareInfo);
this.props.startBatchDownload(this.props.shareInfo);
};
signOut = () => {
@ -503,7 +504,9 @@ class NavbarCompoment extends Component {
<ListItem
button
key="注册"
onClick={() => this.props.history.push("/signup")}
onClick={() =>
this.props.history.push("/signup")
}
>
<ListItemIcon>
<AccountPlus className={classes.iconFix} />
@ -635,7 +638,8 @@ class NavbarCompoment extends Component {
color="inherit"
onClick={() =>
this.props.openPreview(
window.shareInfo
this.props
.shareInfo
)
}
>
@ -798,7 +802,10 @@ class NavbarCompoment extends Component {
{this.props.selected.length === 0 && <UserAvatar />}
{this.props.selected.length === 0 &&
pathHelper.isMobile() && <SubActions inherit />}
pathHelper.isMobile() &&
(isHomePage || this.props.shareInfo) && (
<SubActions inherit />
)}
</Toolbar>
</AppBar>
<Uploader />

View File

@ -16,6 +16,7 @@ import {
showImgPreivew,
toggleSnackbar,
} from "../../redux/explorer";
import { setShareInfo } from "../../redux/viewUpdate/action";
const styles = (theme) => ({
layout: {
@ -69,6 +70,9 @@ const mapDispatchToProps = (dispatch) => {
setShareUserPopover: (e) => {
dispatch(setShareUserPopover(e));
},
setShareInfo: (s) => {
dispatch(setShareInfo(s));
},
};
};
@ -76,11 +80,11 @@ class SharedFolderComponent extends Component {
state = {};
UNSAFE_componentWillMount() {
window.shareInfo = this.props.share;
this.props.setShareInfo(this.props.share);
}
componentWillUnmount() {
window.shareInfo = null;
this.props.setShareInfo(null);
this.props.setSelectedTarget([]);
}

View File

@ -67,6 +67,13 @@ export const setPagination = (pagination) => {
};
};
export const setShareInfo = (shareInfo) => {
return {
type: "SET_SHARE_INFO",
shareInfo: shareInfo,
};
};
export const changePageSize = (
size: number
): ThunkAction<any, any, any, any> => {

View File

@ -348,6 +348,11 @@ const viewUpdate = (state: ViewUpdateState = initState, action: AnyAction) => {
...state,
pagination: action.pagination,
};
case "SET_SHARE_INFO":
return {
...state,
shareInfo: action.shareInfo,
};
default:
return state;
}

View File

@ -40,21 +40,6 @@ export const setGetParameter = (paramName, paramValue) => {
window.history.pushState(null, null, url);
};
export const allowSharePreview = () => {
if (!window.isSharePage) {
return true;
}
if (window.isSharePage) {
if (window.shareInfo.allowPreview) {
return true;
}
if (window.userInfo.uid === -1) {
return false;
}
return true;
}
};
export const checkGetParameters = (field) => {
const url = window.location.href;
if (url.indexOf("?" + field + "=") !== -1) return true;