edit voice messages
This commit is contained in:
parent
9aa85d1d2a
commit
b0e82f82c9
|
|
@ -11,7 +11,8 @@ import CircularProgress from "@mui/material/CircularProgress";
|
||||||
|
|
||||||
import TextFieldsIcon from "@mui/icons-material/TextFields";
|
import TextFieldsIcon from "@mui/icons-material/TextFields";
|
||||||
import ImageIcon from "@mui/icons-material/Image";
|
import ImageIcon from "@mui/icons-material/Image";
|
||||||
// import RecordVoiceOverIcon from "@mui/icons-material/RecordVoiceOver";
|
import RecordVoiceOverIcon from "@mui/icons-material/RecordVoiceOver";
|
||||||
|
import MicNoneIcon from "@mui/icons-material/MicNone";
|
||||||
|
|
||||||
interface TabPanelProps {
|
interface TabPanelProps {
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
|
|
@ -59,6 +60,8 @@ export default function ActionEditor({
|
||||||
canExit = false,
|
canExit = false,
|
||||||
}: ActionEditorProps) {
|
}: ActionEditorProps) {
|
||||||
const imageRef = useRef<HTMLInputElement>(null);
|
const imageRef = useRef<HTMLInputElement>(null);
|
||||||
|
const voiceRef = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
const attachmentType = initialAction
|
const attachmentType = initialAction
|
||||||
? getActionAttachmentType(initialAction)
|
? getActionAttachmentType(initialAction)
|
||||||
: "empty";
|
: "empty";
|
||||||
|
|
@ -75,6 +78,12 @@ export default function ActionEditor({
|
||||||
: null,
|
: null,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const [voiceUrl, setVoiceUrl] = useState<string | null>(
|
||||||
|
initialAction && attachmentType === "voice"
|
||||||
|
? initialAction.fileUrls[0]!
|
||||||
|
: null,
|
||||||
|
);
|
||||||
|
|
||||||
const [action, setAction] = useState<CommentAction>(
|
const [action, setAction] = useState<CommentAction>(
|
||||||
initialAction ?? {
|
initialAction ?? {
|
||||||
actionType: "comment",
|
actionType: "comment",
|
||||||
|
|
@ -106,6 +115,8 @@ export default function ActionEditor({
|
||||||
|
|
||||||
if (origin === "image") {
|
if (origin === "image") {
|
||||||
setImageUrl(fileUrl);
|
setImageUrl(fileUrl);
|
||||||
|
} else if (origin === "voice") {
|
||||||
|
setVoiceUrl(fileUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|
@ -137,9 +148,17 @@ export default function ActionEditor({
|
||||||
fileUrls: [imageUrl],
|
fileUrls: [imageUrl],
|
||||||
});
|
});
|
||||||
} else if (value === 2) {
|
} else if (value === 2) {
|
||||||
alert("Unsupported");
|
if (!voiceUrl) {
|
||||||
|
alert("Загрузите голосовое :3");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onSave(actionIndex, {
|
||||||
|
actionType: action.actionType,
|
||||||
|
text: null,
|
||||||
|
fileUrls: [voiceUrl],
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
@ -154,11 +173,11 @@ export default function ActionEditor({
|
||||||
>
|
>
|
||||||
<Tab label="Текст" icon={<TextFieldsIcon />} {...a11yProps(0)} />
|
<Tab label="Текст" icon={<TextFieldsIcon />} {...a11yProps(0)} />
|
||||||
<Tab label="Изображение" icon={<ImageIcon />} {...a11yProps(1)} />
|
<Tab label="Изображение" icon={<ImageIcon />} {...a11yProps(1)} />
|
||||||
{/* <Tab
|
<Tab
|
||||||
label="Голосовое"
|
label="Голосовое"
|
||||||
icon={<RecordVoiceOverIcon />}
|
icon={<RecordVoiceOverIcon />}
|
||||||
{...a11yProps(2)}
|
{...a11yProps(2)}
|
||||||
/> */}
|
/>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
|
|
@ -212,6 +231,7 @@ export default function ActionEditor({
|
||||||
|
|
||||||
<input
|
<input
|
||||||
ref={imageRef}
|
ref={imageRef}
|
||||||
|
accept="image/*"
|
||||||
type="file"
|
type="file"
|
||||||
className="mb-4 hidden select-none"
|
className="mb-4 hidden select-none"
|
||||||
onChange={async (e) => await handleFileChange(e, "image")}
|
onChange={async (e) => await handleFileChange(e, "image")}
|
||||||
|
|
@ -233,9 +253,37 @@ export default function ActionEditor({
|
||||||
/>
|
/>
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
|
|
||||||
{/* <TabPanel value={value} index={2}>
|
<TabPanel value={value} index={2}>
|
||||||
In progress
|
<div className="mt-5 text-center">
|
||||||
</TabPanel> */}
|
<input
|
||||||
|
ref={voiceRef}
|
||||||
|
type="file"
|
||||||
|
accept=".mp3"
|
||||||
|
className="mb-4 hidden select-none"
|
||||||
|
onChange={async (e) => await handleFileChange(e, "voice")}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
startIcon={<MicNoneIcon />}
|
||||||
|
variant="contained"
|
||||||
|
color="info"
|
||||||
|
disabled={loading}
|
||||||
|
onClick={() => {
|
||||||
|
if (!voiceRef.current) return;
|
||||||
|
voiceRef.current.click();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{voiceUrl ? "Изменить голосовое" : "Загрузить голосовое"}
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
{voiceUrl && (
|
||||||
|
<div className="mt-10 flex justify-center">
|
||||||
|
<audio controls>
|
||||||
|
<source src={voiceUrl} type="audio/mp3" />
|
||||||
|
</audio>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</TabPanel>
|
||||||
</Box>
|
</Box>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user