pl-fe: improve types

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2024-11-22 13:37:33 +01:00
parent c907e10138
commit ac44543b55
11 changed files with 43 additions and 32 deletions

View file

@ -23,7 +23,7 @@ interface FetchAboutPageFailAction {
type: typeof FETCH_ABOUT_PAGE_FAIL;
slug: string;
locale?: string;
error: any;
error: unknown;
}
const fetchAboutPage = (slug = 'index', locale?: string) => (dispatch: AppDispatch, getState: () => RootState) => {

View file

@ -174,7 +174,7 @@ interface VerifyCredentialsSuccessAction {
interface VerifyCredentialsFailAction {
type: typeof VERIFY_CREDENTIALS_FAIL;
token: string;
error: any;
error: unknown;
}
const verifyCredentials = (token: string, accountUrl?: string) =>
@ -220,7 +220,7 @@ interface AuthAccountRememberSuccessAction {
interface AuthAccountRememberFailAction {
type: typeof AUTH_ACCOUNT_REMEMBER_FAIL;
error: any;
error: unknown;
accountUrl: string;
skipAlert: boolean;
}

View file

@ -27,15 +27,16 @@ const messages = defineMessages({
type ExportDataAction = {
type: typeof EXPORT_FOLLOWS_REQUEST
| typeof EXPORT_FOLLOWS_SUCCESS
| typeof EXPORT_FOLLOWS_FAIL
| typeof EXPORT_BLOCKS_REQUEST
| typeof EXPORT_BLOCKS_SUCCESS
| typeof EXPORT_BLOCKS_FAIL
| typeof EXPORT_MUTES_REQUEST
| typeof EXPORT_MUTES_SUCCESS
| typeof EXPORT_FOLLOWS_SUCCESS
| typeof EXPORT_BLOCKS_SUCCESS
| typeof EXPORT_MUTES_SUCCESS;
} | {
type: typeof EXPORT_FOLLOWS_FAIL
| typeof EXPORT_BLOCKS_FAIL
| typeof EXPORT_MUTES_FAIL;
error?: any;
error?: unknown;
}
const fileExport = (content: string, fileName: string) => {

View file

@ -20,16 +20,18 @@ const IMPORT_MUTES_FAIL = 'IMPORT_MUTES_FAIL' as const;
type ImportDataActions = {
type: typeof IMPORT_FOLLOWS_REQUEST
| typeof IMPORT_FOLLOWS_SUCCESS
| typeof IMPORT_FOLLOWS_FAIL
| typeof IMPORT_BLOCKS_REQUEST
| typeof IMPORT_MUTES_REQUEST;
} | {
type: typeof IMPORT_FOLLOWS_SUCCESS
| typeof IMPORT_BLOCKS_SUCCESS
| typeof IMPORT_BLOCKS_FAIL
| typeof IMPORT_MUTES_REQUEST
| typeof IMPORT_MUTES_SUCCESS
| typeof IMPORT_MUTES_FAIL;
error?: any;
| typeof IMPORT_MUTES_SUCCESS;
response?: string;
} | {
type: | typeof IMPORT_FOLLOWS_FAIL
| typeof IMPORT_BLOCKS_FAIL
| typeof IMPORT_MUTES_FAIL;
error?: unknown;
}
const messages = defineMessages({

View file

@ -26,7 +26,7 @@ interface InstanceFetchSuccessAction {
interface InstanceFetchFailAction {
type: typeof INSTANCE_FETCH_FAIL;
error: any;
error: unknown;
}
const fetchInstance = () => async (dispatch: AppDispatch, getState: () => RootState) => {

View file

@ -310,7 +310,7 @@ const addToListSuccess = (listId: string, accountId: string) => ({
accountId,
});
const addToListFail = (listId: string, accountId: string, error: any) => ({
const addToListFail = (listId: string, accountId: string, error: unknown) => ({
type: LIST_EDITOR_ADD_FAIL,
listId,
accountId,

View file

@ -16,10 +16,10 @@ const messages = defineMessages({
exceededVideoDurationLimit: { id: 'upload_error.video_duration_limit', defaultMessage: 'Video exceeds the current duration limit ({limit, plural, one {# second} other {# seconds}})' },
});
const noOp = (e: any) => {};
const noOp = () => {};
const updateMedia = (mediaId: string, params: Record<string, any>) =>
(dispatch: any, getState: () => RootState) =>
(_dispatch: AppDispatch, getState: () => RootState) =>
getClient(getState()).media.updateMedia(mediaId, params);
const uploadMedia = (body: UploadMediaParams, onUploadProgress: (e: ProgressEvent) => void = noOp) =>

View file

@ -6,7 +6,17 @@ import { getClient } from '../api';
import { importEntities } from './importer';
import type { PaginatedResponse, Status as BaseStatus, PublicTimelineParams, HomeTimelineParams, ListTimelineParams, HashtagTimelineParams, GetAccountStatusesParams, GroupTimelineParams } from 'pl-api';
import type {
Account as BaseAccount,
GetAccountStatusesParams,
GroupTimelineParams,
HashtagTimelineParams,
HomeTimelineParams,
ListTimelineParams,
PaginatedResponse,
PublicTimelineParams,
Status as BaseStatus,
} from 'pl-api';
import type { AppDispatch, RootState } from 'pl-fe/store';
const TIMELINE_UPDATE = 'TIMELINE_UPDATE' as const;
@ -133,20 +143,16 @@ const parseTags = (tags: Record<string, any[]> = {}, mode: 'any' | 'all' | 'none
(tags[mode] || []).map((tag) => tag.value);
const deduplicateStatuses = (statuses: Array<BaseStatus>) => {
const deduplicatedStatuses: any[] = [];
const deduplicatedStatuses: Array<BaseStatus & { accounts: Array<BaseAccount> }> = [];
for (const status of statuses) {
const reblogged = status.reblog && deduplicatedStatuses.find((deduplicatedStatus) => deduplicatedStatus.reblog?.id === status.reblog?.id);
if (reblogged) {
if (reblogged.accounts) {
reblogged.accounts.push(status.account);
} else {
reblogged.accounts = [reblogged.account, status.account];
}
reblogged.accounts.push(status.account);
reblogged.id += ':' + status.id;
} else if (!deduplicatedStatuses.find((deduplicatedStatus) => deduplicatedStatus.reblog?.id === status.id)) {
deduplicatedStatuses.push(status);
deduplicatedStatuses.push({ accounts: [status.account], ...status });
}
}

View file

@ -7,14 +7,16 @@ import AutosuggestAccountInput from 'pl-fe/components/autosuggest-account-input'
import SvgIcon from 'pl-fe/components/ui/svg-icon';
import { useAppDispatch } from 'pl-fe/hooks/use-app-dispatch';
import { selectAccount } from 'pl-fe/selectors';
import { AppDispatch, RootState } from 'pl-fe/store';
import type { AppDispatch, RootState } from 'pl-fe/store';
import type { History } from 'pl-fe/types/history';
const messages = defineMessages({
placeholder: { id: 'search.placeholder', defaultMessage: 'Search' },
action: { id: 'search.action', defaultMessage: 'Search for “{query}”' },
});
const redirectToAccount = (accountId: string, routerHistory: any) =>
const redirectToAccount = (accountId: string, routerHistory: History) =>
(_dispatch: AppDispatch, getState: () => RootState) => {
const acct = selectAccount(getState(), accountId)!.acct;

View file

@ -1,5 +1,5 @@
/** ID of this iframe (given by embed.js) when embedded on a page. */
let iframeId: any;
let iframeId: string;
/** Receive iframe messages. */
// https://github.com/mastodon/mastodon/pull/4853

View file

@ -8,7 +8,7 @@ const initialState = {
const meta = (state = initialState, action: InstanceAction): typeof initialState => {
switch (action.type) {
case INSTANCE_FETCH_FAIL:
if (action.error?.response?.status === 404) {
if ((action.error as any)?.response?.status === 404) {
return { instance_fetch_failed: true };
}
return state;