2022-08-23 04:29:37 +03:00
|
|
|
/* eslint-disable react/no-unescaped-entities */
|
2022-08-23 04:27:47 +03:00
|
|
|
import { Input, Button, Alert, Spin, Space } from 'antd';
|
2022-09-07 10:00:28 +03:00
|
|
|
import { FC, useState } from 'react';
|
|
|
|
import styles from './FollowModal.module.scss';
|
2023-04-17 00:17:13 +03:00
|
|
|
import { isValidFediverseAccount } from '../../../utils/validators';
|
2022-06-25 01:55:53 +03:00
|
|
|
|
|
|
|
const ENDPOINT = '/api/remotefollow';
|
|
|
|
|
2022-09-07 10:00:28 +03:00
|
|
|
export type FollowModalProps = {
|
2022-06-25 01:55:53 +03:00
|
|
|
handleClose: () => void;
|
2022-08-23 04:27:47 +03:00
|
|
|
account: string;
|
|
|
|
name: string;
|
2022-09-07 10:00:28 +03:00
|
|
|
};
|
2022-06-25 01:55:53 +03:00
|
|
|
|
2022-09-07 10:00:28 +03:00
|
|
|
export const FollowModal: FC<FollowModalProps> = ({ handleClose, account, name }) => {
|
2022-08-23 04:27:47 +03:00
|
|
|
const [remoteAccount, setRemoteAccount] = useState(null);
|
2022-06-25 01:55:53 +03:00
|
|
|
const [valid, setValid] = useState(false);
|
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
const [errorMessage, setErrorMessage] = useState(null);
|
|
|
|
|
|
|
|
const handleAccountChange = a => {
|
2022-08-23 04:27:47 +03:00
|
|
|
setRemoteAccount(a);
|
2023-04-17 00:17:13 +03:00
|
|
|
if (isValidFediverseAccount(a)) {
|
2022-06-25 01:55:53 +03:00
|
|
|
setValid(true);
|
|
|
|
} else {
|
|
|
|
setValid(false);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-08-23 04:27:47 +03:00
|
|
|
const joinButtonPressed = () => {
|
|
|
|
window.open('https://owncast.online/join-fediverse', '_blank');
|
|
|
|
};
|
|
|
|
|
2022-06-25 01:55:53 +03:00
|
|
|
const remoteFollowButtonPressed = async () => {
|
|
|
|
if (!valid) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
setLoading(true);
|
|
|
|
|
|
|
|
try {
|
2022-08-23 04:27:47 +03:00
|
|
|
const sanitizedAccount = remoteAccount.replace(/^@+/, '');
|
2022-06-25 01:55:53 +03:00
|
|
|
const request = { account: sanitizedAccount };
|
|
|
|
const rawResponse = await fetch(ENDPOINT, {
|
|
|
|
method: 'POST',
|
|
|
|
body: JSON.stringify(request),
|
|
|
|
});
|
|
|
|
const result = await rawResponse.json();
|
|
|
|
|
|
|
|
if (result.redirectUrl) {
|
|
|
|
window.open(result.redirectUrl, '_blank');
|
|
|
|
handleClose();
|
|
|
|
}
|
|
|
|
if (!result.success) {
|
|
|
|
setErrorMessage(result.message);
|
|
|
|
setLoading(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!result.redirectUrl) {
|
|
|
|
setErrorMessage('Unable to follow.');
|
|
|
|
setLoading(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
setErrorMessage(e.message);
|
|
|
|
}
|
|
|
|
setLoading(false);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2022-12-12 08:06:20 +03:00
|
|
|
<Space direction="vertical" id="follow-modal">
|
2022-09-07 10:00:28 +03:00
|
|
|
<div className={styles.header}>
|
2022-08-23 04:27:47 +03:00
|
|
|
By following this stream you'll get notified on the Fediverse when it goes live. Now is a
|
2022-08-23 04:29:37 +03:00
|
|
|
great time to
|
2022-08-23 04:27:47 +03:00
|
|
|
<a href="https://owncast.online/join-fediverse" target="_blank" rel="noreferrer">
|
2022-12-06 09:11:06 +03:00
|
|
|
learn about the Fediverse
|
2022-08-23 04:29:37 +03:00
|
|
|
</a>
|
2022-08-23 04:27:47 +03:00
|
|
|
if it's new to you.
|
2022-06-25 01:55:53 +03:00
|
|
|
</div>
|
2022-08-23 04:27:47 +03:00
|
|
|
|
|
|
|
<Spin spinning={loading}>
|
|
|
|
{errorMessage && (
|
|
|
|
<Alert message="Follow Error" description={errorMessage} type="error" showIcon />
|
|
|
|
)}
|
2022-09-07 10:00:28 +03:00
|
|
|
<div className={styles.account}>
|
|
|
|
<img src="/logo" alt="logo" className={styles.logo} />
|
|
|
|
<div className={styles.username}>
|
|
|
|
<div className={styles.name}>{name}</div>
|
2022-08-23 04:27:47 +03:00
|
|
|
<div>{account}</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div>
|
2022-09-07 10:00:28 +03:00
|
|
|
<div className={styles.instructions}>Enter your username @server to follow</div>
|
2022-08-23 04:27:47 +03:00
|
|
|
<Input
|
2022-10-05 04:43:15 +03:00
|
|
|
value={remoteAccount}
|
2022-08-23 04:27:47 +03:00
|
|
|
size="large"
|
|
|
|
onChange={e => handleAccountChange(e.target.value)}
|
|
|
|
placeholder="Your fediverse account @account@server"
|
2022-10-05 04:43:15 +03:00
|
|
|
defaultValue={remoteAccount}
|
2022-08-23 04:27:47 +03:00
|
|
|
/>
|
2022-09-07 10:00:28 +03:00
|
|
|
<div className={styles.footer}>
|
2022-08-23 04:27:47 +03:00
|
|
|
You'll be redirected to your Fediverse server and asked to confirm the action.
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-09-07 10:00:28 +03:00
|
|
|
<Space className={styles.buttons}>
|
2022-08-30 09:17:12 +03:00
|
|
|
<Button disabled={!valid} type="primary" onClick={remoteFollowButtonPressed}>
|
2022-08-23 04:27:47 +03:00
|
|
|
Follow
|
|
|
|
</Button>
|
2022-08-30 09:17:12 +03:00
|
|
|
<Button onClick={joinButtonPressed} type="primary">
|
|
|
|
Join the Fediverse
|
|
|
|
</Button>
|
2022-08-23 04:27:47 +03:00
|
|
|
</Space>
|
|
|
|
</Spin>
|
|
|
|
</Space>
|
2022-06-25 01:55:53 +03:00
|
|
|
);
|
2022-09-07 10:00:28 +03:00
|
|
|
};
|