diff --git a/packages/pl-fe/src/actions/compose.ts b/packages/pl-fe/src/actions/compose.ts index babe042ec..0915e9a9b 100644 --- a/packages/pl-fe/src/actions/compose.ts +++ b/packages/pl-fe/src/actions/compose.ts @@ -508,7 +508,7 @@ const submitCompose = local_only: compose.localOnly, interaction_policy: (['public', 'unlisted', 'private'].includes(compose.visibility) && - compose.interactionPolicy) ?? + compose.interactionPolicy) || undefined, quote_approval_policy: compose.quoteApprovalPolicy ?? undefined, location_id: compose.location?.origin_id ?? undefined, diff --git a/packages/pl-fe/src/actions/preload.ts b/packages/pl-fe/src/actions/preload.ts index 785c5b5e2..e7af0a279 100644 --- a/packages/pl-fe/src/actions/preload.ts +++ b/packages/pl-fe/src/actions/preload.ts @@ -25,7 +25,7 @@ const pleromaDecoder = (json: string) => decodePleromaData(JSON.parse(json)); // Should be called inside a try-catch. const decodeFromMarkup = (elementId: string, decoder: (json: string) => Record) => { const { textContent } = document.getElementById(elementId)!; - return decoder(textContent); + return decoder(textContent as string); }; const preloadFromMarkup = diff --git a/packages/pl-fe/src/actions/timelines.ts b/packages/pl-fe/src/actions/timelines.ts index 39b96857b..79a0e88da 100644 --- a/packages/pl-fe/src/actions/timelines.ts +++ b/packages/pl-fe/src/actions/timelines.ts @@ -216,7 +216,7 @@ const fetchHomeTimeline = if (expand && state.timelines.home?.isLoading) return; const fn = - (expand && state.timelines.home?.next?.()) ?? getClient(state).timelines.homeTimeline(params); + (expand && state.timelines.home?.next?.()) || getClient(state).timelines.homeTimeline(params); return dispatch(handleTimelineExpand('home', fn, done)); }; @@ -242,7 +242,7 @@ const fetchPublicTimeline = if (expand && state.timelines[timelineId]?.isLoading) return; const fn = - (expand && state.timelines[timelineId]?.next?.()) ?? + (expand && state.timelines[timelineId]?.next?.()) || getClient(state).timelines.publicTimeline(params); return dispatch(handleTimelineExpand(timelineId, fn, done, onError)); @@ -260,7 +260,7 @@ const fetchBubbleTimeline = if (expand && state.timelines[timelineId]?.isLoading) return; const fn = - (expand && state.timelines[timelineId]?.next?.()) ?? + (expand && state.timelines[timelineId]?.next?.()) || getClient(state).timelines.bubbleTimeline(params); return dispatch(handleTimelineExpand(timelineId, fn, done)); @@ -278,7 +278,7 @@ const fetchWrenchedTimeline = if (expand && state.timelines[timelineId]?.isLoading) return; const fn = - (expand && state.timelines[timelineId]?.next?.()) ?? + (expand && state.timelines[timelineId]?.next?.()) || getClient(state).timelines.wrenchedTimeline(params); return dispatch(handleTimelineExpand(timelineId, fn, done)); @@ -303,7 +303,7 @@ const fetchAccountTimeline = if (expand && state.timelines[timelineId]?.isLoading) return; const fn = - (expand && state.timelines[timelineId]?.next?.()) ?? + (expand && state.timelines[timelineId]?.next?.()) || getClient(state).accounts.getAccountStatuses(accountId, params); return dispatch(handleTimelineExpand(timelineId, fn, done)); @@ -321,7 +321,7 @@ const fetchListTimeline = if (expand && state.timelines[timelineId]?.isLoading) return; const fn = - (expand && state.timelines[timelineId]?.next?.()) ?? + (expand && state.timelines[timelineId]?.next?.()) || getClient(state).timelines.listTimeline(listId, params); return dispatch(handleTimelineExpand(timelineId, fn, done)); @@ -339,7 +339,7 @@ const fetchCircleTimeline = if (expand && state.timelines[timelineId]?.isLoading) return; const fn = - (expand && state.timelines[timelineId]?.next?.()) ?? + (expand && state.timelines[timelineId]?.next?.()) || getClient(state).circles.getCircleStatuses(circleId, params); return dispatch(handleTimelineExpand(timelineId, fn, done)); @@ -357,7 +357,7 @@ const fetchAntennaTimeline = if (expand && state.timelines[timelineId]?.isLoading) return; const fn = - (expand && state.timelines[timelineId]?.next?.()) ?? + (expand && state.timelines[timelineId]?.next?.()) || getClient(state).timelines.antennaTimeline(antennaId, params); return dispatch(handleTimelineExpand(timelineId, fn, done)); @@ -376,7 +376,7 @@ const fetchGroupTimeline = if (expand && state.timelines[timelineId]?.isLoading) return; const fn = - (expand && state.timelines[timelineId]?.next?.()) ?? + (expand && state.timelines[timelineId]?.next?.()) || getClient(state).timelines.groupTimeline(groupId, params); return dispatch(handleTimelineExpand(timelineId, fn, done)); @@ -399,7 +399,7 @@ const fetchHashtagTimeline = if (useSettingsStore.getState().settings.autoTranslate) params.language = getLocale(); const fn = - (expand && state.timelines[timelineId]?.next?.()) ?? + (expand && state.timelines[timelineId]?.next?.()) || getClient(state).timelines.hashtagTimeline(hashtag, params); return dispatch(handleTimelineExpand(timelineId, fn, done)); @@ -418,7 +418,7 @@ const fetchLinkTimeline = if (useSettingsStore.getState().settings.autoTranslate) params.language = getLocale(); const fn = - (expand && state.timelines[timelineId]?.next?.()) ?? + (expand && state.timelines[timelineId]?.next?.()) || getClient(state).timelines.linkTimeline(url, params); return dispatch(handleTimelineExpand(timelineId, fn, done)); diff --git a/packages/pl-fe/src/components/dropdown-navigation.tsx b/packages/pl-fe/src/components/dropdown-navigation.tsx index 124eacfcf..df6479f8d 100644 --- a/packages/pl-fe/src/components/dropdown-navigation.tsx +++ b/packages/pl-fe/src/components/dropdown-navigation.tsx @@ -84,7 +84,7 @@ const DropdownNavigation: React.FC = React.memo((): JSX.Element | null => { ); const getOtherAccounts = useCallback(makeGetOtherAccounts(), []); - const { account } = useAccount(me ?? undefined); + const { account } = useAccount(me || undefined); const otherAccounts = useAppSelector((state) => getOtherAccounts(state)); const settings = useSettings(); const followRequestsCount = useFollowRequestsCount().data ?? 0; diff --git a/packages/pl-fe/src/components/media-gallery.tsx b/packages/pl-fe/src/components/media-gallery.tsx index 47ace8b51..3f4de40bc 100644 --- a/packages/pl-fe/src/components/media-gallery.tsx +++ b/packages/pl-fe/src/components/media-gallery.tsx @@ -384,7 +384,7 @@ const MediaGallery: React.FC = (props) => { className='size-4 min-w-fit text-gray-800 dark:text-gray-200' src={ MIMETYPE_ICONS[ - (attachment.type === 'unknown' && attachment.mime_type) ?? attachment.type + (attachment.type === 'unknown' && attachment.mime_type) || attachment.type ] ?? require('@phosphor-icons/core/regular/paperclip.svg') } /> diff --git a/packages/pl-fe/src/components/parsed-content.tsx b/packages/pl-fe/src/components/parsed-content.tsx index 2ddc97c42..d66150dbd 100644 --- a/packages/pl-fe/src/components/parsed-content.tsx +++ b/packages/pl-fe/src/components/parsed-content.tsx @@ -215,6 +215,7 @@ function parseContent( if (!(domNode instanceof Element)) { // @ts-ignore domNode.preGreentext = + // @ts-ignore (!domNode.prev || domNode.prev.preGreentext) && !domNode.data.trim().length; // @ts-ignore diff --git a/packages/pl-fe/src/components/pull-to-refresh.tsx b/packages/pl-fe/src/components/pull-to-refresh.tsx index e1b826679..4fcc785b5 100644 --- a/packages/pl-fe/src/components/pull-to-refresh.tsx +++ b/packages/pl-fe/src/components/pull-to-refresh.tsx @@ -65,7 +65,7 @@ const isTreeScrollable = (element: HTMLElement, direction: DIRECTION): boolean = interface PullToRefreshProps { isPullable?: boolean; - onRefresh?: () => Promise; + onRefresh?: () => Promise | void; refreshingContent?: JSX.Element | string; pullingContent?: JSX.Element | string; children: JSX.Element; @@ -217,7 +217,15 @@ const PullToRefresh: React.FC = ({ childrenRef.current.style.overflow = 'visible'; childrenRef.current.style.transform = `translate(0px, ${pullDownThreshold}px)`; } - onRefresh?.().then(initContainer).catch(initContainer); + + if (onRefresh) { + const result = onRefresh(); + if (result instanceof Promise) { + result.then(initContainer).catch(initContainer); + } else { + initContainer(); + } + } }; return ( diff --git a/packages/pl-fe/src/components/sidebar-navigation-link.tsx b/packages/pl-fe/src/components/sidebar-navigation-link.tsx index 29a442d7b..298c913f7 100644 --- a/packages/pl-fe/src/components/sidebar-navigation-link.tsx +++ b/packages/pl-fe/src/components/sidebar-navigation-link.tsx @@ -54,7 +54,7 @@ const SidebarNavigationLink = React.memo( > diff --git a/packages/pl-fe/src/components/status.tsx b/packages/pl-fe/src/components/status.tsx index e94eb81b0..db0d1c966 100644 --- a/packages/pl-fe/src/components/status.tsx +++ b/packages/pl-fe/src/components/status.tsx @@ -187,7 +187,7 @@ const Status: React.FC = (props) => { const getStatus = useMemo(makeGetStatus, []); const actualStatus = useAppSelector( - (state) => (status.reblog_id && getStatus(state, { id: status.reblog_id })) ?? status, + (state) => (status.reblog_id && getStatus(state, { id: status.reblog_id })!) || status, ); const { mutate: favouriteStatus } = useFavouriteStatus(actualStatus.id); diff --git a/packages/pl-fe/src/components/thumb-navigation-link.tsx b/packages/pl-fe/src/components/thumb-navigation-link.tsx index 23ff7b035..df620b1a6 100644 --- a/packages/pl-fe/src/components/thumb-navigation-link.tsx +++ b/packages/pl-fe/src/components/thumb-navigation-link.tsx @@ -30,7 +30,7 @@ const ThumbNavigationLink: React.FC = ({ const icon = (activeSrc && matchRoute({ to: props.to, params: props.params, search: props.search }) !== false && - activeSrc) ?? + activeSrc) || src; return ( diff --git a/packages/pl-fe/src/components/translate-button.tsx b/packages/pl-fe/src/components/translate-button.tsx index 689ac053f..d667f893d 100644 --- a/packages/pl-fe/src/components/translate-button.tsx +++ b/packages/pl-fe/src/components/translate-button.tsx @@ -49,7 +49,7 @@ const canRemoteTranslate = ( type Availability = Awaited>; -const localTranslationAvailability = ( +const localTranslationAvailability = async ( status: ITranslateButton['status'], locale: string, ): Promise => { diff --git a/packages/pl-fe/src/entity-store/actions.ts b/packages/pl-fe/src/entity-store/actions.ts index d8e689b1d..b2de9cc75 100644 --- a/packages/pl-fe/src/entity-store/actions.ts +++ b/packages/pl-fe/src/entity-store/actions.ts @@ -1,3 +1,4 @@ +import type { Entities } from './entities'; import type { EntitiesTransaction, Entity, EntityListState, ImportPosition } from './types'; const ENTITIES_IMPORT = 'ENTITIES_IMPORT' as const; @@ -12,7 +13,7 @@ const ENTITIES_TRANSACTION = 'ENTITIES_TRANSACTION' as const; /** Action to import entities into the cache. */ const importEntities = ( entities: Entity[], - entityType: string, + entityType: Entities, listKey?: string, pos?: ImportPosition, ) => ({ @@ -53,7 +54,7 @@ const entitiesFetchRequest = (entityType: string, listKey?: string) => ({ const entitiesFetchSuccess = ( entities: Entity[], - entityType: string, + entityType: Entities, listKey?: string, pos?: ImportPosition, newState?: EntityListState, @@ -68,14 +69,14 @@ const entitiesFetchSuccess = ( overwrite, }); -const entitiesFetchFail = (entityType: string, listKey: string | undefined, error: any) => ({ +const entitiesFetchFail = (entityType: Entities, listKey: string | undefined, error: any) => ({ type: ENTITIES_FETCH_FAIL, entityType, listKey, error, }); -const invalidateEntityList = (entityType: string, listKey: string) => ({ +const invalidateEntityList = (entityType: Entities, listKey: string) => ({ type: ENTITIES_INVALIDATE_LIST, entityType, listKey, diff --git a/packages/pl-fe/src/entity-store/hooks/types.ts b/packages/pl-fe/src/entity-store/hooks/types.ts index 9b2acb336..f838e8af9 100644 --- a/packages/pl-fe/src/entity-store/hooks/types.ts +++ b/packages/pl-fe/src/entity-store/hooks/types.ts @@ -1,3 +1,4 @@ +import type { Entities } from '../entities'; import type { Entity } from '../types'; import type { BaseSchema, BaseIssue } from 'valibot'; @@ -10,7 +11,7 @@ type EntitySchema = BaseSchema { diff --git a/packages/pl-fe/src/entity-store/hooks/use-delete-entity.ts b/packages/pl-fe/src/entity-store/hooks/use-delete-entity.ts index ac497cf8f..844c99358 100644 --- a/packages/pl-fe/src/entity-store/hooks/use-delete-entity.ts +++ b/packages/pl-fe/src/entity-store/hooks/use-delete-entity.ts @@ -4,6 +4,7 @@ import { useLoading } from '@/hooks/use-loading'; import { deleteEntities, importEntities } from '../actions'; +import type { Entities } from '../entities'; import type { EntityCallbacks, EntityFn } from './types'; /** @@ -11,7 +12,7 @@ import type { EntityCallbacks, EntityFn } from './types'; * This hook should be used to globally delete an entity from all lists. * To remove an entity from a single list, see `useDismissEntity`. */ -const useDeleteEntity = (entityType: string, entityFn: EntityFn) => { +const useDeleteEntity = (entityType: Entities, entityFn: EntityFn) => { const dispatch = useAppDispatch(); const getState = useGetState(); const [isSubmitting, setPromise] = useLoading(); diff --git a/packages/pl-fe/src/entity-store/hooks/use-entity-lookup.ts b/packages/pl-fe/src/entity-store/hooks/use-entity-lookup.ts index ea875041d..2839e18d6 100644 --- a/packages/pl-fe/src/entity-store/hooks/use-entity-lookup.ts +++ b/packages/pl-fe/src/entity-store/hooks/use-entity-lookup.ts @@ -8,6 +8,7 @@ import { useLoading } from '@/hooks/use-loading'; import { importEntities } from '../actions'; import { findEntity } from '../selectors'; +import type { Entities } from '../entities'; import type { Entity } from '../types'; import type { EntityFn } from './types'; import type { UseEntityOpts } from './use-entity'; @@ -17,7 +18,7 @@ import type { PlfeResponse } from '@/api'; type LookupFn = (entity: TEntity) => boolean; const useEntityLookup = ( - entityType: string, + entityType: Entities, lookupFn: LookupFn, entityFn: EntityFn, opts: UseEntityOpts = {}, diff --git a/packages/pl-fe/src/reducers/compose.ts b/packages/pl-fe/src/reducers/compose.ts index 83272f294..b3bf59c31 100644 --- a/packages/pl-fe/src/reducers/compose.ts +++ b/packages/pl-fe/src/reducers/compose.ts @@ -644,7 +644,7 @@ const compose = ( const contentType = action.contentType === 'text/markdown' && state.default.contentType === 'wysiwyg' ? 'wysiwyg' - : (action.contentType ?? 'text/plain'); + : action.contentType || 'text/plain'; compose.contentType = contentType; compose.quoteId = action.status.quote_id; compose.groupId = action.status.group_id; diff --git a/packages/pl-fe/src/selectors/index.ts b/packages/pl-fe/src/selectors/index.ts index 28670670e..2feaa5337 100644 --- a/packages/pl-fe/src/selectors/index.ts +++ b/packages/pl-fe/src/selectors/index.ts @@ -177,8 +177,8 @@ const makeGetNotification = () => createSelector( [ (_state: RootState, notification: NotificationGroup) => notification, - // @ts-expect-error types will be fine valibot ensures that (state: RootState, notification: NotificationGroup) => + // @ts-expect-error types will be fine valibot ensures that selectAccount(state, notification.target_id), // @ts-expect-error types will be fine valibot ensures that (state: RootState, notification: NotificationGroup) => state.statuses[notification.status_id],