diff --git a/src/api/types.d.ts b/src/api/types.d.ts index 286230f76..7408cc7bc 100644 --- a/src/api/types.d.ts +++ b/src/api/types.d.ts @@ -102,12 +102,17 @@ export interface ApiUser { export interface ApiComment { body?: string; user?: ApiUser; + id: number; + hidden?: boolean; + uuid: string; + created_at: string; } export interface ApiIdentification { body?: string; taxon?: ApiTaxon; user?: ApiUser; + hidden?: boolean; } export interface ApiNotification { @@ -134,6 +139,9 @@ export interface ApiObservation extends ApiRecord { time_observed_at?: string; user?: ApiUser; uuid: string; + comments?: ApiComment[]; + identifications?: ApiIdentification[]; + taxon?: ApiTaxon; } export interface ApiObservationsSearchResponse extends ApiResponse { diff --git a/src/sharedHooks/useRemoteObservation.ts b/src/sharedHooks/useRemoteObservation.ts index e35656480..002f53a98 100644 --- a/src/sharedHooks/useRemoteObservation.ts +++ b/src/sharedHooks/useRemoteObservation.ts @@ -1,4 +1,5 @@ import { fetchRemoteObservation } from "api/observations"; +import type { ApiObservation } from "api/types"; import i18n from "i18next"; import { RealmContext } from "providers/contexts"; import { useCallback, useEffect, useMemo } from "react"; @@ -9,35 +10,15 @@ const { useRealm } = RealmContext; export const fetchRemoteObservationKey = "fetchRemoteObservation"; -interface CommentWithHidden { - hidden?: boolean; - [key: string]: unknown; -} - -interface IdentificationWithHidden { - hidden?: boolean; - [key: string]: unknown; -} - -interface RemoteObservation { - user?: { - id: number; - [key: string]: unknown; - }; - comments?: CommentWithHidden[]; - identifications?: IdentificationWithHidden[]; - [key: string]: unknown; -} - interface UseRemoteObservationReturn { - remoteObservation: RemoteObservation | null | undefined; + remoteObservation: ApiObservation | null | undefined; refetchRemoteObservation: () => void; isRefetching: boolean; fetchRemoteObservationError: Error | null; } const filterHiddenContent -= ( observation?: RemoteObservation | null ): RemoteObservation | null | undefined => { += ( observation?: ApiObservation | null ): ApiObservation | null | undefined => { if ( observation === undefined || observation === null ) { return observation; } @@ -67,7 +48,7 @@ const useRemoteObservation = ( uuid: string, enabled: boolean ): UseRemoteObserv refetch: refetchRemoteObservation, isRefetching, error: fetchRemoteObservationError - } = useAuthenticatedQuery( + } = useAuthenticatedQuery( fetchRemoteObservationQueryKey, optsWithAuth => fetchRemoteObservation( uuid,