diff --git a/src/app/features/bookmarks/bookmarkRepository.ts b/src/app/features/bookmarks/bookmarkRepository.ts index f4c0a61f8..66f3ff152 100644 --- a/src/app/features/bookmarks/bookmarkRepository.ts +++ b/src/app/features/bookmarks/bookmarkRepository.ts @@ -1,4 +1,4 @@ -import { MatrixClient } from 'matrix-js-sdk'; +import type { AccountDataEvents, MatrixClient } from 'matrix-js-sdk'; import { bookmarkItemEventType, emptyIndex, @@ -9,16 +9,14 @@ import type { BookmarkIndexContent, BookmarkItemContent } from '$types/matrix-sd import { MATRIX_SABLE_UNSTABLE_BOOKMARKS_INDEX_EVENT } from '$unstable/prefixes'; function readIndex(mx: MatrixClient): BookmarkIndexContent { - const evt = mx.getAccountData(MATRIX_SABLE_UNSTABLE_BOOKMARKS_INDEX_EVENT as any); + const evt = mx.getAccountData(MATRIX_SABLE_UNSTABLE_BOOKMARKS_INDEX_EVENT); const content = evt?.getContent(); if (isValidIndexContent(content)) return content; return emptyIndex(); } async function readIndexFromServer(mx: MatrixClient): Promise { - const content = await mx.getAccountDataFromServer( - MATRIX_SABLE_UNSTABLE_BOOKMARKS_INDEX_EVENT as any - ); + const content = await mx.getAccountDataFromServer(MATRIX_SABLE_UNSTABLE_BOOKMARKS_INDEX_EVENT); if (isValidIndexContent(content)) return content; return emptyIndex(); } @@ -27,17 +25,19 @@ async function readItemFromServer( mx: MatrixClient, bookmarkId: string ): Promise { - const content = await mx.getAccountDataFromServer(bookmarkItemEventType(bookmarkId) as any); + const content = await mx.getAccountDataFromServer( + bookmarkItemEventType(bookmarkId) as keyof AccountDataEvents + ); if (isValidBookmarkItem(content) && !content.deleted) return content; return undefined; } async function writeIndex(mx: MatrixClient, index: BookmarkIndexContent): Promise { - await mx.setAccountData(MATRIX_SABLE_UNSTABLE_BOOKMARKS_INDEX_EVENT as any, index as any); + await mx.setAccountData(MATRIX_SABLE_UNSTABLE_BOOKMARKS_INDEX_EVENT, index); } async function writeItem(mx: MatrixClient, item: BookmarkItemContent): Promise { - await mx.setAccountData(bookmarkItemEventType(item.bookmark_id) as any, item as any); + await mx.setAccountData(bookmarkItemEventType(item.bookmark_id) as keyof AccountDataEvents, item); } type IndexMutator = (index: BookmarkIndexContent) => BookmarkIndexContent; diff --git a/src/app/pages/client/inbox/Bookmarks.tsx b/src/app/pages/client/inbox/Bookmarks.tsx index 16ab652b9..56595ff5d 100644 --- a/src/app/pages/client/inbox/Bookmarks.tsx +++ b/src/app/pages/client/inbox/Bookmarks.tsx @@ -1,12 +1,7 @@ -import type { - ChangeEventHandler, - ComponentProps, - FormEventHandler, - MouseEventHandler, -} from 'react'; +import type { ChangeEventHandler, ComponentProps, MouseEventHandler, ReactNode } from 'react'; import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'; import type { MatrixEvent, Room } from 'matrix-js-sdk'; -import { ClientEvent, EventType, IEvent, JoinRule, M_POLL_START } from 'matrix-js-sdk'; +import { ClientEvent, EventType, JoinRule, M_POLL_START } from 'matrix-js-sdk'; import { Avatar, Box, @@ -45,11 +40,12 @@ import { useBookmarkLoading, useBookmarkActions, } from '../../../hooks/useBookmarks'; -import type { BookmarkIndexContent, BookmarkItemContent } from '$types/matrix-sdk-events'; +import type { BookmarkItemContent } from '$types/matrix-sdk-events'; import { SequenceCard } from '../../../components/sequence-card'; import { useRoomNavigate } from '../../../hooks/useRoomNavigate'; import { useMatrixClient } from '../../../hooks/useMatrixClient'; import { getMxIdLocalPart, mxcUrlToHttp } from '../../../utils/matrix'; +import type { RenderImageContentProps } from '../../../components/message'; import { AvatarBase, ImageContent, @@ -58,7 +54,6 @@ import { ModernLayout, MSticker, RedactedContent, - RenderImageContentProps, Time, Username, UsernameBold, @@ -81,35 +76,30 @@ import { stopPropagation } from '../../../utils/keyboard'; import { highlightText, makeHighlightRegex } from '../../../plugins/react-custom-html-parser'; import colorMXID from '$utils/colorMXID'; import { RenderMessageContent } from '$components/RenderMessageContent'; -import { GetContentCallback } from '$types/matrix/room'; -import { useAllJoinedRoomsSet, useGetRoom } from '$hooks/useGetRoom'; +import type { GetContentCallback } from '$types/matrix/room'; import { useRoomEvent } from '$hooks/useRoomEvent'; -import { HTMLReactParserOptions } from 'html-react-parser'; -import { Opts } from 'linkifyjs'; +import type { HTMLReactParserOptions } from 'html-react-parser'; +import type { Opts } from 'linkifyjs'; import { ImageViewer } from '$components/image-viewer'; import { Image } from '$components/media'; import { EncryptedContent } from '$features/room/message'; import * as customHtmlCss from '$styles/CustomHtml.css'; -import { IImageContent } from '$types/matrix/common'; -import { RenderMatrixEvent, useMatrixEventRenderer } from '$hooks/useMatrixEventRenderer'; +import type { IImageContent } from '$types/matrix/common'; +import { useMatrixEventRenderer } from '$hooks/useMatrixEventRenderer'; import { MATRIX_SABLE_UNSTABLE_BOOKMARKS_INDEX_EVENT } from '$unstable/prefixes'; import { useDebounce } from '$hooks/useDebounce'; type RemoveBookmarkDialogProps = { open: boolean; - event?: MatrixEvent; - bodyPreview?: string; sender?: string; displayName?: string; senderAvatarMxc?: string; - renderMatrixEvent: RenderMatrixEvent<[MatrixEvent, string, GetContentCallback]>; + renderMatrixEvent: () => ReactNode; onConfirm: () => void; onClose: () => void; }; function RemoveBookmarkDialog({ open, - event, - bodyPreview, sender, displayName, senderAvatarMxc, @@ -120,8 +110,6 @@ function RemoveBookmarkDialog({ const mx = useMatrixClient(); const useAuthentication = useMediaAuthentication(); - const getContent = (() => event?.getContent()) as GetContentCallback; - return ( }> @@ -151,7 +139,7 @@ function RemoveBookmarkDialog({ Are you sure you want to remove this bookmark? - {(bodyPreview || sender) && ( + {sender && ( )} - {event - ? renderMatrixEvent( - event.getType(), - false, - event, - displayName ?? sender ?? '', - getContent - ) - : bodyPreview && ( - - {bodyPreview} - - )} + {renderMatrixEvent()} )}