mirror of
https://github.com/cheeaun/phanpy.git
synced 2024-12-25 19:58:15 +03:00
55 lines
1.3 KiB
React
55 lines
1.3 KiB
React
|
import { useState } from 'preact/hooks';
|
||
|
|
||
|
import { api } from '../utils/api';
|
||
|
|
||
|
import Loader from './loader';
|
||
|
|
||
|
function FollowRequestButtons({ accountID, onChange }) {
|
||
|
const { masto } = api();
|
||
|
const [uiState, setUIState] = useState('default');
|
||
|
return (
|
||
|
<p class="follow-request-buttons">
|
||
|
<button
|
||
|
type="button"
|
||
|
disabled={uiState === 'loading'}
|
||
|
onClick={() => {
|
||
|
setUIState('loading');
|
||
|
(async () => {
|
||
|
try {
|
||
|
await masto.v1.followRequests.authorize(accountID);
|
||
|
onChange();
|
||
|
} catch (e) {
|
||
|
console.error(e);
|
||
|
setUIState('default');
|
||
|
}
|
||
|
})();
|
||
|
}}
|
||
|
>
|
||
|
Accept
|
||
|
</button>{' '}
|
||
|
<button
|
||
|
type="button"
|
||
|
disabled={uiState === 'loading'}
|
||
|
class="light danger"
|
||
|
onClick={() => {
|
||
|
setUIState('loading');
|
||
|
(async () => {
|
||
|
try {
|
||
|
await masto.v1.followRequests.reject(accountID);
|
||
|
onChange();
|
||
|
} catch (e) {
|
||
|
console.error(e);
|
||
|
setUIState('default');
|
||
|
}
|
||
|
})();
|
||
|
}}
|
||
|
>
|
||
|
Reject
|
||
|
</button>
|
||
|
<Loader hidden={uiState !== 'loading'} />
|
||
|
</p>
|
||
|
);
|
||
|
}
|
||
|
|
||
|
export default FollowRequestButtons;
|