diff --git a/src/entities/action/lib.ts b/src/entities/action/lib.ts new file mode 100644 index 0000000..120d37d --- /dev/null +++ b/src/entities/action/lib.ts @@ -0,0 +1,20 @@ +import type { CommentAction } from "./schema"; + +type ActionAttachmentType = "empty" | "image" | "voice"; + +const imageExtensions = ["jpeg", "jpg", "png"]; +const voiceExtensions = ["mp3"]; + +export function getActionAttachmentType( + action: CommentAction, +): ActionAttachmentType { + if (action.fileUrls.length === 0) { + return "empty"; + } else if (imageExtensions.includes(action.fileUrls[0].split(".").at(-1)!)) { + return "image"; + } else if (voiceExtensions.includes(action.fileUrls[0].split(".").at(-1)!)) { + return "voice"; + } else { + return "empty"; + } +} diff --git a/src/widgets/chain-editor/ui/ChainEditor.tsx b/src/widgets/chain-editor/ui/ChainEditor.tsx index 662a9a5..9be04ef 100644 --- a/src/widgets/chain-editor/ui/ChainEditor.tsx +++ b/src/widgets/chain-editor/ui/ChainEditor.tsx @@ -2,6 +2,8 @@ import type { Chain } from "@/entities/chain/schema"; import { useChainState } from "@/entities/chain/model"; import { useNavigate } from "@tanstack/react-router"; +import { getActionAttachmentType } from "@/entities/action/lib"; + import { useState, useRef } from "react"; import humanizeDuration from "humanize-duration"; import { upsertChain } from "@/entities/chain/api/upsert"; @@ -99,15 +101,28 @@ export default function ChainEditor({ chain }: ChainEditorProps) { className="no-scrollbar flex grow flex-col items-center gap-y-24 overflow-y-scroll pb-20 pt-8" > {chain.actions.map((action, index) => { - if (action.actionType === "comment") + if (action.actionType === "comment") console.log(action); + + if (action.actionType === "comment") { + const attachmentType = getActionAttachmentType(action); + return (
- {action.text} + {attachmentType === "image" && ( + Image + )} + {action.text &&
{action.text}
}
); + } return (