mirror of
https://github.com/hexastack/hexabot
synced 2025-04-24 16:27:23 +00:00
refactor(frontend): update AttachmentViewer dialog
This commit is contained in:
parent
773fa9f1bc
commit
12fd65b774
@ -7,11 +7,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import DownloadIcon from "@mui/icons-material/Download";
|
import DownloadIcon from "@mui/icons-material/Download";
|
||||||
import { Box, Button, Dialog, DialogContent, Typography } from "@mui/material";
|
import { Box, Button, Typography } from "@mui/material";
|
||||||
import { FC } from "react";
|
import { FC } from "react";
|
||||||
|
|
||||||
import { DialogTitle } from "@/app-components/dialogs";
|
import { useDialogs } from "@/hooks/useDialogs";
|
||||||
import { useDialog } from "@/hooks/useDialog";
|
|
||||||
import { useGetAttachmentMetadata } from "@/hooks/useGetAttachmentMetadata";
|
import { useGetAttachmentMetadata } from "@/hooks/useGetAttachmentMetadata";
|
||||||
import { useTranslate } from "@/hooks/useTranslate";
|
import { useTranslate } from "@/hooks/useTranslate";
|
||||||
import {
|
import {
|
||||||
@ -21,6 +20,8 @@ import {
|
|||||||
StdOutgoingAttachmentMessage,
|
StdOutgoingAttachmentMessage,
|
||||||
} from "@/types/message.types";
|
} from "@/types/message.types";
|
||||||
|
|
||||||
|
import { AttachmentViewerFormDialog } from "./AttachmentViewerFormDialog";
|
||||||
|
|
||||||
interface AttachmentInterface {
|
interface AttachmentInterface {
|
||||||
name?: string;
|
name?: string;
|
||||||
url?: string;
|
url?: string;
|
||||||
@ -28,35 +29,27 @@ interface AttachmentInterface {
|
|||||||
|
|
||||||
const componentMap: { [key in FileType]: FC<AttachmentInterface> } = {
|
const componentMap: { [key in FileType]: FC<AttachmentInterface> } = {
|
||||||
[FileType.image]: ({ url }: AttachmentInterface) => {
|
[FileType.image]: ({ url }: AttachmentInterface) => {
|
||||||
const dialogCtl = useDialog(false);
|
const dialogs = useDialogs();
|
||||||
|
|
||||||
if (url)
|
if (url)
|
||||||
return (
|
return (
|
||||||
<>
|
// eslint-disable-next-line @next/next/no-img-element
|
||||||
<Dialog {...dialogCtl}>
|
<img
|
||||||
<DialogTitle onClose={dialogCtl.closeDialog}>Image</DialogTitle>
|
width="auto"
|
||||||
<DialogContent>
|
height={200}
|
||||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
style={{ objectFit: "contain", cursor: "pointer" }}
|
||||||
<img
|
alt={url}
|
||||||
width="auto"
|
src={url}
|
||||||
height={800}
|
onClick={() =>
|
||||||
style={{ objectFit: "contain", cursor: "pointer" }}
|
dialogs.open(
|
||||||
alt={url}
|
AttachmentViewerFormDialog,
|
||||||
src={url}
|
{ url },
|
||||||
onClick={dialogCtl.openDialog}
|
{
|
||||||
/>
|
hasButtons: false,
|
||||||
</DialogContent>
|
},
|
||||||
</Dialog>
|
)
|
||||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
}
|
||||||
<img
|
/>
|
||||||
width="auto"
|
|
||||||
height={200}
|
|
||||||
style={{ objectFit: "contain", cursor: "pointer" }}
|
|
||||||
alt={url}
|
|
||||||
src={url}
|
|
||||||
onClick={dialogCtl.openDialog}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2025 Hexastack. All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
|
||||||
|
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
|
||||||
|
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { FC, Fragment } from "react";
|
||||||
|
|
||||||
|
import { ComponentFormProps } from "@/types/common/dialogs.types";
|
||||||
|
|
||||||
|
export type AttachmentViewerFormData = {
|
||||||
|
row?: never;
|
||||||
|
url?: string;
|
||||||
|
name?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const AttachmentViewerForm: FC<
|
||||||
|
ComponentFormProps<AttachmentViewerFormData>
|
||||||
|
> = ({ data, Wrapper = Fragment, WrapperProps }) => {
|
||||||
|
return (
|
||||||
|
<Wrapper {...WrapperProps}>
|
||||||
|
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||||
|
<img
|
||||||
|
width="auto"
|
||||||
|
height={800}
|
||||||
|
style={{
|
||||||
|
cursor: "pointer",
|
||||||
|
objectFit: "contain",
|
||||||
|
}}
|
||||||
|
alt={data?.url}
|
||||||
|
src={data?.url}
|
||||||
|
/>
|
||||||
|
</Wrapper>
|
||||||
|
);
|
||||||
|
};
|
@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2025 Hexastack. All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
|
||||||
|
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
|
||||||
|
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { GenericFormDialog } from "@/app-components/dialogs";
|
||||||
|
import { ComponentFormDialogProps } from "@/types/common/dialogs.types";
|
||||||
|
|
||||||
|
import {
|
||||||
|
AttachmentViewerForm,
|
||||||
|
AttachmentViewerFormData,
|
||||||
|
} from "./AttachmentViewerForm";
|
||||||
|
|
||||||
|
export const AttachmentViewerFormDialog = <
|
||||||
|
T extends AttachmentViewerFormData = AttachmentViewerFormData,
|
||||||
|
>(
|
||||||
|
props: ComponentFormDialogProps<T>,
|
||||||
|
) => (
|
||||||
|
<GenericFormDialog<T>
|
||||||
|
Form={AttachmentViewerForm}
|
||||||
|
rowKey="row"
|
||||||
|
addText="label.image"
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
Loading…
Reference in New Issue
Block a user