✨ Disable arrows when nothing previous/next
This commit is contained in:
parent
fd574305b4
commit
2cfd3907b7
@ -15,9 +15,14 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|
||||||
.arrow-container{
|
.arrow-container{
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
|
||||||
|
&[data-disabled="true"]{
|
||||||
|
opacity: 0.3;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.file-container{
|
.file-container{
|
||||||
|
@ -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,13 +18,11 @@ 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 = {
|
||||||
documentsList: Document[];
|
documentsList: Document[];
|
||||||
selectedDocument: Document | null;
|
selectedDocument: Document | null;
|
||||||
router: NextRouter;
|
router: NextRouter;
|
||||||
folderUid: string;
|
folderUid: string;
|
||||||
};
|
};
|
||||||
@ -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 && (
|
||||||
<Image src={LeftArrowIcon} alt="left arrow" />
|
<div className={classes["arrow-container"]} onClick={this.goToPrevious} data-disabled={(!this.hasPrevious()).toString()}>
|
||||||
</div>
|
<Image src={LeftArrowIcon} alt="left arrow" />
|
||||||
|
</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 && (
|
||||||
<Image src={RightArrowIcon} alt="right arrow" />
|
<div className={classes["arrow-container"]} onClick={this.goToNext} data-disabled={(!this.hasNext()).toString()}>
|
||||||
</div>
|
<Image src={RightArrowIcon} alt="right arrow" />
|
||||||
|
</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}>
|
||||||
@ -148,7 +156,7 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override componentDidMount(): void {
|
override componentDidMount(): void {
|
||||||
if(!this.props.selectedDocument) return;
|
if (!this.props.selectedDocument) return;
|
||||||
this.setState({
|
this.setState({
|
||||||
selectedDocument: this.props.selectedDocument,
|
selectedDocument: this.props.selectedDocument,
|
||||||
selectedDocumentIndex: this.props.documentsList.findIndex((doc) => doc.uid === this.props.selectedDocument!.uid),
|
selectedDocumentIndex: this.props.documentsList.findIndex((doc) => doc.uid === this.props.selectedDocument!.uid),
|
||||||
@ -163,27 +171,33 @@ 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()) {
|
||||||
const index = this.state.selectedDocumentIndex + 1;
|
this.props.router.push(
|
||||||
if (index >= this.props.documentsList.length) {
|
`/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 hasPrevious() {
|
||||||
|
const index = this.state.selectedDocumentIndex - 1;
|
||||||
|
return index >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private hasNext() {
|
||||||
|
const index = this.state.selectedDocumentIndex + 1;
|
||||||
|
return index < this.props.documentsList.length;
|
||||||
|
}
|
||||||
|
|
||||||
private validateAnchoring() {
|
private validateAnchoring() {
|
||||||
this.setState({
|
this.setState({
|
||||||
hasValidateAnchoring: true,
|
hasValidateAnchoring: true,
|
||||||
@ -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}
|
||||||
|
/>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user