pl-fe: improve types
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
c907e10138
commit
ac44543b55
11 changed files with 43 additions and 32 deletions
|
@ -23,7 +23,7 @@ interface FetchAboutPageFailAction {
|
||||||
type: typeof FETCH_ABOUT_PAGE_FAIL;
|
type: typeof FETCH_ABOUT_PAGE_FAIL;
|
||||||
slug: string;
|
slug: string;
|
||||||
locale?: string;
|
locale?: string;
|
||||||
error: any;
|
error: unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchAboutPage = (slug = 'index', locale?: string) => (dispatch: AppDispatch, getState: () => RootState) => {
|
const fetchAboutPage = (slug = 'index', locale?: string) => (dispatch: AppDispatch, getState: () => RootState) => {
|
||||||
|
|
|
@ -174,7 +174,7 @@ interface VerifyCredentialsSuccessAction {
|
||||||
interface VerifyCredentialsFailAction {
|
interface VerifyCredentialsFailAction {
|
||||||
type: typeof VERIFY_CREDENTIALS_FAIL;
|
type: typeof VERIFY_CREDENTIALS_FAIL;
|
||||||
token: string;
|
token: string;
|
||||||
error: any;
|
error: unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
const verifyCredentials = (token: string, accountUrl?: string) =>
|
const verifyCredentials = (token: string, accountUrl?: string) =>
|
||||||
|
@ -220,7 +220,7 @@ interface AuthAccountRememberSuccessAction {
|
||||||
|
|
||||||
interface AuthAccountRememberFailAction {
|
interface AuthAccountRememberFailAction {
|
||||||
type: typeof AUTH_ACCOUNT_REMEMBER_FAIL;
|
type: typeof AUTH_ACCOUNT_REMEMBER_FAIL;
|
||||||
error: any;
|
error: unknown;
|
||||||
accountUrl: string;
|
accountUrl: string;
|
||||||
skipAlert: boolean;
|
skipAlert: boolean;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,15 +27,16 @@ const messages = defineMessages({
|
||||||
|
|
||||||
type ExportDataAction = {
|
type ExportDataAction = {
|
||||||
type: typeof EXPORT_FOLLOWS_REQUEST
|
type: typeof EXPORT_FOLLOWS_REQUEST
|
||||||
| typeof EXPORT_FOLLOWS_SUCCESS
|
|
||||||
| typeof EXPORT_FOLLOWS_FAIL
|
|
||||||
| typeof EXPORT_BLOCKS_REQUEST
|
| typeof EXPORT_BLOCKS_REQUEST
|
||||||
| typeof EXPORT_BLOCKS_SUCCESS
|
|
||||||
| typeof EXPORT_BLOCKS_FAIL
|
|
||||||
| typeof EXPORT_MUTES_REQUEST
|
| 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;
|
| typeof EXPORT_MUTES_FAIL;
|
||||||
error?: any;
|
error?: unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
const fileExport = (content: string, fileName: string) => {
|
const fileExport = (content: string, fileName: string) => {
|
||||||
|
|
|
@ -20,16 +20,18 @@ const IMPORT_MUTES_FAIL = 'IMPORT_MUTES_FAIL' as const;
|
||||||
|
|
||||||
type ImportDataActions = {
|
type ImportDataActions = {
|
||||||
type: typeof IMPORT_FOLLOWS_REQUEST
|
type: typeof IMPORT_FOLLOWS_REQUEST
|
||||||
| typeof IMPORT_FOLLOWS_SUCCESS
|
|
||||||
| typeof IMPORT_FOLLOWS_FAIL
|
|
||||||
| typeof IMPORT_BLOCKS_REQUEST
|
| typeof IMPORT_BLOCKS_REQUEST
|
||||||
|
| typeof IMPORT_MUTES_REQUEST;
|
||||||
|
} | {
|
||||||
|
type: typeof IMPORT_FOLLOWS_SUCCESS
|
||||||
| typeof IMPORT_BLOCKS_SUCCESS
|
| typeof IMPORT_BLOCKS_SUCCESS
|
||||||
| typeof IMPORT_BLOCKS_FAIL
|
| typeof IMPORT_MUTES_SUCCESS;
|
||||||
| typeof IMPORT_MUTES_REQUEST
|
|
||||||
| typeof IMPORT_MUTES_SUCCESS
|
|
||||||
| typeof IMPORT_MUTES_FAIL;
|
|
||||||
error?: any;
|
|
||||||
response?: string;
|
response?: string;
|
||||||
|
} | {
|
||||||
|
type: | typeof IMPORT_FOLLOWS_FAIL
|
||||||
|
| typeof IMPORT_BLOCKS_FAIL
|
||||||
|
| typeof IMPORT_MUTES_FAIL;
|
||||||
|
error?: unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
|
|
|
@ -26,7 +26,7 @@ interface InstanceFetchSuccessAction {
|
||||||
|
|
||||||
interface InstanceFetchFailAction {
|
interface InstanceFetchFailAction {
|
||||||
type: typeof INSTANCE_FETCH_FAIL;
|
type: typeof INSTANCE_FETCH_FAIL;
|
||||||
error: any;
|
error: unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchInstance = () => async (dispatch: AppDispatch, getState: () => RootState) => {
|
const fetchInstance = () => async (dispatch: AppDispatch, getState: () => RootState) => {
|
||||||
|
|
|
@ -310,7 +310,7 @@ const addToListSuccess = (listId: string, accountId: string) => ({
|
||||||
accountId,
|
accountId,
|
||||||
});
|
});
|
||||||
|
|
||||||
const addToListFail = (listId: string, accountId: string, error: any) => ({
|
const addToListFail = (listId: string, accountId: string, error: unknown) => ({
|
||||||
type: LIST_EDITOR_ADD_FAIL,
|
type: LIST_EDITOR_ADD_FAIL,
|
||||||
listId,
|
listId,
|
||||||
accountId,
|
accountId,
|
||||||
|
|
|
@ -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}})' },
|
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>) =>
|
const updateMedia = (mediaId: string, params: Record<string, any>) =>
|
||||||
(dispatch: any, getState: () => RootState) =>
|
(_dispatch: AppDispatch, getState: () => RootState) =>
|
||||||
getClient(getState()).media.updateMedia(mediaId, params);
|
getClient(getState()).media.updateMedia(mediaId, params);
|
||||||
|
|
||||||
const uploadMedia = (body: UploadMediaParams, onUploadProgress: (e: ProgressEvent) => void = noOp) =>
|
const uploadMedia = (body: UploadMediaParams, onUploadProgress: (e: ProgressEvent) => void = noOp) =>
|
||||||
|
|
|
@ -6,7 +6,17 @@ import { getClient } from '../api';
|
||||||
|
|
||||||
import { importEntities } from './importer';
|
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';
|
import type { AppDispatch, RootState } from 'pl-fe/store';
|
||||||
|
|
||||||
const TIMELINE_UPDATE = 'TIMELINE_UPDATE' as const;
|
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);
|
(tags[mode] || []).map((tag) => tag.value);
|
||||||
|
|
||||||
const deduplicateStatuses = (statuses: Array<BaseStatus>) => {
|
const deduplicateStatuses = (statuses: Array<BaseStatus>) => {
|
||||||
const deduplicatedStatuses: any[] = [];
|
const deduplicatedStatuses: Array<BaseStatus & { accounts: Array<BaseAccount> }> = [];
|
||||||
|
|
||||||
for (const status of statuses) {
|
for (const status of statuses) {
|
||||||
const reblogged = status.reblog && deduplicatedStatuses.find((deduplicatedStatus) => deduplicatedStatus.reblog?.id === status.reblog?.id);
|
const reblogged = status.reblog && deduplicatedStatuses.find((deduplicatedStatus) => deduplicatedStatus.reblog?.id === status.reblog?.id);
|
||||||
|
|
||||||
if (reblogged) {
|
if (reblogged) {
|
||||||
if (reblogged.accounts) {
|
reblogged.accounts.push(status.account);
|
||||||
reblogged.accounts.push(status.account);
|
|
||||||
} else {
|
|
||||||
reblogged.accounts = [reblogged.account, status.account];
|
|
||||||
}
|
|
||||||
reblogged.id += ':' + status.id;
|
reblogged.id += ':' + status.id;
|
||||||
} else if (!deduplicatedStatuses.find((deduplicatedStatus) => deduplicatedStatus.reblog?.id === status.id)) {
|
} else if (!deduplicatedStatuses.find((deduplicatedStatus) => deduplicatedStatus.reblog?.id === status.id)) {
|
||||||
deduplicatedStatuses.push(status);
|
deduplicatedStatuses.push({ accounts: [status.account], ...status });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,14 +7,16 @@ import AutosuggestAccountInput from 'pl-fe/components/autosuggest-account-input'
|
||||||
import SvgIcon from 'pl-fe/components/ui/svg-icon';
|
import SvgIcon from 'pl-fe/components/ui/svg-icon';
|
||||||
import { useAppDispatch } from 'pl-fe/hooks/use-app-dispatch';
|
import { useAppDispatch } from 'pl-fe/hooks/use-app-dispatch';
|
||||||
import { selectAccount } from 'pl-fe/selectors';
|
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({
|
const messages = defineMessages({
|
||||||
placeholder: { id: 'search.placeholder', defaultMessage: 'Search' },
|
placeholder: { id: 'search.placeholder', defaultMessage: 'Search' },
|
||||||
action: { id: 'search.action', defaultMessage: 'Search for “{query}”' },
|
action: { id: 'search.action', defaultMessage: 'Search for “{query}”' },
|
||||||
});
|
});
|
||||||
|
|
||||||
const redirectToAccount = (accountId: string, routerHistory: any) =>
|
const redirectToAccount = (accountId: string, routerHistory: History) =>
|
||||||
(_dispatch: AppDispatch, getState: () => RootState) => {
|
(_dispatch: AppDispatch, getState: () => RootState) => {
|
||||||
const acct = selectAccount(getState(), accountId)!.acct;
|
const acct = selectAccount(getState(), accountId)!.acct;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/** ID of this iframe (given by embed.js) when embedded on a page. */
|
/** ID of this iframe (given by embed.js) when embedded on a page. */
|
||||||
let iframeId: any;
|
let iframeId: string;
|
||||||
|
|
||||||
/** Receive iframe messages. */
|
/** Receive iframe messages. */
|
||||||
// https://github.com/mastodon/mastodon/pull/4853
|
// https://github.com/mastodon/mastodon/pull/4853
|
||||||
|
|
|
@ -8,7 +8,7 @@ const initialState = {
|
||||||
const meta = (state = initialState, action: InstanceAction): typeof initialState => {
|
const meta = (state = initialState, action: InstanceAction): typeof initialState => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case INSTANCE_FETCH_FAIL:
|
case INSTANCE_FETCH_FAIL:
|
||||||
if (action.error?.response?.status === 404) {
|
if ((action.error as any)?.response?.status === 404) {
|
||||||
return { instance_fetch_failed: true };
|
return { instance_fetch_failed: true };
|
||||||
}
|
}
|
||||||
return state;
|
return state;
|
||||||
|
|
Loading…
Reference in a new issue