From f0100be3c6ad212a95070f4750321495677f600b Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 17 Dec 2024 09:47:32 +0100 Subject: [PATCH] make NavBar typesafe --- src/Components/AppShell/NavBar.tsx | 40 +++++++++---------- src/Components/Gaming/Modal.tsx | 2 - src/Components/Gaming/Quests.tsx | 1 - .../Map/Subcomponents/ItemFormPopup.tsx | 5 +-- .../Profile/Subcomponents/ContactInfoView.tsx | 1 - .../Profile/Templates/OnepagerView.tsx | 3 +- src/Components/Templates/AttestationForm.tsx | 5 +-- src/Components/Templates/DateUserInfo.tsx | 2 - src/index.tsx | 5 ++- types/Item.d.ts | 3 ++ types/UserItem.d.ts | 1 + 11 files changed, 32 insertions(+), 36 deletions(-) diff --git a/src/Components/AppShell/NavBar.tsx b/src/Components/AppShell/NavBar.tsx index 2a7a977..7a814cc 100644 --- a/src/Components/AppShell/NavBar.tsx +++ b/src/Components/AppShell/NavBar.tsx @@ -1,14 +1,14 @@ -/* eslint-disable @typescript-eslint/no-empty-function */ -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/no-unsafe-argument */ -/* eslint-disable @typescript-eslint/restrict-template-expressions */ -/* eslint-disable @typescript-eslint/no-floating-promises */ -/* eslint-disable @typescript-eslint/no-unsafe-return */ -/* eslint-disable @typescript-eslint/no-unsafe-member-access */ -/* eslint-disable @typescript-eslint/no-unsafe-call */ -/* eslint-disable @typescript-eslint/restrict-plus-operands */ -/* eslint-disable @typescript-eslint/no-unnecessary-condition */ +// eslint-disable @typescript-eslint/no-empty-function */ +// eslint-disable @typescript-eslint/no-unsafe-assignment */ +// eslint-disable @typescript-eslint/no-explicit-any */ +// eslint-disable @typescript-eslint/no-unsafe-argument */ +// eslint-disable @typescript-eslint/restrict-template-expressions */ +// eslint-disable @typescript-eslint/no-floating-promises */ +// eslint-disable @typescript-eslint/no-unsafe-return */ +// eslint-disable @typescript-eslint/no-unsafe-member-access */ +// eslint-disable @typescript-eslint/no-unsafe-call */ +// eslint-disable @typescript-eslint/restrict-plus-operands */ +// eslint-disable @typescript-eslint/no-unnecessary-condition */ import QuestionMarkIcon from '@heroicons/react/24/outline/QuestionMarkCircleIcon' import { useEffect, useRef, useState } from 'react' import { Link, useLocation } from 'react-router-dom' @@ -31,19 +31,19 @@ export default function NavBar({ appName, userType }: { appName: string; userTyp items.find((i) => i.user_created?.id === user.id && i.layer?.itemType.name === userType) profile ? setUserProfile(profile) - : setUserProfile({ id: crypto.randomUUID(), name: user?.first_name, text: '' }) + : setUserProfile({ id: crypto.randomUUID(), name: user?.first_name ?? '', text: '' }) // eslint-disable-next-line react-hooks/exhaustive-deps }, [user, items]) - useEffect(() => {}, [userProfile]) + // useEffect(() => {}, [userProfile]) - const nameRef = useRef(null) + const nameRef = useRef(null) const [nameWidth, setNameWidth] = useState(0) const location = useLocation() const [showNav, setShowNav] = useState(false) useEffect(() => { - showNav && nameRef && setNameWidth(nameRef.current.scrollWidth) + showNav && nameRef.current && setNameWidth(nameRef.current.scrollWidth) }, [nameRef, appName, showNav]) useEffect(() => { @@ -52,8 +52,8 @@ export default function NavBar({ appName, userType }: { appName: string; userTyp embedded !== 'true' && setShowNav(true) }, [location]) - const onLogout = () => { - toast.promise(logout(), { + const onLogout = async () => { + await toast.promise(logout(), { success: { render() { return 'Bye bye' @@ -63,7 +63,7 @@ export default function NavBar({ appName, userType }: { appName: string; userTyp }, error: { render({ data }) { - return `${data}` + return JSON.stringify(data) }, }, pending: 'logging out ..', @@ -123,7 +123,7 @@ export default function NavBar({ appName, userType }: { appName: string; userTyp to={`${userProfile.id && '/item/' + userProfile.id}`} className='tw-flex tw-items-center' > - {userProfile?.image && ( + {userProfile.image && (
@@ -156,7 +156,7 @@ export default function NavBar({ appName, userType }: { appName: string; userTyp
  • { - onLogout() + void onLogout() }} > Logout diff --git a/src/Components/Gaming/Modal.tsx b/src/Components/Gaming/Modal.tsx index 7d83ac5..d58de15 100644 --- a/src/Components/Gaming/Modal.tsx +++ b/src/Components/Gaming/Modal.tsx @@ -1,5 +1,3 @@ -/* eslint-disable @typescript-eslint/no-unsafe-member-access */ -/* eslint-disable @typescript-eslint/no-unsafe-call */ import { useEffect } from 'react' export function Modal({ diff --git a/src/Components/Gaming/Quests.tsx b/src/Components/Gaming/Quests.tsx index 792b4fa..0e669c6 100644 --- a/src/Components/Gaming/Quests.tsx +++ b/src/Components/Gaming/Quests.tsx @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/no-unsafe-member-access */ import { useEffect, useState } from 'react' import { useAuth } from '#components/Auth' diff --git a/src/Components/Map/Subcomponents/ItemFormPopup.tsx b/src/Components/Map/Subcomponents/ItemFormPopup.tsx index 64cb9b9..ed35d86 100644 --- a/src/Components/Map/Subcomponents/ItemFormPopup.tsx +++ b/src/Components/Map/Subcomponents/ItemFormPopup.tsx @@ -4,7 +4,6 @@ /* eslint-disable @typescript-eslint/no-unsafe-argument */ /* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable @typescript-eslint/no-unsafe-call */ -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/no-non-null-assertion */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ import { Children, cloneElement, isValidElement, useEffect, useRef, useState } from 'react' @@ -113,8 +112,8 @@ export function ItemFormPopup(props: ItemFormPopupProps) { if (!props.layer.onlyOnePerOwner || !item) { addItem({ ...formItem, - name: formItem.name ? formItem.name : user?.first_name, - user_created: user, + name: (formItem.name ? formItem.name : user?.first_name) ?? '', + user_created: user ?? undefined, type: props.layer.itemType, id: uuid, layer: props.layer, diff --git a/src/Components/Profile/Subcomponents/ContactInfoView.tsx b/src/Components/Profile/Subcomponents/ContactInfoView.tsx index ae9fb81..a8368d2 100644 --- a/src/Components/Profile/Subcomponents/ContactInfoView.tsx +++ b/src/Components/Profile/Subcomponents/ContactInfoView.tsx @@ -1,6 +1,5 @@ /* eslint-disable @typescript-eslint/no-unnecessary-condition */ /* eslint-disable @typescript-eslint/restrict-template-expressions */ -/* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-unsafe-return */ /* eslint-disable @typescript-eslint/restrict-plus-operands */ import { useEffect, useState } from 'react' diff --git a/src/Components/Profile/Templates/OnepagerView.tsx b/src/Components/Profile/Templates/OnepagerView.tsx index 10e49a0..32a786e 100644 --- a/src/Components/Profile/Templates/OnepagerView.tsx +++ b/src/Components/Profile/Templates/OnepagerView.tsx @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/restrict-template-expressions */ import { TextView } from '#components/Map' @@ -14,7 +13,7 @@ export const OnepagerView = ({ item }: { item: Item }) => { item={item} shareBaseUrl={`https://www.wuerdekompass.org/aktivitaeten/gruppensuche/#/gruppe/${item.slug}`} /> - {item.user_created.first_name && } + {item.user_created?.first_name && } {/* Description Section */}
    diff --git a/src/Components/Templates/AttestationForm.tsx b/src/Components/Templates/AttestationForm.tsx index 595280e..1b308b8 100644 --- a/src/Components/Templates/AttestationForm.tsx +++ b/src/Components/Templates/AttestationForm.tsx @@ -2,7 +2,6 @@ /* eslint-disable @typescript-eslint/prefer-optional-chain */ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/require-await */ -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/no-floating-promises */ /* eslint-disable @typescript-eslint/restrict-template-expressions */ /* eslint-disable @typescript-eslint/restrict-plus-operands */ @@ -49,7 +48,7 @@ export const AttestationForm = ({ api }: { api?: ItemsApi }) => { const sendAttestation = async () => { const to: any[] = [] - users?.map((u) => to.push({ directus_users_id: u.user_created.id })) + users?.map((u) => to.push({ directus_users_id: u.user_created?.id })) api?.createItem && toast @@ -76,7 +75,7 @@ export const AttestationForm = ({ api }: { api?: ItemsApi }) => { '/item/' + items.find( (i) => - i.user_created.id === to[0].directus_users_id && + i.user_created?.id === to[0].directus_users_id && i.layer?.itemType.name === 'player', )?.id + '?tab=2', diff --git a/src/Components/Templates/DateUserInfo.tsx b/src/Components/Templates/DateUserInfo.tsx index b7bbd7d..4243a9c 100644 --- a/src/Components/Templates/DateUserInfo.tsx +++ b/src/Components/Templates/DateUserInfo.tsx @@ -1,5 +1,3 @@ -/* eslint-disable @typescript-eslint/no-unsafe-member-access */ -/* eslint-disable @typescript-eslint/restrict-template-expressions */ /* eslint-disable @typescript-eslint/no-non-null-assertion */ /* eslint-disable @typescript-eslint/no-unnecessary-condition */ /* eslint-disable @typescript-eslint/prefer-optional-chain */ diff --git a/src/index.tsx b/src/index.tsx index 6008084..8592a9e 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -41,7 +41,8 @@ export { TextInput, TextAreaInput, SelectBox } from './Components/Input' declare global { interface Window { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - my_modal_3: any + my_modal_3: { + showModal(): void + } } } diff --git a/types/Item.d.ts b/types/Item.d.ts index f35d720..47560e6 100644 --- a/types/Item.d.ts +++ b/types/Item.d.ts @@ -1,6 +1,7 @@ import type { ItemsApi } from './ItemsApi' import type { LayerProps } from './LayerProps' import type { Relation } from './Relation' +import type { UserItem } from './UserItem' import type { Point } from 'geojson' export interface Item { @@ -21,6 +22,8 @@ export interface Item { subname?: string public_edit?: boolean slug?: string + user_created?: UserItem + image?: string // eslint-disable-next-line @typescript-eslint/no-explicit-any [key: string]: any /* constructor( diff --git a/types/UserItem.d.ts b/types/UserItem.d.ts index 77512f2..1d28817 100644 --- a/types/UserItem.d.ts +++ b/types/UserItem.d.ts @@ -7,6 +7,7 @@ export interface UserItem { email?: string password?: string profile?: Profile + first_name?: string // eslint-disable-next-line @typescript-eslint/no-explicit-any [key: string]: any }