2022-09-07 10:00:28 +03:00
|
|
|
import React, { FC, useState } from 'react';
|
2022-01-13 00:52:37 +03:00
|
|
|
|
2022-10-29 08:39:20 +03:00
|
|
|
import { Button, Input, Modal } from 'antd';
|
2023-01-10 07:57:29 +03:00
|
|
|
import { STATUS_ERROR, STATUS_SUCCESS } from '../../utils/input-statuses';
|
|
|
|
import { fetchData, FEDERATION_MESSAGE_SEND } from '../../utils/apis';
|
2022-01-13 00:52:37 +03:00
|
|
|
|
|
|
|
const { TextArea } = Input;
|
|
|
|
|
2022-09-07 10:00:28 +03:00
|
|
|
export type ComposeFederatedPostProps = {
|
2022-11-02 00:50:23 +03:00
|
|
|
open: boolean;
|
2022-01-13 00:52:37 +03:00
|
|
|
handleClose: () => void;
|
2022-09-07 10:00:28 +03:00
|
|
|
};
|
2022-01-13 00:52:37 +03:00
|
|
|
|
2022-11-02 00:50:23 +03:00
|
|
|
export const ComposeFederatedPost: FC<ComposeFederatedPostProps> = ({ open, handleClose }) => {
|
2022-01-13 00:52:37 +03:00
|
|
|
const [content, setContent] = useState('');
|
|
|
|
const [postPending, setPostPending] = useState(false);
|
|
|
|
const [postSuccessState, setPostSuccessState] = useState(null);
|
|
|
|
|
|
|
|
function handleEditorChange(e) {
|
|
|
|
setContent(e.target.value);
|
|
|
|
}
|
|
|
|
|
2022-01-21 07:11:37 +03:00
|
|
|
function close() {
|
|
|
|
setPostPending(false);
|
|
|
|
setPostSuccessState(null);
|
|
|
|
handleClose();
|
|
|
|
}
|
|
|
|
|
2022-01-13 00:52:37 +03:00
|
|
|
async function sendButtonClicked() {
|
|
|
|
setPostPending(true);
|
|
|
|
|
|
|
|
const data = {
|
|
|
|
value: content,
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
await fetchData(FEDERATION_MESSAGE_SEND, {
|
|
|
|
data,
|
|
|
|
method: 'POST',
|
|
|
|
auth: true,
|
|
|
|
});
|
|
|
|
setPostSuccessState(STATUS_SUCCESS);
|
2022-01-21 07:11:37 +03:00
|
|
|
setTimeout(close, 1000);
|
2022-01-13 00:52:37 +03:00
|
|
|
} catch (e) {
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
console.error(e);
|
|
|
|
setPostSuccessState(STATUS_ERROR);
|
|
|
|
}
|
|
|
|
setPostPending(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Modal
|
|
|
|
destroyOnClose
|
|
|
|
width={600}
|
|
|
|
title="Post to Followers"
|
2022-11-02 00:50:23 +03:00
|
|
|
open={open}
|
2022-01-13 00:52:37 +03:00
|
|
|
onCancel={handleClose}
|
|
|
|
footer={[
|
|
|
|
<Button onClick={() => handleClose()}>Cancel</Button>,
|
|
|
|
<Button
|
|
|
|
type="primary"
|
|
|
|
onClick={sendButtonClicked}
|
|
|
|
disabled={postPending || postSuccessState}
|
|
|
|
loading={postPending}
|
|
|
|
>
|
|
|
|
{postSuccessState?.toUpperCase() || 'Post'}
|
|
|
|
</Button>,
|
|
|
|
]}
|
|
|
|
>
|
2022-12-19 22:58:04 +03:00
|
|
|
<h3>
|
|
|
|
Tell the world about your future streaming plans or let your followers know to tune in.
|
|
|
|
</h3>
|
2022-10-29 08:39:20 +03:00
|
|
|
<TextArea
|
2022-12-19 22:58:04 +03:00
|
|
|
placeholder="I'm still live, come join me!"
|
2022-10-29 08:39:20 +03:00
|
|
|
size="large"
|
|
|
|
showCount
|
|
|
|
maxLength={500}
|
|
|
|
style={{ height: '150px', width: '100%' }}
|
|
|
|
onChange={handleEditorChange}
|
|
|
|
/>
|
2022-01-13 00:52:37 +03:00
|
|
|
</Modal>
|
|
|
|
);
|
2022-09-07 10:00:28 +03:00
|
|
|
};
|