Handle accept/reject follow requests for locked accounts

This commit is contained in:
Lim Chee Aun 2023-01-10 21:49:23 +08:00
parent 021d2aa2ae
commit 9faf730e82

View file

@ -85,6 +85,7 @@ function Notification({ notification }) {
</div> </div>
<div class="notification-content"> <div class="notification-content">
{type !== 'mention' && ( {type !== 'mention' && (
<>
<p> <p>
{!/poll|update/i.test(type) && ( {!/poll|update/i.test(type) && (
<> <>
@ -111,6 +112,15 @@ function Notification({ notification }) {
</span> </span>
)} )}
</p> </p>
{type === 'follow_request' && (
<FollowRequestButtons
accountID={account.id}
onChange={() => {
loadNotifications(true);
}}
/>
)}
</>
)} )}
{_accounts?.length > 1 && ( {_accounts?.length > 1 && (
<p class="avatars-stack"> <p class="avatars-stack">
@ -414,4 +424,50 @@ function Notifications() {
); );
} }
function FollowRequestButtons({ accountID, onChange }) {
const [uiState, setUIState] = useState('default');
return (
<p>
<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 memo(Notifications); export default memo(Notifications);