✨ Disable arrows when nothing previous/next
This commit is contained in:
parent
fd574305b4
commit
2cfd3907b7
@ -18,6 +18,11 @@
|
||||
|
||||
.arrow-container{
|
||||
cursor: pointer;
|
||||
|
||||
&[data-disabled="true"]{
|
||||
opacity: 0.3;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
}
|
||||
|
||||
.file-container{
|
||||
|
@ -1,5 +1,6 @@
|
||||
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 Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button";
|
||||
import CheckBox from "@Front/Components/DesignSystem/CheckBox";
|
||||
@ -17,8 +18,6 @@ import React from "react";
|
||||
import BasePage from "../../Base";
|
||||
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 IPropsClass = {
|
||||
@ -47,7 +46,7 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
|
||||
refuseText: "",
|
||||
hasValidateAnchoring: false,
|
||||
selectedDocument: null,
|
||||
selectedDocumentIndex: -1
|
||||
selectedDocumentIndex: -1,
|
||||
};
|
||||
|
||||
this.closeModals = this.closeModals.bind(this);
|
||||
@ -55,6 +54,11 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
|
||||
this.openRefuseModal = this.openRefuseModal.bind(this);
|
||||
this.onRefuseTextChange = this.onRefuseTextChange.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 {
|
||||
@ -69,17 +73,21 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
|
||||
{this.state.selectedDocument.document_type.name}
|
||||
</Typography>
|
||||
<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" />
|
||||
</div>
|
||||
)}
|
||||
<div className={classes["file-container"]}>
|
||||
{this.state.selectedDocument.files?.map((file) => (
|
||||
<FilePreview href={file.file_path as string} key={file.uid} />
|
||||
))}
|
||||
</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" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className={classes["buttons-container"]}>
|
||||
<Button variant={EButtonVariant.GHOST} onClick={this.openRefuseModal}>
|
||||
@ -148,7 +156,7 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
|
||||
}
|
||||
|
||||
override componentDidMount(): void {
|
||||
if(!this.props.selectedDocument) return;
|
||||
if (!this.props.selectedDocument) return;
|
||||
this.setState({
|
||||
selectedDocument: this.props.selectedDocument,
|
||||
selectedDocumentIndex: this.props.documentsList.findIndex((doc) => doc.uid === this.props.selectedDocument!.uid),
|
||||
@ -165,23 +173,29 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
|
||||
}
|
||||
|
||||
private goToPrevious() {
|
||||
return () => {
|
||||
const index = this.state.selectedDocumentIndex - 1;
|
||||
if (index < 0) {
|
||||
return;
|
||||
if (this.hasPrevious()) {
|
||||
this.props.router.push(
|
||||
`/folder/${this.props.folderUid}/document/${this.props.documentsList[this.state.selectedDocumentIndex - 1]!.uid}`,
|
||||
);
|
||||
}
|
||||
this.props.router.push(`/folder/${this.props.folderUid}/document/${this.props.documentsList[index]!.uid}`)
|
||||
};
|
||||
}
|
||||
|
||||
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;
|
||||
if (index >= this.props.documentsList.length) {
|
||||
return;
|
||||
}
|
||||
this.props.router.push(`/folder/${this.props.folderUid}/document/${this.props.documentsList[index]!.uid}`)
|
||||
}
|
||||
return index < this.props.documentsList.length;
|
||||
}
|
||||
|
||||
private validateAnchoring() {
|
||||
@ -224,5 +238,13 @@ export default function ViewDocuments(props: IProps) {
|
||||
const documents = folder.documents!;
|
||||
|
||||
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}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user