Disable arrows when nothing previous/next

This commit is contained in:
Maxime Lalo 2023-04-24 15:58:21 +02:00
parent fd574305b4
commit 2cfd3907b7
2 changed files with 55 additions and 28 deletions

View File

@ -18,6 +18,11 @@
.arrow-container{ .arrow-container{
cursor: pointer; cursor: pointer;
&[data-disabled="true"]{
opacity: 0.3;
cursor: not-allowed;
}
} }
.file-container{ .file-container{

View File

@ -1,5 +1,6 @@
import "reflect-metadata"; import "reflect-metadata";
import LeftArrowIcon from "@Assets/Icons/left-arrow.svg";
import RightArrowIcon from "@Assets/Icons/right-arrow.svg";
import ValidateAnchoringGif from "@Front/Assets/images/validate_anchoring.gif"; import ValidateAnchoringGif from "@Front/Assets/images/validate_anchoring.gif";
import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button"; import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button";
import CheckBox from "@Front/Components/DesignSystem/CheckBox"; import CheckBox from "@Front/Components/DesignSystem/CheckBox";
@ -17,8 +18,6 @@ import React from "react";
import BasePage from "../../Base"; import BasePage from "../../Base";
import classes from "./classes.module.scss"; import classes from "./classes.module.scss";
import LeftArrowIcon from "@Assets/Icons/left-arrow.svg";
import RightArrowIcon from "@Assets/Icons/right-arrow.svg";
type IProps = {}; type IProps = {};
type IPropsClass = { type IPropsClass = {
@ -47,7 +46,7 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
refuseText: "", refuseText: "",
hasValidateAnchoring: false, hasValidateAnchoring: false,
selectedDocument: null, selectedDocument: null,
selectedDocumentIndex: -1 selectedDocumentIndex: -1,
}; };
this.closeModals = this.closeModals.bind(this); this.closeModals = this.closeModals.bind(this);
@ -55,6 +54,11 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
this.openRefuseModal = this.openRefuseModal.bind(this); this.openRefuseModal = this.openRefuseModal.bind(this);
this.onRefuseTextChange = this.onRefuseTextChange.bind(this); this.onRefuseTextChange = this.onRefuseTextChange.bind(this);
this.validateAnchoring = this.validateAnchoring.bind(this); this.validateAnchoring = this.validateAnchoring.bind(this);
this.goToNext = this.goToNext.bind(this);
this.goToPrevious = this.goToPrevious.bind(this);
this.hasPrevious = this.hasPrevious.bind(this);
this.hasNext = this.hasNext.bind(this);
} }
public override render(): JSX.Element | null { public override render(): JSX.Element | null {
@ -69,17 +73,21 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
{this.state.selectedDocument.document_type.name} {this.state.selectedDocument.document_type.name}
</Typography> </Typography>
<div className={classes["document-container"]}> <div className={classes["document-container"]}>
<div className={classes["arrow-container"]} onClick={this.goToPrevious()}> {this.props.documentsList.length > 1 && (
<div className={classes["arrow-container"]} onClick={this.goToPrevious} data-disabled={(!this.hasPrevious()).toString()}>
<Image src={LeftArrowIcon} alt="left arrow" /> <Image src={LeftArrowIcon} alt="left arrow" />
</div> </div>
)}
<div className={classes["file-container"]}> <div className={classes["file-container"]}>
{this.state.selectedDocument.files?.map((file) => ( {this.state.selectedDocument.files?.map((file) => (
<FilePreview href={file.file_path as string} key={file.uid} /> <FilePreview href={file.file_path as string} key={file.uid} />
))} ))}
</div> </div>
<div className={classes["arrow-container"]} onClick={this.goToNext()}> {this.props.documentsList.length > 1 && (
<div className={classes["arrow-container"]} onClick={this.goToNext} data-disabled={(!this.hasNext()).toString()}>
<Image src={RightArrowIcon} alt="right arrow" /> <Image src={RightArrowIcon} alt="right arrow" />
</div> </div>
)}
</div> </div>
<div className={classes["buttons-container"]}> <div className={classes["buttons-container"]}>
<Button variant={EButtonVariant.GHOST} onClick={this.openRefuseModal}> <Button variant={EButtonVariant.GHOST} onClick={this.openRefuseModal}>
@ -165,23 +173,29 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
} }
private goToPrevious() { private goToPrevious() {
return () => { if (this.hasPrevious()) {
const index = this.state.selectedDocumentIndex - 1; this.props.router.push(
if (index < 0) { `/folder/${this.props.folderUid}/document/${this.props.documentsList[this.state.selectedDocumentIndex - 1]!.uid}`,
return; );
} }
this.props.router.push(`/folder/${this.props.folderUid}/document/${this.props.documentsList[index]!.uid}`)
};
} }
private goToNext() { private goToNext() {
return () => { if (this.hasNext()) {
this.props.router.push(
`/folder/${this.props.folderUid}/document/${this.props.documentsList[this.state.selectedDocumentIndex + 1]!.uid}`,
);
}
}
private hasPrevious() {
const index = this.state.selectedDocumentIndex - 1;
return index >= 0;
}
private hasNext() {
const index = this.state.selectedDocumentIndex + 1; const index = this.state.selectedDocumentIndex + 1;
if (index >= this.props.documentsList.length) { return index < this.props.documentsList.length;
return;
}
this.props.router.push(`/folder/${this.props.folderUid}/document/${this.props.documentsList[index]!.uid}`)
}
} }
private validateAnchoring() { private validateAnchoring() {
@ -224,5 +238,13 @@ export default function ViewDocuments(props: IProps) {
const documents = folder.documents!; const documents = folder.documents!;
const selectedDocument = documents.find((document) => document.uid === documentUid) ?? null; const selectedDocument = documents.find((document) => document.uid === documentUid) ?? null;
return <ViewDocumentsClass {...props} documentsList={documents} selectedDocument={selectedDocument} router={router} folderUid={folderUid as string}/>; return (
<ViewDocumentsClass
{...props}
documentsList={documents}
selectedDocument={selectedDocument}
router={router}
folderUid={folderUid as string}
/>
);
} }