diff --git a/.eslintrc.js b/.eslintrc.js index 18dd567..6254811 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -79,7 +79,7 @@ module.exports = { 'import/no-relative-parent-imports': [ 'error', { - ignore: ['#[src,root,components,utils]/*'], + ignore: ['#[src,types,root,components,utils]/*'], }, ], 'import/no-self-import': 'error', @@ -156,6 +156,7 @@ module.exports = { 'plugin:@typescript-eslint/strict', ], rules: { + '@typescript-eslint/consistent-type-imports': 'error', // allow explicitly defined dangling promises '@typescript-eslint/no-floating-promises': ['error', { ignoreVoid: true }], 'no-void': ['error', { allowAsStatement: true }], diff --git a/package.json b/package.json index dfafb75..b7cdb45 100644 --- a/package.json +++ b/package.json @@ -79,6 +79,7 @@ "#components/*": "./src/Components/*", "#utils/*": "./src/Utils/*", "#src/*": "./src/*", + "#types/*": "./types/*", "#root/*": "./*" } } diff --git a/src/Components/AppShell/AppShell.tsx b/src/Components/AppShell/AppShell.tsx index 3f8746d..0421a30 100644 --- a/src/Components/AppShell/AppShell.tsx +++ b/src/Components/AppShell/AppShell.tsx @@ -1,9 +1,9 @@ -import { AssetsApi } from '#src/types' - import { ContextWrapper } from './ContextWrapper' import NavBar from './NavBar' import { SetAppState } from './SetAppState' +import type { AssetsApi } from '#types/AssetsApi' + export function AppShell({ appName, children, diff --git a/src/Components/AppShell/NavBar.tsx b/src/Components/AppShell/NavBar.tsx index 1ea5576..2a7a977 100644 --- a/src/Components/AppShell/NavBar.tsx +++ b/src/Components/AppShell/NavBar.tsx @@ -16,7 +16,8 @@ import { toast } from 'react-toastify' import { useAuth } from '#components/Auth' import { useItems } from '#components/Map/hooks/useItems' -import { Item } from '#src/types' + +import type { Item } from '#types/Item' export default function NavBar({ appName, userType }: { appName: string; userType: string }) { const { isAuthenticated, user, logout } = useAuth() diff --git a/src/Components/AppShell/SetAppState.tsx b/src/Components/AppShell/SetAppState.tsx index b7831ac..eb53791 100644 --- a/src/Components/AppShell/SetAppState.tsx +++ b/src/Components/AppShell/SetAppState.tsx @@ -1,9 +1,9 @@ import { useEffect } from 'react' -import { AssetsApi } from '#src/types' - import { useSetAppState } from './hooks/useAppState' +import type { AssetsApi } from '#types/AssetsApi' + export const SetAppState = ({ assetsApi, userType, diff --git a/src/Components/AppShell/hooks/useAppState.tsx b/src/Components/AppShell/hooks/useAppState.tsx index 053d23b..c338d8c 100644 --- a/src/Components/AppShell/hooks/useAppState.tsx +++ b/src/Components/AppShell/hooks/useAppState.tsx @@ -2,7 +2,7 @@ /* eslint-disable @typescript-eslint/no-empty-function */ import { useCallback, useState, createContext, useContext } from 'react' -import { AssetsApi } from '#src/types' +import type { AssetsApi } from '#types/AssetsApi' interface AppState { assetsApi: AssetsApi diff --git a/src/Components/AppShell/hooks/useAssets.tsx b/src/Components/AppShell/hooks/useAssets.tsx index 08f4a4e..6c04d6a 100644 --- a/src/Components/AppShell/hooks/useAssets.tsx +++ b/src/Components/AppShell/hooks/useAssets.tsx @@ -3,7 +3,7 @@ /* eslint-disable @typescript-eslint/no-empty-function */ import { useCallback, useState, createContext, useContext } from 'react' -import { AssetsApi } from '#src/types' +import type { AssetsApi } from '#types/AssetsApi' type UseAssetManagerResult = ReturnType diff --git a/src/Components/Auth/useAuth.tsx b/src/Components/Auth/useAuth.tsx index 5104c52..e892a0c 100644 --- a/src/Components/Auth/useAuth.tsx +++ b/src/Components/Auth/useAuth.tsx @@ -1,5 +1,3 @@ -/* eslint-disable @typescript-eslint/no-unsafe-member-access */ -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable @typescript-eslint/no-unsafe-return */ /* eslint-disable @typescript-eslint/no-unsafe-argument */ @@ -7,7 +5,8 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import { createContext, useState, useContext, useEffect } from 'react' -import { UserApi, UserItem } from '#src/types' +import type { UserApi } from '#types/UserApi' +import type { UserItem } from '#types/UserItem' interface AuthProviderProps { userApi: UserApi @@ -80,7 +79,7 @@ export const AuthProvider = ({ userApi, children }: AuthProviderProps) => { setLoading(true) try { const res = await userApi.login(credentials.email, credentials.password) - setToken(res.access_token) + setToken(res?.access_token) return await loadUser() } catch (error: any) { setLoading(false) diff --git a/src/Components/Gaming/Quests.tsx b/src/Components/Gaming/Quests.tsx index 3541576..792b4fa 100644 --- a/src/Components/Gaming/Quests.tsx +++ b/src/Components/Gaming/Quests.tsx @@ -3,10 +3,11 @@ import { useEffect, useState } from 'react' import { useAuth } from '#components/Auth' import { useItems } from '#components/Map/hooks/useItems' -import { Item } from '#src/types' import { useQuestsOpen, useSetQuestOpen } from './hooks/useQuests' +import type { Item } from '#types/Item' + export function Quests() { const questsOpen = useQuestsOpen() const setQuestsOpen = useSetQuestOpen() diff --git a/src/Components/Map/ItemForm.tsx b/src/Components/Map/ItemForm.tsx index 91cf08a..d48b33c 100644 --- a/src/Components/Map/ItemForm.tsx +++ b/src/Components/Map/ItemForm.tsx @@ -1,7 +1,7 @@ import { node, string } from 'prop-types' import { Children, cloneElement, isValidElement, useEffect } from 'react' -import { Item } from '#src/types' +import type { Item } from '#types/Item' export const ItemForm = ({ children, diff --git a/src/Components/Map/ItemView.tsx b/src/Components/Map/ItemView.tsx index fe4f0d1..63a241d 100644 --- a/src/Components/Map/ItemView.tsx +++ b/src/Components/Map/ItemView.tsx @@ -1,7 +1,7 @@ import { node, string } from 'prop-types' import { Children, cloneElement, isValidElement } from 'react' -import { Item } from '#src/types' +import type { Item } from '#types/Item' export const ItemView = ({ children, item }: { children?: React.ReactNode; item?: Item }) => { return ( diff --git a/src/Components/Map/Layer.tsx b/src/Components/Map/Layer.tsx index 74337ff..b50cd69 100644 --- a/src/Components/Map/Layer.tsx +++ b/src/Components/Map/Layer.tsx @@ -7,12 +7,10 @@ /* eslint-disable @typescript-eslint/no-unsafe-argument */ /* eslint-disable @typescript-eslint/prefer-optional-chain */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ -import { Popup } from 'leaflet' import { Children, isValidElement, useEffect, useState } from 'react' import { Marker, Tooltip, useMap, useMapEvents } from 'react-leaflet' import { useLocation } from 'react-router-dom' -import { Item, LayerProps, Tag } from '#src/types' import { encodeTag } from '#utils/FormatTags' import { getValue } from '#utils/GetValue' import { hashTagRegex } from '#utils/HashTagRegex' @@ -32,6 +30,11 @@ import { useAddTag, useAllTagsLoaded, useGetItemTags, useTags } from './hooks/us import { ItemFormPopup } from './Subcomponents/ItemFormPopup' import { ItemViewPopup } from './Subcomponents/ItemViewPopup' +import type { Item } from '#types/Item' +import type { LayerProps } from '#types/LayerProps' +import type { Tag } from '#types/Tag' +import type { Popup } from 'leaflet' + export const Layer = ({ data, children, diff --git a/src/Components/Map/Permissions.tsx b/src/Components/Map/Permissions.tsx index 5b40bd7..cac67cf 100644 --- a/src/Components/Map/Permissions.tsx +++ b/src/Components/Map/Permissions.tsx @@ -1,10 +1,12 @@ import { useEffect } from 'react' import { useAuth } from '#components/Auth' -import { ItemsApi, Permission } from '#src/types' import { useSetPermissionData, useSetPermissionApi, useSetAdminRole } from './hooks/usePermissions' +import type { ItemsApi } from '#types/ItemsApi' +import type { Permission } from '#types/Permission' + export function Permissions({ data, api, diff --git a/src/Components/Map/Subcomponents/AddButton.tsx b/src/Components/Map/Subcomponents/AddButton.tsx index 3ab0768..b4b9dd4 100644 --- a/src/Components/Map/Subcomponents/AddButton.tsx +++ b/src/Components/Map/Subcomponents/AddButton.tsx @@ -1,6 +1,5 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-non-null-assertion */ -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ import { useLayers } from '#components/Map/hooks/useLayers' import { useHasUserPermission } from '#components/Map/hooks/usePermissions' diff --git a/src/Components/Map/Subcomponents/Controls/SearchControl.tsx b/src/Components/Map/Subcomponents/Controls/SearchControl.tsx index 5e77d29..323d8c5 100644 --- a/src/Components/Map/Subcomponents/Controls/SearchControl.tsx +++ b/src/Components/Map/Subcomponents/Controls/SearchControl.tsx @@ -22,7 +22,6 @@ import { useItems } from '#components/Map/hooks/useItems' import { useLeafletRefs } from '#components/Map/hooks/useLeafletRefs' import { useTags } from '#components/Map/hooks/useTags' import useWindowDimensions from '#components/Map/hooks/useWindowDimension' -import { Item } from '#src/types' import { decodeTag } from '#utils/FormatTags' import { getValue } from '#utils/GetValue' import MarkerIconFactory from '#utils/MarkerIconFactory' @@ -30,6 +29,8 @@ import MarkerIconFactory from '#utils/MarkerIconFactory' import { LocateControl } from './LocateControl' import { SidebarControl } from './SidebarControl' +import type { Item } from '#types/Item' + export const SearchControl = () => { const windowDimensions = useWindowDimensions() const [popupOpen, setPopupOpen] = useState(false) diff --git a/src/Components/Map/Subcomponents/ItemFormPopup.tsx b/src/Components/Map/Subcomponents/ItemFormPopup.tsx index 405a341..64cb9b9 100644 --- a/src/Components/Map/Subcomponents/ItemFormPopup.tsx +++ b/src/Components/Map/Subcomponents/ItemFormPopup.tsx @@ -17,10 +17,12 @@ import { TextInput } from '#components/Input/TextInput' import { useResetFilterTags } from '#components/Map/hooks/useFilter' import { useAddItem, useItems, useRemoveItem, useUpdateItem } from '#components/Map/hooks/useItems' import { useAddTag, useTags } from '#components/Map/hooks/useTags' -import { Geometry, Item, ItemFormPopupProps } from '#src/types' import { hashTagRegex } from '#utils/HashTagRegex' import { randomColor } from '#utils/RandomColor' +import type { Item } from '#types/Item' +import type { ItemFormPopupProps } from '#types/ItemFormPopupProps' + export function ItemFormPopup(props: ItemFormPopupProps) { const [spinner, setSpinner] = useState(false) @@ -50,7 +52,7 @@ export function ItemFormPopup(props: ItemFormPopupProps) { formItem[input.name] = input.value } }) - formItem.position = new Geometry(props.position.lng, props.position.lat) + formItem.position = { type: 'Point', coordinates: [props.position.lng, props.position.lat] } evt.preventDefault() setSpinner(true) diff --git a/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView.tsx b/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView.tsx index 078ae83..83fd9f2 100644 --- a/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView.tsx +++ b/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView.tsx @@ -15,9 +15,11 @@ import { useNavigate } from 'react-router-dom' import { useAppState } from '#components/AppShell/hooks/useAppState' import { useHasUserPermission } from '#components/Map/hooks/usePermissions' import DialogModal from '#components/Templates/DialogModal' -import { Item, ItemsApi } from '#src/types' import { getValue } from '#utils/GetValue' +import type { Item } from '#types/Item' +import type { ItemsApi } from '#types/ItemsApi' + export function HeaderView({ item, api, diff --git a/src/Components/Map/Subcomponents/ItemPopupComponents/PopupButton.tsx b/src/Components/Map/Subcomponents/ItemPopupComponents/PopupButton.tsx index 8ba9bb6..3f3bf2d 100644 --- a/src/Components/Map/Subcomponents/ItemPopupComponents/PopupButton.tsx +++ b/src/Components/Map/Subcomponents/ItemPopupComponents/PopupButton.tsx @@ -3,9 +3,10 @@ import { Link } from 'react-router-dom' import { useGetItemTags } from '#components/Map/hooks/useTags' -import { Item } from '#src/types' import { getValue } from '#utils/GetValue' +import type { Item } from '#types/Item' + export const PopupButton = ({ url, parameterField, diff --git a/src/Components/Map/Subcomponents/ItemPopupComponents/PopupCheckboxInput.tsx b/src/Components/Map/Subcomponents/ItemPopupComponents/PopupCheckboxInput.tsx index 64c3eb6..42a1d6c 100644 --- a/src/Components/Map/Subcomponents/ItemPopupComponents/PopupCheckboxInput.tsx +++ b/src/Components/Map/Subcomponents/ItemPopupComponents/PopupCheckboxInput.tsx @@ -1,4 +1,4 @@ -import { Item } from '#src/types' +import type { Item } from '#types/Item' export const PopupCheckboxInput = ({ dataField, diff --git a/src/Components/Map/Subcomponents/ItemPopupComponents/PopupStartEndInput.tsx b/src/Components/Map/Subcomponents/ItemPopupComponents/PopupStartEndInput.tsx index f46ce12..819182d 100644 --- a/src/Components/Map/Subcomponents/ItemPopupComponents/PopupStartEndInput.tsx +++ b/src/Components/Map/Subcomponents/ItemPopupComponents/PopupStartEndInput.tsx @@ -1,6 +1,7 @@ /* eslint-disable @typescript-eslint/prefer-optional-chain */ import { TextInput } from '#components/Input' -import { Item } from '#src/types' + +import type { Item } from '#types/Item' interface StartEndInputProps { item?: Item diff --git a/src/Components/Map/Subcomponents/ItemPopupComponents/PopupTextAreaInput.tsx b/src/Components/Map/Subcomponents/ItemPopupComponents/PopupTextAreaInput.tsx index 6f8fabf..c07b6b2 100644 --- a/src/Components/Map/Subcomponents/ItemPopupComponents/PopupTextAreaInput.tsx +++ b/src/Components/Map/Subcomponents/ItemPopupComponents/PopupTextAreaInput.tsx @@ -1,5 +1,6 @@ import { TextAreaInput } from '#components/Input' -import { Item } from '#src/types' + +import type { Item } from '#types/Item' export const PopupTextAreaInput = ({ dataField, diff --git a/src/Components/Map/Subcomponents/ItemPopupComponents/PopupTextInput.tsx b/src/Components/Map/Subcomponents/ItemPopupComponents/PopupTextInput.tsx index df72cbe..4030769 100644 --- a/src/Components/Map/Subcomponents/ItemPopupComponents/PopupTextInput.tsx +++ b/src/Components/Map/Subcomponents/ItemPopupComponents/PopupTextInput.tsx @@ -1,5 +1,6 @@ import { TextInput } from '#components/Input' -import { Item } from '#src/types' + +import type { Item } from '#types/Item' export const PopupTextInput = ({ dataField, diff --git a/src/Components/Map/Subcomponents/ItemPopupComponents/StartEndView.tsx b/src/Components/Map/Subcomponents/ItemPopupComponents/StartEndView.tsx index 4496535..c41d86f 100644 --- a/src/Components/Map/Subcomponents/ItemPopupComponents/StartEndView.tsx +++ b/src/Components/Map/Subcomponents/ItemPopupComponents/StartEndView.tsx @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/prefer-optional-chain */ -import { Item } from '#src/types' +import type { Item } from '#types/Item' export const StartEndView = ({ item }: { item?: Item }) => { return ( diff --git a/src/Components/Map/Subcomponents/ItemPopupComponents/TextView.tsx b/src/Components/Map/Subcomponents/ItemPopupComponents/TextView.tsx index 33999ff..5911515 100644 --- a/src/Components/Map/Subcomponents/ItemPopupComponents/TextView.tsx +++ b/src/Components/Map/Subcomponents/ItemPopupComponents/TextView.tsx @@ -11,12 +11,14 @@ import remarkBreaks from 'remark-breaks' import { useAddFilterTag } from '#components/Map/hooks/useFilter' import { useTags } from '#components/Map/hooks/useTags' -import { Item, Tag } from '#src/types' import { decodeTag } from '#utils/FormatTags' import { getValue } from '#utils/GetValue' import { hashTagRegex } from '#utils/HashTagRegex' import { fixUrls, mailRegex } from '#utils/ReplaceURLs' +import type { Item } from '#types/Item' +import type { Tag } from '#types/Tag' + export const TextView = ({ item, truncate = false, diff --git a/src/Components/Map/Subcomponents/ItemViewPopup.tsx b/src/Components/Map/Subcomponents/ItemViewPopup.tsx index 27464a5..633634e 100644 --- a/src/Components/Map/Subcomponents/ItemViewPopup.tsx +++ b/src/Components/Map/Subcomponents/ItemViewPopup.tsx @@ -15,12 +15,14 @@ import { toast } from 'react-toastify' import { useRemoveItem, useUpdateItem } from '#components/Map/hooks/useItems' import { useSetSelectPosition } from '#components/Map/hooks/useSelectPosition' -import { Item, ItemFormPopupProps } from '#src/types' import { timeAgo } from '#utils/TimeAgo' import { HeaderView } from './ItemPopupComponents/HeaderView' import { TextView } from './ItemPopupComponents/TextView' +import type { Item } from '#types/Item' +import type { ItemFormPopupProps } from '#types/ItemFormPopupProps' + export interface ItemViewPopupProps { item: Item children?: React.ReactNode diff --git a/src/Components/Map/Tags.tsx b/src/Components/Map/Tags.tsx index c9a9f53..ff77a3f 100644 --- a/src/Components/Map/Tags.tsx +++ b/src/Components/Map/Tags.tsx @@ -1,11 +1,12 @@ import { useEffect } from 'react' import { useLocation } from 'react-router-dom' -import { ItemsApi, Tag } from '#src/types' - import { useAddFilterTag, useFilterTags, useResetFilterTags } from './hooks/useFilter' import { useSetTagData, useSetTagApi, useTags } from './hooks/useTags' +import type { ItemsApi } from '#types/ItemsApi' +import type { Tag } from '#types/Tag' + export function Tags({ data, api }: { data?: Tag[]; api?: ItemsApi }) { const setTagData = useSetTagData() const setTagApi = useSetTagApi() diff --git a/src/Components/Map/UtopiaMap.tsx b/src/Components/Map/UtopiaMap.tsx index 0a577e9..5240d68 100644 --- a/src/Components/Map/UtopiaMap.tsx +++ b/src/Components/Map/UtopiaMap.tsx @@ -1,7 +1,9 @@ import { ContextWrapper } from '#components/AppShell/ContextWrapper' -import { UtopiaMapProps } from '#src/types' import { UtopiaMapInner } from './UtopiaMapInner' + +import type { UtopiaMapProps } from '#types/UtopiaMapProps' + // eslint-disable-next-line import/no-unassigned-import import 'react-toastify/dist/ReactToastify.css' diff --git a/src/Components/Map/UtopiaMapInner.tsx b/src/Components/Map/UtopiaMapInner.tsx index deb3fa5..3a8df9c 100644 --- a/src/Components/Map/UtopiaMapInner.tsx +++ b/src/Components/Map/UtopiaMapInner.tsx @@ -23,8 +23,6 @@ import MarkerClusterGroup from 'react-leaflet-cluster' import { Outlet } from 'react-router-dom' import { toast } from 'react-toastify' -import { ItemFormPopupProps, UtopiaMapProps } from '#src/types' - // eslint-disable-next-line import/no-unassigned-import import './UtopiaMap.css' @@ -46,6 +44,8 @@ import { TagsControl } from './Subcomponents/Controls/TagsControl' import { TextView } from './Subcomponents/ItemPopupComponents/TextView' import { SelectPosition } from './Subcomponents/SelectPosition' +import type { ItemFormPopupProps } from '#types/ItemFormPopupProps' +import type { UtopiaMapProps } from '#types/UtopiaMapProps' import type { Feature, Geometry as GeoJSONGeometry } from 'geojson' const mapDivRef = createRef() diff --git a/src/Components/Map/hooks/useFilter.tsx b/src/Components/Map/hooks/useFilter.tsx index 8b21caf..febc6bf 100644 --- a/src/Components/Map/hooks/useFilter.tsx +++ b/src/Components/Map/hooks/useFilter.tsx @@ -7,11 +7,12 @@ import { useCallback, useReducer, createContext, useContext, useState } from 'react' import { useNavigate } from 'react-router-dom' -import { LayerProps, Tag } from '#src/types' - import { useLayers } from './useLayers' import useWindowDimensions from './useWindowDimension' +import type { LayerProps } from '#types/LayerProps' +import type { Tag } from '#types/Tag' + type ActionType = | { type: 'ADD_TAG'; tag: Tag } | { type: 'REMOVE_TAG'; name: string } diff --git a/src/Components/Map/hooks/useItems.tsx b/src/Components/Map/hooks/useItems.tsx index 3e67c2c..db174e7 100644 --- a/src/Components/Map/hooks/useItems.tsx +++ b/src/Components/Map/hooks/useItems.tsx @@ -3,17 +3,16 @@ /* eslint-disable @typescript-eslint/no-empty-function */ /* eslint-disable @typescript-eslint/no-non-null-assertion */ /* eslint-disable @typescript-eslint/restrict-template-expressions */ -/* eslint-disable @typescript-eslint/no-unsafe-member-access */ -/* eslint-disable @typescript-eslint/no-unsafe-call */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/no-misused-promises */ import { useCallback, useReducer, createContext, useContext, useState } from 'react' import { toast } from 'react-toastify' -import { Item, LayerProps } from '#src/types' - import { useAddLayer } from './useLayers' +import type { Item } from '#types/Item' +import type { LayerProps } from '#types/LayerProps' + type ActionType = | { type: 'ADD'; item: Item } | { type: 'UPDATE'; item: Item } @@ -82,13 +81,11 @@ function useItemsManager(initialItems: Item[]): { }, }, }) - if (result) { - result.map((item) => { - dispatch({ type: 'ADD', item: { ...item, layer } }) - return null - }) - setallItemsLoaded(true) - } + result.map((item) => { + dispatch({ type: 'ADD', item: { ...item, layer } }) + return null + }) + setallItemsLoaded(true) // eslint-disable-next-line react-hooks/exhaustive-deps }, []) diff --git a/src/Components/Map/hooks/useLayers.tsx b/src/Components/Map/hooks/useLayers.tsx index 392d535..477ffc6 100644 --- a/src/Components/Map/hooks/useLayers.tsx +++ b/src/Components/Map/hooks/useLayers.tsx @@ -2,7 +2,7 @@ /* eslint-disable @typescript-eslint/no-empty-function */ import { useCallback, useReducer, createContext, useContext } from 'react' -import { LayerProps } from '#src/types' +import type { LayerProps } from '#types/LayerProps' interface ActionType { type: 'ADD LAYER' diff --git a/src/Components/Map/hooks/useLeafletRefs.tsx b/src/Components/Map/hooks/useLeafletRefs.tsx index 3a728b4..a092d98 100644 --- a/src/Components/Map/hooks/useLeafletRefs.tsx +++ b/src/Components/Map/hooks/useLeafletRefs.tsx @@ -1,10 +1,10 @@ /* eslint-disable react/prop-types */ /* eslint-disable @typescript-eslint/ban-types */ /* eslint-disable @typescript-eslint/no-empty-function */ -import { Marker, Popup } from 'leaflet' import { useCallback, useReducer, createContext, useContext } from 'react' -import { Item } from '#src/types' +import type { Item } from '#types/Item' +import type { Marker, Popup } from 'leaflet' interface LeafletRef { item: Item diff --git a/src/Components/Map/hooks/usePermissions.tsx b/src/Components/Map/hooks/usePermissions.tsx index d74021b..5d149eb 100644 --- a/src/Components/Map/hooks/usePermissions.tsx +++ b/src/Components/Map/hooks/usePermissions.tsx @@ -1,6 +1,5 @@ /* eslint-disable react/prop-types */ /* eslint-disable @typescript-eslint/no-misused-promises */ -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/no-empty-function */ /* eslint-disable @typescript-eslint/prefer-optional-chain */ /* eslint-disable @typescript-eslint/no-unsafe-call */ @@ -10,7 +9,12 @@ import { useCallback, useReducer, createContext, useContext, useState } from 'react' import { useAuth } from '#components/Auth/useAuth' -import { Item, ItemsApi, LayerProps, Permission, PermissionAction } from '#src/types' + +import type { Item } from '#types/Item' +import type { ItemsApi } from '#types/ItemsApi' +import type { LayerProps } from '#types/LayerProps' +import type { Permission } from '#types/Permission' +import type { PermissionAction } from '#types/PermissionAction' type ActionType = { type: 'ADD'; permission: Permission } | { type: 'REMOVE'; id: string } @@ -57,12 +61,10 @@ function usePermissionsManager(initialPermissions: Permission[]): { const setPermissionApi = useCallback(async (api: ItemsApi) => { const result = await api.getItems() - if (result) { - result.map((permission) => { - dispatch({ type: 'ADD', permission }) - return null - }) - } + result.map((permission) => { + dispatch({ type: 'ADD', permission }) + return null + }) }, []) const setPermissionData = useCallback((data: Permission[]) => { diff --git a/src/Components/Map/hooks/useSelectPosition.tsx b/src/Components/Map/hooks/useSelectPosition.tsx index cc5409d..541e05a 100644 --- a/src/Components/Map/hooks/useSelectPosition.tsx +++ b/src/Components/Map/hooks/useSelectPosition.tsx @@ -8,15 +8,18 @@ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-unsafe-call */ /* eslint-disable @typescript-eslint/no-non-null-assertion */ -import { LatLng } from 'leaflet' import { createContext, useContext, useEffect, useState } from 'react' import { toast } from 'react-toastify' -import { Geometry, Item, LayerProps, ItemFormPopupProps } from '#src/types' - import { useUpdateItem } from './useItems' import { useHasUserPermission } from './usePermissions' +import type { Item } from '#types/Item' +import type { ItemFormPopupProps } from '#types/ItemFormPopupProps' +import type { LayerProps } from '#types/LayerProps' +import type { Point } from 'geojson' +import type { LatLng } from 'leaflet' + interface PolygonClickedProps { position: LatLng setItemFormPopup: React.Dispatch> @@ -67,7 +70,11 @@ function useSelectPositionManager(): { } if ('text' in selectPosition) { const position = - mapClicked?.position.lng && new Geometry(mapClicked.position.lng, mapClicked.position.lat) + mapClicked?.position.lng && + ({ + type: 'Point', + coordinates: [mapClicked.position.lng, mapClicked.position.lat], + } as Point) position && itemUpdatePosition({ ...selectPosition, position }) setSelectPosition(null) } diff --git a/src/Components/Map/hooks/useTags.tsx b/src/Components/Map/hooks/useTags.tsx index 83e3a37..f80e96a 100644 --- a/src/Components/Map/hooks/useTags.tsx +++ b/src/Components/Map/hooks/useTags.tsx @@ -1,6 +1,5 @@ /* eslint-disable react/prop-types */ /* eslint-disable @typescript-eslint/no-misused-promises */ -/* eslint-disable @typescript-eslint/no-unsafe-argument */ /* eslint-disable @typescript-eslint/no-empty-function */ /* eslint-disable @typescript-eslint/no-floating-promises */ /* eslint-disable @typescript-eslint/prefer-optional-chain */ @@ -11,10 +10,13 @@ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ import { useCallback, useReducer, createContext, useContext, useState } from 'react' -import { Item, ItemsApi, Tag } from '#src/types' import { getValue } from '#utils/GetValue' import { hashTagRegex } from '#utils/HashTagRegex' +import type { Item } from '#types/Item' +import type { ItemsApi } from '#types/ItemsApi' +import type { Tag } from '#types/Tag' + type ActionType = { type: 'ADD'; tag: Tag } | { type: 'REMOVE'; id: string } type UseTagManagerResult = ReturnType diff --git a/src/Components/Profile/ProfileForm.tsx b/src/Components/Profile/ProfileForm.tsx index 67c421f..b51344b 100644 --- a/src/Components/Profile/ProfileForm.tsx +++ b/src/Components/Profile/ProfileForm.tsx @@ -14,7 +14,6 @@ import { useLayers } from '#components/Map/hooks/useLayers' import { useHasUserPermission } from '#components/Map/hooks/usePermissions' import { useAddTag, useGetItemTags, useTags } from '#components/Map/hooks/useTags' import { MapOverlayPage } from '#components/Templates' -import { Item, Tag } from '#src/types' import { getValue } from '#utils/GetValue' import { linkItem, onUpdateItem, unlinkItem } from './itemFunctions' @@ -24,6 +23,9 @@ import { OnepagerForm } from './Templates/OnepagerForm' import { SimpleForm } from './Templates/SimpleForm' import { TabsForm } from './Templates/TabsForm' +import type { Item } from '#types/Item' +import type { Tag } from '#types/Tag' + export function ProfileForm() { const [state, setState] = useState({ color: '', diff --git a/src/Components/Profile/ProfileView.tsx b/src/Components/Profile/ProfileView.tsx index 92a329c..76c42ae 100644 --- a/src/Components/Profile/ProfileView.tsx +++ b/src/Components/Profile/ProfileView.tsx @@ -21,7 +21,6 @@ import { useSelectPosition, useSetSelectPosition } from '#components/Map/hooks/u import { useTags } from '#components/Map/hooks/useTags' import { HeaderView } from '#components/Map/Subcomponents/ItemPopupComponents/HeaderView' import { MapOverlayPage } from '#components/Templates' -import { Item, ItemsApi, Tag } from '#src/types' import { getValue } from '#utils/GetValue' import { handleDelete, linkItem, unlinkItem } from './itemFunctions' @@ -30,6 +29,10 @@ import { OnepagerView } from './Templates/OnepagerView' import { SimpleView } from './Templates/SimpleView' import { TabsView } from './Templates/TabsView' +import type { Item } from '#types/Item' +import type { ItemsApi } from '#types/ItemsApi' +import type { Tag } from '#types/Tag' + export function ProfileView({ attestationApi }: { attestationApi?: ItemsApi }) { const [item, setItem] = useState() const [updatePermission, setUpdatePermission] = useState(false) diff --git a/src/Components/Profile/Subcomponents/ActionsButton.tsx b/src/Components/Profile/Subcomponents/ActionsButton.tsx index 4b62d2d..7eea5e4 100644 --- a/src/Components/Profile/Subcomponents/ActionsButton.tsx +++ b/src/Components/Profile/Subcomponents/ActionsButton.tsx @@ -10,9 +10,10 @@ import { useHasUserPermission } from '#components/Map/hooks/usePermissions' import { useGetItemTags } from '#components/Map/hooks/useTags' import { HeaderView } from '#components/Map/Subcomponents/ItemPopupComponents/HeaderView' import DialogModal from '#components/Templates/DialogModal' -import { Item } from '#src/types' import { getValue } from '#utils/GetValue' +import type { Item } from '#types/Item' + export function ActionButton({ item, triggerAddButton, diff --git a/src/Components/Profile/Subcomponents/ContactInfoForm.tsx b/src/Components/Profile/Subcomponents/ContactInfoForm.tsx index ed5cea1..7f129d0 100644 --- a/src/Components/Profile/Subcomponents/ContactInfoForm.tsx +++ b/src/Components/Profile/Subcomponents/ContactInfoForm.tsx @@ -1,7 +1,8 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-unsafe-return */ import { TextInput } from '#components/Input' -import { FormState } from '#src/types' + +import type { FormState } from '#types/FormState' export const ContactInfoForm = ({ state, diff --git a/src/Components/Profile/Subcomponents/ContactInfoView.tsx b/src/Components/Profile/Subcomponents/ContactInfoView.tsx index 80bc5f9..ae9fb81 100644 --- a/src/Components/Profile/Subcomponents/ContactInfoView.tsx +++ b/src/Components/Profile/Subcomponents/ContactInfoView.tsx @@ -8,7 +8,8 @@ import { Link } from 'react-router-dom' import { useAppState } from '#components/AppShell/hooks/useAppState' import { useItems } from '#components/Map/hooks/useItems' -import { Item } from '#src/types' + +import type { Item } from '#types/Item' export const ContactInfoView = ({ item, heading }: { item: Item; heading: string }) => { const appState = useAppState() diff --git a/src/Components/Profile/Subcomponents/GroupSubHeaderView.tsx b/src/Components/Profile/Subcomponents/GroupSubHeaderView.tsx index 98196e2..7718b07 100644 --- a/src/Components/Profile/Subcomponents/GroupSubHeaderView.tsx +++ b/src/Components/Profile/Subcomponents/GroupSubHeaderView.tsx @@ -1,7 +1,7 @@ -import { Item } from '#src/types' - import SocialShareBar from './SocialShareBar' +import type { Item } from '#types/Item' + export const GroupSubHeaderView = ({ item, shareBaseUrl, diff --git a/src/Components/Profile/Subcomponents/GroupSubheaderForm.tsx b/src/Components/Profile/Subcomponents/GroupSubheaderForm.tsx index afd43c2..55b8c58 100644 --- a/src/Components/Profile/Subcomponents/GroupSubheaderForm.tsx +++ b/src/Components/Profile/Subcomponents/GroupSubheaderForm.tsx @@ -4,7 +4,9 @@ import { useEffect } from 'react' import ComboBoxInput from '#components/Input/ComboBoxInput' -import { Item, FormState } from '#src/types' + +import type { FormState } from '#types/FormState' +import type { Item } from '#types/Item' interface groupType { groupTypes_id: { diff --git a/src/Components/Profile/Subcomponents/LinkedItemsHeaderView.tsx b/src/Components/Profile/Subcomponents/LinkedItemsHeaderView.tsx index 48d1d72..57dd0ce 100644 --- a/src/Components/Profile/Subcomponents/LinkedItemsHeaderView.tsx +++ b/src/Components/Profile/Subcomponents/LinkedItemsHeaderView.tsx @@ -8,9 +8,10 @@ import { useEffect } from 'react' import { useAppState } from '#components/AppShell/hooks/useAppState' -import { Item } from '#src/types' import { getValue } from '#utils/GetValue' +import type { Item } from '#types/Item' + export function LinkedItemsHeaderView({ item, unlinkCallback, diff --git a/src/Components/Profile/Subcomponents/PlusButton.tsx b/src/Components/Profile/Subcomponents/PlusButton.tsx index 9faba0d..c8122d9 100644 --- a/src/Components/Profile/Subcomponents/PlusButton.tsx +++ b/src/Components/Profile/Subcomponents/PlusButton.tsx @@ -1,7 +1,8 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-unsafe-call */ import { useHasUserPermission } from '#components/Map/hooks/usePermissions' -import { LayerProps } from '#src/types' + +import type { LayerProps } from '#types/LayerProps' export function PlusButton({ layer, diff --git a/src/Components/Profile/Subcomponents/ProfileStartEndForm.tsx b/src/Components/Profile/Subcomponents/ProfileStartEndForm.tsx index 5657ac6..e5f67ff 100644 --- a/src/Components/Profile/Subcomponents/ProfileStartEndForm.tsx +++ b/src/Components/Profile/Subcomponents/ProfileStartEndForm.tsx @@ -1,7 +1,8 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-unsafe-return */ import { PopupStartEndInput } from '#components/Map' -import { Item } from '#src/types' + +import type { Item } from '#types/Item' export const ProfileStartEndForm = ({ item, diff --git a/src/Components/Profile/Subcomponents/ProfileStartEndView.tsx b/src/Components/Profile/Subcomponents/ProfileStartEndView.tsx index f166523..8d64e55 100644 --- a/src/Components/Profile/Subcomponents/ProfileStartEndView.tsx +++ b/src/Components/Profile/Subcomponents/ProfileStartEndView.tsx @@ -1,5 +1,6 @@ import { StartEndView } from '#components/Map' -import { Item } from '#src/types' + +import type { Item } from '#types/Item' export const ProfileStartEndView = ({ item }: { item: Item }) => { return ( diff --git a/src/Components/Profile/Subcomponents/ProfileTextForm.tsx b/src/Components/Profile/Subcomponents/ProfileTextForm.tsx index 364008f..9509d92 100644 --- a/src/Components/Profile/Subcomponents/ProfileTextForm.tsx +++ b/src/Components/Profile/Subcomponents/ProfileTextForm.tsx @@ -5,11 +5,12 @@ import { useEffect, useState } from 'react' import { TextAreaInput } from '#components/Input' -import { FormState } from '#src/types' import { getValue } from '#utils/GetValue' import { MarkdownHint } from './MarkdownHint' +import type { FormState } from '#types/FormState' + export const ProfileTextForm = ({ state, setState, diff --git a/src/Components/Profile/Subcomponents/ProfileTextView.tsx b/src/Components/Profile/Subcomponents/ProfileTextView.tsx index e36f04d..8a2725c 100644 --- a/src/Components/Profile/Subcomponents/ProfileTextView.tsx +++ b/src/Components/Profile/Subcomponents/ProfileTextView.tsx @@ -1,8 +1,9 @@ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ import { TextView } from '#components/Map' -import { Item } from '#src/types' import { getValue } from '#utils/GetValue' +import type { Item } from '#types/Item' + export const ProfileTextView = ({ item, dataField, diff --git a/src/Components/Profile/Subcomponents/TagsWidget.tsx b/src/Components/Profile/Subcomponents/TagsWidget.tsx index 3a5709a..b1a03ad 100644 --- a/src/Components/Profile/Subcomponents/TagsWidget.tsx +++ b/src/Components/Profile/Subcomponents/TagsWidget.tsx @@ -8,10 +8,11 @@ import { useEffect, useState } from 'react' import { Autocomplete } from '#components/Input/Autocomplete' import { useTags } from '#components/Map/hooks/useTags' -import { Tag } from '#src/types' import { decodeTag, encodeTag } from '#utils/FormatTags' import { randomColor } from '#utils/RandomColor' +import type { Tag } from '#types/Tag' + // eslint-disable-next-line react/prop-types export const TagsWidget = ({ placeholder, containerStyle, defaultTags, onUpdate }) => { const [input, setInput] = useState('') diff --git a/src/Components/Profile/Templates/FlexForm.tsx b/src/Components/Profile/Templates/FlexForm.tsx index c7a8d5f..56f14ea 100644 --- a/src/Components/Profile/Templates/FlexForm.tsx +++ b/src/Components/Profile/Templates/FlexForm.tsx @@ -7,7 +7,9 @@ import { ContactInfoForm } from '#components/Profile/Subcomponents/ContactInfoFo import { GroupSubheaderForm } from '#components/Profile/Subcomponents/GroupSubheaderForm' import { ProfileStartEndForm } from '#components/Profile/Subcomponents/ProfileStartEndForm' import { ProfileTextForm } from '#components/Profile/Subcomponents/ProfileTextForm' -import { Item, FormState } from '#src/types' + +import type { FormState } from '#types/FormState' +import type { Item } from '#types/Item' const componentMap = { groupSubheaders: GroupSubheaderForm, diff --git a/src/Components/Profile/Templates/FlexView.tsx b/src/Components/Profile/Templates/FlexView.tsx index 0fb741e..1dea72d 100644 --- a/src/Components/Profile/Templates/FlexView.tsx +++ b/src/Components/Profile/Templates/FlexView.tsx @@ -6,7 +6,8 @@ import { ContactInfoView } from '#components/Profile/Subcomponents/ContactInfoVi import { GroupSubHeaderView } from '#components/Profile/Subcomponents/GroupSubHeaderView' import { ProfileStartEndView } from '#components/Profile/Subcomponents/ProfileStartEndView' import { ProfileTextView } from '#components/Profile/Subcomponents/ProfileTextView' -import { Item } from '#src/types' + +import type { Item } from '#types/Item' const componentMap = { groupSubheaders: GroupSubHeaderView, diff --git a/src/Components/Profile/Templates/OnepagerForm.tsx b/src/Components/Profile/Templates/OnepagerForm.tsx index db7d4f3..163cae4 100644 --- a/src/Components/Profile/Templates/OnepagerForm.tsx +++ b/src/Components/Profile/Templates/OnepagerForm.tsx @@ -3,7 +3,9 @@ import { TextAreaInput } from '#components/Input' import { ContactInfoForm } from '#components/Profile/Subcomponents/ContactInfoForm' import { GroupSubheaderForm } from '#components/Profile/Subcomponents/GroupSubheaderForm' -import { FormState, Item } from '#src/types' + +import type { FormState } from '#types/FormState' +import type { Item } from '#types/Item' export const OnepagerForm = ({ item, diff --git a/src/Components/Profile/Templates/OnepagerView.tsx b/src/Components/Profile/Templates/OnepagerView.tsx index b5e9328..10e49a0 100644 --- a/src/Components/Profile/Templates/OnepagerView.tsx +++ b/src/Components/Profile/Templates/OnepagerView.tsx @@ -4,7 +4,8 @@ import { TextView } from '#components/Map' import { ContactInfoView } from '#components/Profile/Subcomponents/ContactInfoView' import { GroupSubHeaderView } from '#components/Profile/Subcomponents/GroupSubHeaderView' -import { Item } from '#src/types' + +import type { Item } from '#types/Item' export const OnepagerView = ({ item }: { item: Item }) => { return ( diff --git a/src/Components/Profile/Templates/SimpleView.tsx b/src/Components/Profile/Templates/SimpleView.tsx index 027ed7c..dca6d07 100644 --- a/src/Components/Profile/Templates/SimpleView.tsx +++ b/src/Components/Profile/Templates/SimpleView.tsx @@ -1,5 +1,6 @@ import { TextView } from '#components/Map' -import { Item } from '#src/types' + +import type { Item } from '#types/Item' export const SimpleView = ({ item }: { item: Item }) => { return ( diff --git a/src/Components/Profile/Templates/TabsView.tsx b/src/Components/Profile/Templates/TabsView.tsx index 2b046f7..3f6dc05 100644 --- a/src/Components/Profile/Templates/TabsView.tsx +++ b/src/Components/Profile/Templates/TabsView.tsx @@ -16,9 +16,11 @@ import { useItems } from '#components/Map/hooks/useItems' import { ActionButton } from '#components/Profile/Subcomponents/ActionsButton' import { LinkedItemsHeaderView } from '#components/Profile/Subcomponents/LinkedItemsHeaderView' import { TagView } from '#components/Templates/TagView' -import { Item, Tag } from '#src/types' import { timeAgo } from '#utils/TimeAgo' +import type { Item } from '#types/Item' +import type { Tag } from '#types/Tag' + export const TabsView = ({ attestations, item, diff --git a/src/Components/Profile/UserSettings.tsx b/src/Components/Profile/UserSettings.tsx index e98896c..9f602f6 100644 --- a/src/Components/Profile/UserSettings.tsx +++ b/src/Components/Profile/UserSettings.tsx @@ -7,7 +7,8 @@ import { toast } from 'react-toastify' import { useAuth } from '#components/Auth' import { TextInput } from '#components/Input' import { MapOverlayPage } from '#components/Templates' -import { UserItem } from '#src/types' + +import type { UserItem } from '#types/UserItem' export function UserSettings() { const { user, updateUser, loading /* token */ } = useAuth() diff --git a/src/Components/Profile/itemFunctions.ts b/src/Components/Profile/itemFunctions.ts index e599912..ad11c53 100644 --- a/src/Components/Profile/itemFunctions.ts +++ b/src/Components/Profile/itemFunctions.ts @@ -11,11 +11,12 @@ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ import { toast } from 'react-toastify' -import { Item } from '#src/types' import { encodeTag } from '#utils/FormatTags' import { hashTagRegex } from '#utils/HashTagRegex' import { randomColor } from '#utils/RandomColor' +import type { Item } from '#types/Item' + // eslint-disable-next-line promise/avoid-new const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)) diff --git a/src/Components/Templates/AttestationForm.tsx b/src/Components/Templates/AttestationForm.tsx index a5ed5b6..595280e 100644 --- a/src/Components/Templates/AttestationForm.tsx +++ b/src/Components/Templates/AttestationForm.tsx @@ -13,11 +13,13 @@ import { toast } from 'react-toastify' import { useAppState } from '#components/AppShell/hooks/useAppState' import { useItems } from '#components/Map/hooks/useItems' -import { Item, ItemsApi } from '#src/types' import { EmojiPicker } from './EmojiPicker' import { MapOverlayPage } from './MapOverlayPage' +import type { Item } from '#types/Item' +import type { ItemsApi } from '#types/ItemsApi' + export const AttestationForm = ({ api }: { api?: ItemsApi }) => { const items = useItems() const appState = useAppState() diff --git a/src/Components/Templates/DateUserInfo.tsx b/src/Components/Templates/DateUserInfo.tsx index a25e623..b7bbd7d 100644 --- a/src/Components/Templates/DateUserInfo.tsx +++ b/src/Components/Templates/DateUserInfo.tsx @@ -5,9 +5,10 @@ /* eslint-disable @typescript-eslint/prefer-optional-chain */ import { useState } from 'react' -import { Item } from '#src/types' import { timeAgo } from '#utils/TimeAgo' +import type { Item } from '#types/Item' + export const DateUserInfo = ({ item }: { item: Item }) => { const [infoExpanded, setInfoExpanded] = useState(false) return ( diff --git a/src/Components/Templates/DialogModal.tsx b/src/Components/Templates/DialogModal.tsx index 3fa4da0..f207be3 100644 --- a/src/Components/Templates/DialogModal.tsx +++ b/src/Components/Templates/DialogModal.tsx @@ -1,4 +1,6 @@ -import { MouseEvent, useEffect, useRef } from 'react' +import { useEffect, useRef } from 'react' + +import type { MouseEvent } from 'react' const isClickInsideRectangle = (e: MouseEvent, element: HTMLElement) => { const r = element.getBoundingClientRect() diff --git a/src/Components/Templates/ItemCard.tsx b/src/Components/Templates/ItemCard.tsx index 2c2d925..585d18a 100644 --- a/src/Components/Templates/ItemCard.tsx +++ b/src/Components/Templates/ItemCard.tsx @@ -9,11 +9,12 @@ import { useNavigate } from 'react-router-dom' import { StartEndView, TextView } from '#components/Map' import useWindowDimensions from '#components/Map/hooks/useWindowDimension' import { HeaderView } from '#components/Map/Subcomponents/ItemPopupComponents/HeaderView' -import { Item } from '#src/types' import { getValue } from '#utils/GetValue' import { DateUserInfo } from './DateUserInfo' +import type { Item } from '#types/Item' + export const ItemCard = ({ i, loading, diff --git a/src/Components/Templates/MarketView.tsx b/src/Components/Templates/MarketView.tsx index 6009e68..1882275 100644 --- a/src/Components/Templates/MarketView.tsx +++ b/src/Components/Templates/MarketView.tsx @@ -8,12 +8,13 @@ import { useNavigate } from 'react-router-dom' import { useItems } from '#components/Map/hooks/useItems' import { useTags } from '#components/Map/hooks/useTags' -import { Tag } from '#src/types' import { getValue } from '#utils/GetValue' import { MapOverlayPage } from './MapOverlayPage' import { TagView } from './TagView' +import type { Tag } from '#types/Tag' + function groupAndCount(arr) { const grouped = arr.reduce((acc, obj) => { const found = acc.find((item) => JSON.stringify(item.object) === JSON.stringify(obj)) diff --git a/src/Components/Templates/OverlayItemsIndexPage.tsx b/src/Components/Templates/OverlayItemsIndexPage.tsx index 1496dbd..62c4c2e 100644 --- a/src/Components/Templates/OverlayItemsIndexPage.tsx +++ b/src/Components/Templates/OverlayItemsIndexPage.tsx @@ -19,13 +19,14 @@ import { Control } from '#components/Map/Subcomponents/Controls/Control' import { SearchControl } from '#components/Map/Subcomponents/Controls/SearchControl' import { TagsControl } from '#components/Map/Subcomponents/Controls/TagsControl' import { PlusButton } from '#components/Profile/Subcomponents/PlusButton' -import { Item } from '#src/types' import { hashTagRegex } from '#utils/HashTagRegex' import { randomColor } from '#utils/RandomColor' import { ItemCard } from './ItemCard' import { MapOverlayPage } from './MapOverlayPage' +import type { Item } from '#types/Item' + export const OverlayItemsIndexPage = ({ url, layerName, diff --git a/src/Components/Templates/TagView.tsx b/src/Components/Templates/TagView.tsx index 13c184a..f19c5ad 100644 --- a/src/Components/Templates/TagView.tsx +++ b/src/Components/Templates/TagView.tsx @@ -1,8 +1,9 @@ /* eslint-disable @typescript-eslint/restrict-template-expressions */ -import { Tag } from '#src/types' import { decodeTag } from '#utils/FormatTags' +import type { Tag } from '#types/Tag' + export const TagView = ({ tag, heighlight, diff --git a/src/types.ts b/src/types.ts deleted file mode 100644 index 4b96423..0000000 --- a/src/types.ts +++ /dev/null @@ -1,207 +0,0 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -import { LatLng } from 'leaflet' - -export interface Tag { - color: string - id: string - name: string - offer_or_need?: boolean -} - -export interface UtopiaMapProps { - height?: string - width?: string - center?: [number, number] - zoom?: number - tags?: Tag[] - children?: React.ReactNode - geo?: any - showFilterControl?: boolean - showLayerControl?: boolean - showGratitudeControl?: boolean - infoText?: string -} - -export interface ItemType { - name: string - [key: string]: any -} - -export interface ItemsApi { - getItems(): Promise - getItem?(id: string): Promise - createItem?(item: T): Promise - updateItem?(item: T): Promise - deleteItem?(id: string): Promise - collectionName?: string -} - -export interface LayerProps { - id?: string - // eslint-disable-next-line no-use-before-define - data?: Item[] - children?: React.ReactNode - name: string - menuIcon: any - menuColor: string - menuText: string - markerIcon: string - markerShape: string - markerDefaultColor: string - markerDefaultColor2?: string - api?: ItemsApi - itemType: ItemType - itemNameField?: string - itemSubnameField?: string - itemTextField?: string - itemAvatarField?: string - itemColorField?: string - itemOwnerField?: string - itemTagsField?: string - itemLatitudeField?: any - itemLongitudeField?: any - itemOffersField?: string - itemNeedsField?: string - onlyOnePerOwner?: boolean - customEditLink?: string - customEditParameter?: string - public_edit_items?: boolean - listed?: boolean - item_presets?: Record - // eslint-disable-next-line no-use-before-define - setItemFormPopup?: React.Dispatch> - // eslint-disable-next-line no-use-before-define - itemFormPopup?: ItemFormPopupProps | null - clusterRef?: any -} - -export class Geometry { - type: string - coordinates: number[] - constructor(lng: number, lat: number) { - this.coordinates = [lng, lat] - this.type = 'Point' - } -} - -export interface Relation { - related_items_id: string - [key: string]: any -} - -export class Item { - id: string - name: string - text: string - position?: Geometry - date_created?: string - date_updated?: string | null - start?: string - end?: string - api?: ItemsApi - tags?: string[] - layer?: LayerProps - relations?: Relation[] - parent?: string - subname?: string - public_edit?: boolean - slug?: string; - [key: string]: any - 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 interface AssetsApi { - upload(file: Blob, title: string): any - url: string -} - -export interface Profile { - id?: string - avatar?: string - color?: string - name: string - text: string - geoposition?: Geometry -} - -export interface UserItem { - id?: string - role?: any - email?: string - password?: string - profile?: Profile - [key: string]: any -} - -export interface UserApi { - register(email: string, password: string, userName: string): Promise - login(email: string, password: string): Promise - logout(): Promise - getUser(): Promise - getToken(): Promise - updateUser(user: UserItem): Promise - requestPasswordReset(email: string, reset_url?: string) - passwordReset(token: string, new_password: string) -} - -export interface PermissionCondition { - user_created?: { - _eq: string // Erwartet den speziellen Wert "$CURRENT_USER" oder eine spezifische UUID - } - public_edit?: { - _eq: boolean // Erwartet den speziellen Wert "$CURRENT_USER" oder eine spezifische UUID - } -} - -export type PermissionAction = 'create' | 'read' | 'update' | 'delete' - -export interface Permission { - id?: string - policy: any - collection: string - action: PermissionAction - permissions?: { - // Optional, für spezifische Bedingungen wie `user_created` - _and: PermissionCondition[] - } -} - -export interface ItemFormPopupProps { - position: LatLng - layer: LayerProps - item?: Item - children?: React.ReactNode - setItemFormPopup?: React.Dispatch> -} - -export interface FormState { - color: string - id: string - group_type: string - status: string - name: string - subname: string - text: string - contact: string - telephone: string - next_appointment: string - image: string - marker_icon: string - offers: Tag[] - needs: Tag[] - relations: Item[] -} diff --git a/tsconfig.json b/tsconfig.json index 1fcb7eb..38e666f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -20,10 +20,11 @@ "#components/*": ["./src/Components/*"], "#utils/*": ["./src/Utils/*"], "#src/*": ["./src/*"], + "#types/*": ["./types/*"], "#root/*": ["./*"] } }, - "include": ["src"], + "include": ["src", "types"], "exclude": ["node_modules", "dist", "example", "rollup.config.mjss"], "typeRoots": [ "./types", diff --git a/types/AssetsApi.d.ts b/types/AssetsApi.d.ts new file mode 100644 index 0000000..ff3d600 --- /dev/null +++ b/types/AssetsApi.d.ts @@ -0,0 +1,5 @@ +export interface AssetsApi { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + upload(file: Blob, title: string): any + url: string +} diff --git a/types/FormState.d.ts b/types/FormState.d.ts new file mode 100644 index 0000000..20589af --- /dev/null +++ b/types/FormState.d.ts @@ -0,0 +1,20 @@ +import type { Item } from './Item' +import type { Tag } from './Tag' + +export interface FormState { + color: string + id: string + group_type: string + status: string + name: string + subname: string + text: string + contact: string + telephone: string + next_appointment: string + image: string + marker_icon: string + offers: Tag[] + needs: Tag[] + relations: Item[] +} diff --git a/types/Item.d.ts b/types/Item.d.ts new file mode 100644 index 0000000..f35d720 --- /dev/null +++ b/types/Item.d.ts @@ -0,0 +1,41 @@ +import type { ItemsApi } from './ItemsApi' +import type { LayerProps } from './LayerProps' +import type { Relation } from './Relation' +import type { Point } from 'geojson' + +export interface Item { + id: string + name: string + text: string + position?: Point + date_created?: string + date_updated?: string | null + start?: string + end?: string + // eslint-disable-next-line @typescript-eslint/no-explicit-any + api?: ItemsApi + tags?: string[] + layer?: LayerProps + relations?: Relation[] + parent?: string + subname?: string + public_edit?: boolean + slug?: string + // eslint-disable-next-line @typescript-eslint/no-explicit-any + [key: string]: any + /* 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 + } */ +} diff --git a/types/ItemFormPopupProps.d.ts b/types/ItemFormPopupProps.d.ts new file mode 100644 index 0000000..64e880b --- /dev/null +++ b/types/ItemFormPopupProps.d.ts @@ -0,0 +1,11 @@ +import type { Item } from './Item' +import type { LayerProps } from './LayerProps' +import type { LatLng } from 'leaflet' + +export interface ItemFormPopupProps { + position: LatLng + layer: LayerProps + item?: Item + children?: React.ReactNode + setItemFormPopup?: React.Dispatch> +} diff --git a/types/ItemType.d.ts b/types/ItemType.d.ts new file mode 100644 index 0000000..1f125cc --- /dev/null +++ b/types/ItemType.d.ts @@ -0,0 +1,5 @@ +export interface ItemType { + name: string + // eslint-disable-next-line @typescript-eslint/no-explicit-any + [key: string]: any +} diff --git a/types/ItemsApi.d.ts b/types/ItemsApi.d.ts new file mode 100644 index 0000000..147fa46 --- /dev/null +++ b/types/ItemsApi.d.ts @@ -0,0 +1,8 @@ +export interface ItemsApi { + getItems(): Promise + getItem?(id: string): Promise + createItem?(item: T): Promise + updateItem?(item: T): Promise + deleteItem?(id: string): Promise + collectionName?: string +} diff --git a/types/LayerProps.d.ts b/types/LayerProps.d.ts new file mode 100644 index 0000000..7d742d5 --- /dev/null +++ b/types/LayerProps.d.ts @@ -0,0 +1,42 @@ +import type { Item } from './Item' +import type { ItemFormPopupProps } from './ItemFormPopupProps' +import type { ItemsApi } from './ItemsApi' +import type { ItemType } from './ItemType' + +export interface LayerProps { + id?: string + data?: Item[] + children?: React.ReactNode + name: string + menuIcon: string + menuColor: string + menuText: string + markerIcon: string + markerShape: string + markerDefaultColor: string + markerDefaultColor2?: string + // eslint-disable-next-line @typescript-eslint/no-explicit-any + api?: ItemsApi + itemType: ItemType + itemNameField?: string + itemSubnameField?: string + itemTextField?: string + itemAvatarField?: string + itemColorField?: string + itemOwnerField?: string + itemTagsField?: string + itemLatitudeField?: string + itemLongitudeField?: string + itemOffersField?: string + itemNeedsField?: string + onlyOnePerOwner?: boolean + customEditLink?: string + customEditParameter?: string + public_edit_items?: boolean + listed?: boolean + item_presets?: Record + setItemFormPopup?: React.Dispatch> + itemFormPopup?: ItemFormPopupProps | null + // eslint-disable-next-line @typescript-eslint/no-explicit-any + clusterRef?: any +} diff --git a/types/Permission.d.ts b/types/Permission.d.ts new file mode 100644 index 0000000..57067fe --- /dev/null +++ b/types/Permission.d.ts @@ -0,0 +1,13 @@ +import type { PermissionAction } from './PermissionAction' +import type { PermissionCondition } from './PermissionCondition' + +export interface Permission { + id?: string + policy?: { name: string } + collection: string + action: PermissionAction + permissions?: { + // Optional, für spezifische Bedingungen wie `user_created` + _and: PermissionCondition[] + } +} diff --git a/types/PermissionAction.d.ts b/types/PermissionAction.d.ts new file mode 100644 index 0000000..7278a06 --- /dev/null +++ b/types/PermissionAction.d.ts @@ -0,0 +1 @@ +export type PermissionAction = 'create' | 'read' | 'update' | 'delete' diff --git a/types/PermissionCondition.d.ts b/types/PermissionCondition.d.ts new file mode 100644 index 0000000..e946bdb --- /dev/null +++ b/types/PermissionCondition.d.ts @@ -0,0 +1,8 @@ +export interface PermissionCondition { + user_created?: { + _eq: string // Erwartet den speziellen Wert "$CURRENT_USER" oder eine spezifische UUID + } + public_edit?: { + _eq: boolean // Erwartet den speziellen Wert "$CURRENT_USER" oder eine spezifische UUID + } +} diff --git a/types/Profile.d.ts b/types/Profile.d.ts new file mode 100644 index 0000000..4bfb898 --- /dev/null +++ b/types/Profile.d.ts @@ -0,0 +1,10 @@ +import type { Geometry } from 'geojson' + +export interface Profile { + id?: string + avatar?: string + color?: string + name: string + text: string + geoposition?: Geometry +} diff --git a/types/Relation.d.ts b/types/Relation.d.ts new file mode 100644 index 0000000..0b03802 --- /dev/null +++ b/types/Relation.d.ts @@ -0,0 +1,5 @@ +export interface Relation { + related_items_id: string + // eslint-disable-next-line @typescript-eslint/no-explicit-any + [key: string]: any +} diff --git a/types/Tag.d.ts b/types/Tag.d.ts new file mode 100644 index 0000000..1dc7c5a --- /dev/null +++ b/types/Tag.d.ts @@ -0,0 +1,6 @@ +export interface Tag { + color: string + id: string + name: string + offer_or_need?: boolean +} diff --git a/types/UserApi.d.ts b/types/UserApi.d.ts new file mode 100644 index 0000000..6c36cd4 --- /dev/null +++ b/types/UserApi.d.ts @@ -0,0 +1,12 @@ +import type { UserItem } from './UserItem' + +export interface UserApi { + register(email: string, password: string, userName: string): Promise + login(email: string, password: string): Promise + logout(): Promise + getUser(): Promise + getToken(): Promise + updateUser(user: UserItem): Promise + requestPasswordReset(email: string, reset_url?: string) + passwordReset(token: string, new_password: string) +} diff --git a/types/UserItem.d.ts b/types/UserItem.d.ts new file mode 100644 index 0000000..77512f2 --- /dev/null +++ b/types/UserItem.d.ts @@ -0,0 +1,12 @@ +import type { Profile } from './Profile' + +export interface UserItem { + id?: string + // eslint-disable-next-line @typescript-eslint/no-explicit-any + role?: any + email?: string + password?: string + profile?: Profile + // eslint-disable-next-line @typescript-eslint/no-explicit-any + [key: string]: any +} diff --git a/types/UtopiaMapProps.d.ts b/types/UtopiaMapProps.d.ts new file mode 100644 index 0000000..99389e8 --- /dev/null +++ b/types/UtopiaMapProps.d.ts @@ -0,0 +1,16 @@ +import type { Tag } from './Tag' +import type { GeoJsonObject } from 'geojson' + +export interface UtopiaMapProps { + height?: string + width?: string + center?: [number, number] + zoom?: number + tags?: Tag[] + children?: React.ReactNode + geo?: GeoJsonObject + showFilterControl?: boolean + showLayerControl?: boolean + showGratitudeControl?: boolean + infoText?: string +}