Migrate Attribution component to TypeScript. (#3247)

This commit is contained in:
Corey Farwell
2025-11-24 17:48:36 -05:00
committed by GitHub
parent bccc5b2d52
commit ee4fc1630d
2 changed files with 17 additions and 7 deletions

View File

@@ -1,15 +1,13 @@
// @flow
import { Body4 } from "components/SharedComponents";
import { t } from "i18next";
import type { Node } from "react";
import React from "react";
import type { License, RealmObservation } from "realmModels/types";
type Props = {
observation: Object
interface Props {
observation: RealmObservation;
}
const renderRestrictions = ( licenseCode: string ) => {
const renderRestrictions = ( licenseCode: License | null ) => {
switch ( licenseCode ) {
case "cc0":
return t( "no-rights-reserved-cc0" );
@@ -32,7 +30,7 @@ const renderRestrictions = ( licenseCode: string ) => {
// lifted from web:
// https://github.com/inaturalist/inaturalist/blob/768b9263931ebeea229bbc47d8442ca6b0377d45/app/webpack/shared/components/observation_attribution.jsx
const Attribution = ( { observation }: Props ): Node => {
const Attribution = ( { observation }: Props ) => {
const { user } = observation;
const userName = user
? ( user.name || user.login )

View File

@@ -92,6 +92,16 @@ interface RealmIdentification extends RealmObject {
user: RealmUser;
}
// https://github.com/inaturalist/iNaturalistAPI/blob/08e3aade068c50e02d0caf7a59c69ea87b70bc6e/lib/views/swagger_v1.yml.ejs#L2319-L2333
export type License =
| "cc-by"
| "cc-by-nc"
| "cc-by-nd"
| "cc-by-sa"
| "cc-by-nc-nd"
| "cc-by-nc-sa"
| "cc0"
export interface RealmObservationPojo {
_created_at?: Date;
_synced_at?: Date;
@@ -103,6 +113,7 @@ export interface RealmObservationPojo {
identifications: Array<RealmIdentification>;
identifications_viewed?: boolean;
latitude: number | null;
license_code: License | null;
longitude: number | null;
obscured?: boolean;
observationPhotos: Array<RealmObservationPhotoPojo>;
@@ -119,6 +130,7 @@ export interface RealmObservationPojo {
taxon_geoprivacy?: "open" | "private" | "obscured" | null;
time_observed_at?: string;
timeObservedAt?: string;
user: RealmUser;
uuid: string;
}