diff --git a/src/Components/Map/hooks/useSelectPosition.tsx b/src/Components/Map/hooks/useSelectPosition.tsx index 9fb98e0d..1477eaee 100644 --- a/src/Components/Map/hooks/useSelectPosition.tsx +++ b/src/Components/Map/hooks/useSelectPosition.tsx @@ -2,7 +2,7 @@ /* eslint-disable @typescript-eslint/prefer-optional-chain */ /* eslint-disable @typescript-eslint/no-floating-promises */ /* eslint-disable @typescript-eslint/no-empty-function */ -/* eslint-disable @typescript-eslint/prefer-nullish-coalescing */ + /* eslint-disable @typescript-eslint/await-thenable */ /* eslint-disable @typescript-eslint/restrict-plus-operands */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ diff --git a/types/Item.d.ts b/types/Item.d.ts index 880cc9fc..21221150 100644 --- a/types/Item.d.ts +++ b/types/Item.d.ts @@ -1,13 +1,13 @@ import type { ItemsApi } from './ItemsApi' import type { ItemType } from './ItemType' -import type { LayerProps } from './LayerProps' +import type { LayerParameters, LayerProps } from './LayerProps' import type { Relation } from './Relation' import type { UserItem } from './UserItem' import type { Point } from 'geojson' type TagIds = { tags_id: string }[] -export interface Item { +interface BaseItem { id: string name: string text: string @@ -20,7 +20,7 @@ export interface Item { // eslint-disable-next-line @typescript-eslint/no-explicit-any api?: ItemsApi tags?: string[] - layer?: LayerProps + layer?: LayerProps relations?: Relation[] parent?: string subname?: string @@ -32,30 +32,25 @@ export interface Item { offers?: TagIds needs?: TagIds status?: string - color?: string markerIcon?: string - avatar?: string new?: boolean contact?: string telephone?: string next_appointment?: string type?: ItemType - - // { - // coordinates: [number, number] - /* constructor( - id: string, - name: string, - text: string, - position: Geometry, - layer?: LayerProps, - api?: ItemsApi, - ) { - this.id = id - this.name = name - this.text = text - this.position = position - this.layer = layer - this.api = api - } */ } + +export type Item = BaseItem & + (L extends { hasAvatar: true } + ? { + avatar: string + } + : unknown) & + (L extends { hasColor: true } + ? { + color: string + } + : unknown) & + Record + +type foo = Item<{ hasAvatar: false; hasColor: true }> diff --git a/types/ItemType.d.ts b/types/ItemType.d.ts index 9a4f621c..05b1b7f8 100644 --- a/types/ItemType.d.ts +++ b/types/ItemType.d.ts @@ -1,11 +1,35 @@ import type { Key } from 'react' +interface TextParameters { + dataField: string + heading: string + hideWhenEmpty: boolean +} + +interface GroupSubHeaderParameters { + shareBaseUrl: string + platforms: string[] +} + +interface ContactInfoParameters { + heading: string +} + +interface StartEndParemeters { + heading: string +} + +export type Parameters = + | TextParameters + | GroupSubHeaderParameters + | ContactInfoParameters + | StartEndParemeters + export interface ItemType { name: string show_start_end: boolean show_text: boolean - // eslint-disable-next-line @typescript-eslint/no-explicit-any - profileTemplate: { collection: string | number; id: Key | null | undefined; item: any }[] + profileTemplate: { collection: string | number; id: Key | null | undefined; item: Parameters }[] offers_and_needs: boolean icon_as_labels: unknown relations: boolean diff --git a/types/LayerProps.d.ts b/types/LayerProps.d.ts index a0f076a5..ea44359e 100644 --- a/types/LayerProps.d.ts +++ b/types/LayerProps.d.ts @@ -3,9 +3,17 @@ import type { ItemFormPopupProps } from './ItemFormPopupProps' import type { ItemsApi } from './ItemsApi' import type { ItemType } from './ItemType' -export interface LayerProps { +interface LayerParameters { + hasAvatar?: boolean + hasColor?: boolean + hasTags?: boolean + hasOffers?: boolean + hasNeeds?: boolean +} + +export interface LayerProps { id?: string - data?: Item[] + data?: Item[] children?: React.ReactNode name: string menuIcon: string @@ -15,15 +23,9 @@ export interface LayerProps { markerShape: string markerDefaultColor: string markerDefaultColor2?: string - // eslint-disable-next-line @typescript-eslint/no-explicit-any - api?: ItemsApi - itemType: ItemType // How does this relate to Item type defined in Item.d.ts? + api?: ItemsApi> + itemType: ItemType // TODO Conditionally type items with .avatar etc.? - hasAvatar?: boolean - hasColor?: boolean - hasTags?: boolean - hasOffers?: boolean - hasNeeds?: boolean onlyOnePerOwner?: boolean customEditLink?: string customEditParameter?: string