Further clean up types for the card object (#37023)

This commit is contained in:
diondiondion 2026-01-09 15:40:27 +01:00 committed by GitHub
parent 628fc9b95b
commit 973fef4b69
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 10 additions and 9 deletions

View file

@ -41,11 +41,10 @@ export interface ApiPreviewCardJSON {
url: string;
title: string;
description: string;
language: string;
type: string;
language: string | null;
type: 'video' | 'link';
author_name: string;
author_url: string;
author_account?: ApiAccountJSON;
provider_name: string;
provider_url: string;
html: string;
@ -55,7 +54,7 @@ export interface ApiPreviewCardJSON {
image_description: string;
embed_url: string;
blurhash: string;
published_at: string;
published_at: string | null;
authors: ApiPreviewCardAuthorJSON[];
}

View file

@ -118,7 +118,7 @@ const Card: React.FC<CardProps> = ({ card, sensitive }) => {
? decodeIDNA(getHostname(card.get('url')))
: card.get('provider_name');
const interactive = card.get('type') === 'video';
const language = card.get('language') || '';
const language = card.get('language') ?? '';
const hasImage = (card.get('image')?.length ?? 0) > 0;
const largeImage =
(hasImage && card.get('width') > card.get('height')) || interactive;
@ -131,7 +131,11 @@ const Card: React.FC<CardProps> = ({ card, sensitive }) => {
{card.get('published_at') && (
<>
{' '}
· <RelativeTimestamp timestamp={card.get('published_at')} />
·{' '}
<RelativeTimestamp
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
timestamp={card.get('published_at')!}
/>
</>
)}
</span>

View file

@ -7,8 +7,6 @@ export type { StatusVisibility } from 'mastodon/api_types/statuses';
// Temporary until we type it correctly
export type Status = Immutable.Map<string, unknown>;
type CardShape = Required<ApiPreviewCardJSON>;
export type Card = RecordOf<CardShape>;
export type Card = RecordOf<ApiPreviewCardJSON>;
export type MediaAttachment = Immutable.Map<string, unknown>;