TypeScript: actions

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak
2022-06-10 19:56:22 +02:00
parent 58539146a4
commit 708c3a9e64
27 changed files with 188 additions and 214 deletions

View File

@@ -6,6 +6,8 @@ import { fetchCaptcha } from 'soapbox/actions/auth';
import { Stack, Text, Input } from 'soapbox/components/ui';
import { useAppDispatch } from 'soapbox/hooks';
import type { AxiosResponse } from 'axios';
const noOp = () => {};
const messages = defineMessages({
@@ -39,7 +41,7 @@ const CaptchaField: React.FC<ICaptchaField> = ({
const [refresh, setRefresh] = useState<NodeJS.Timer | undefined>(undefined);
const getCaptcha = () => {
dispatch(fetchCaptcha()).then(response => {
dispatch(fetchCaptcha()).then((response: AxiosResponse) => {
const captcha = ImmutableMap<string, any>(response.data);
setCaptcha(captcha);
onFetch(captcha);

View File

@@ -1,5 +1,4 @@
import React, { useState } from 'react';
import { useIntl } from 'react-intl';
import { Redirect } from 'react-router-dom';
import { logIn, verifyCredentials, switchAccount } from 'soapbox/actions/auth';
@@ -15,7 +14,6 @@ import OtpAuthForm from './otp_auth_form';
import type { AxiosError } from 'axios';
const LoginPage = () => {
const intl = useIntl();
const dispatch = useAppDispatch();
const me = useAppSelector((state) => state.me);
@@ -36,8 +34,8 @@ const LoginPage = () => {
const handleSubmit: React.FormEventHandler = (event) => {
const { username, password } = getFormData(event.target as HTMLFormElement);
dispatch(logIn(intl, username, password)).then(({ access_token }: { access_token: string }) => {
return dispatch(verifyCredentials(access_token))
dispatch(logIn(username, password)).then(({ access_token }) => {
return dispatch(verifyCredentials(access_token as string))
// Refetch the instance for authenticated fetch
.then(() => dispatch(fetchInstance() as any));
}).then((account: { id: string }) => {

View File

@@ -1,5 +1,4 @@
import React, { useEffect, useState } from 'react';
import { useIntl } from 'react-intl';
import { useDispatch } from 'react-redux';
import { Redirect } from 'react-router-dom';
@@ -8,12 +7,11 @@ import { Spinner } from 'soapbox/components/ui';
/** Component that logs the user out when rendered */
const Logout: React.FC = () => {
const intl = useIntl();
const dispatch = useDispatch();
const [done, setDone] = useState(false);
useEffect(() => {
dispatch(logOut(intl) as any)
dispatch(logOut() as any)
.then(() => setDone(true))
.catch(console.warn);
}, []);

View File

@@ -32,8 +32,8 @@ const OtpAuthForm: React.FC<IOtpAuthForm> = ({ mfa_token }) => {
const { code } = getFormData(event.target);
dispatch(otpVerify(code, mfa_token)).then(({ access_token }) => {
setCodeError(false);
return dispatch(verifyCredentials(access_token));
}).then(account => {
return dispatch(verifyCredentials(access_token as string));
}).then((account: Record<string, any>) => {
setShouldRedirect(true);
return dispatch(switchAccount(account.id));
}).catch(() => {

View File

@@ -2,10 +2,7 @@ import classNames from 'classnames';
import React, { useEffect, useState } from 'react';
import { defineMessages, useIntl } from 'react-intl';
import {
fetchBackups,
createBackup,
} from 'soapbox/actions/backups';
import { fetchBackups, createBackup } from 'soapbox/actions/backups';
import ScrollableList from 'soapbox/components/scrollable_list';
import { useAppDispatch, useAppSelector } from 'soapbox/hooks';

View File

@@ -20,7 +20,7 @@ interface IChat {
const Chat: React.FC<IChat> = ({ chatId, onClick }) => {
const chat = useAppSelector((state) => {
const chat = state.chats.getIn(['items', chatId]);
const chat = state.chats.items.get(chatId);
return chat ? getChat(state, (chat as any).toJS()) : undefined;
}) as ChatEntity;

View File

@@ -49,9 +49,9 @@ const ChatList: React.FC<IChatList> = ({ onClickChat, useWindowScroll = false })
const dispatch = useDispatch();
const intl = useIntl();
const chatIds = useAppSelector(state => sortedChatIdsSelector(state.chats.get('items')));
const hasMore = useAppSelector(state => !!state.chats.get('next'));
const isLoading = useAppSelector(state => state.chats.get('isLoading'));
const chatIds = useAppSelector(state => sortedChatIdsSelector(state.chats.items));
const hasMore = useAppSelector(state => !!state.chats.next);
const isLoading = useAppSelector(state => state.chats.isLoading);
const handleLoadMore = useCallback(() => {
if (hasMore && !isLoading) {

View File

@@ -48,7 +48,7 @@ const Header = () => {
event.preventDefault();
setLoading(true);
dispatch(logIn(intl, username, password) as any)
dispatch(logIn(username, password) as any)
.then(({ access_token }: { access_token: string }) => {
return (
dispatch(verifyCredentials(access_token) as any)

View File

@@ -1,6 +1,6 @@
import classNames from 'classnames';
import React from 'react';
import { FormattedMessage, useIntl } from 'react-intl';
import { FormattedMessage } from 'react-intl';
import { useDispatch } from 'react-redux';
import { Link } from 'react-router-dom';
@@ -27,11 +27,10 @@ const LinkFooter: React.FC = (): JSX.Element => {
const features = useFeatures();
const soapboxConfig = useSoapboxConfig();
const intl = useIntl();
const dispatch = useDispatch();
const onClickLogOut: React.EventHandler<React.MouseEvent> = (e) => {
dispatch(logOut(intl));
dispatch(logOut());
e.preventDefault();
};

View File

@@ -44,7 +44,7 @@ const Navbar = () => {
event.preventDefault();
setLoading(true);
dispatch(logIn(intl, username, password) as any)
dispatch(logIn(username, password) as any)
.then(({ access_token }: { access_token: string }) => {
setLoading(false);

View File

@@ -43,7 +43,7 @@ const ProfileDropdown: React.FC<IProfileDropdown> = ({ account, children }) => {
const otherAccounts = useAppSelector((state) => authUsers.map((authUser: any) => getAccount(state, authUser.get('id'))));
const handleLogOut = () => {
dispatch(logOut(intl));
dispatch(logOut());
};
const handleSwitchAccount = (account: AccountEntity) => {

View File

@@ -50,7 +50,7 @@ const Registration = () => {
// TODO: handle validation errors from Pepe
dispatch(createAccount(username, password))
.then(() => dispatch(logIn(intl, username, password)))
.then(() => dispatch(logIn(username, password)))
.then(({ access_token }: any) => dispatch(verifyCredentials(access_token)))
.then(() => dispatch(fetchInstance()))
.then(() => {

View File

@@ -1,5 +1,4 @@
import React, { useEffect } from 'react';
import { useIntl } from 'react-intl';
import { useDispatch } from 'react-redux';
import { Link } from 'react-router-dom';
@@ -12,7 +11,6 @@ import { useAppSelector, useOwnAccount } from 'soapbox/hooks';
const WaitlistPage = (/* { account } */) => {
const dispatch = useDispatch();
const intl = useIntl();
const title = useAppSelector((state) => state.instance.title);
const me = useOwnAccount();
@@ -20,7 +18,7 @@ const WaitlistPage = (/* { account } */) => {
const onClickLogOut: React.MouseEventHandler = (event) => {
event.preventDefault();
dispatch(logOut(intl));
dispatch(logOut());
};
const openVerifySmsModal = () => dispatch(openModal('VERIFY_SMS'));