Skip to content

Commit

Permalink
make NavBar typesafe
Browse files Browse the repository at this point in the history
removed obsolete eslint disables

fixed a type problem
  • Loading branch information
ulfgebhardt committed Dec 19, 2024
1 parent 0316b24 commit ca8f5ac
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 37 deletions.
29 changes: 9 additions & 20 deletions src/Components/AppShell/NavBar.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
/* 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'
Expand All @@ -31,19 +20,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<any>(null)
const nameRef = useRef<HTMLHeadingElement>(null)
const [nameWidth, setNameWidth] = useState<number>(0)
const location = useLocation()
const [showNav, setShowNav] = useState<boolean>(false)

useEffect(() => {
showNav && nameRef && setNameWidth(nameRef.current.scrollWidth)
showNav && nameRef.current && setNameWidth(nameRef.current.scrollWidth)
}, [nameRef, appName, showNav])

useEffect(() => {
Expand All @@ -52,8 +41,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'
Expand All @@ -63,7 +52,7 @@ export default function NavBar({ appName, userType }: { appName: string; userTyp
},
error: {
render({ data }) {
return `${data}`
return JSON.stringify(data)
},
},
pending: 'logging out ..',
Expand Down Expand Up @@ -123,7 +112,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 && (
<div className='tw-avatar'>
<div className='tw-w-10 tw-rounded-full'>
<img src={'https://api.utopia-lab.org/assets/' + userProfile.image} />
Expand Down Expand Up @@ -156,7 +145,7 @@ export default function NavBar({ appName, userType }: { appName: string; userTyp
<li>
<a
onClick={() => {
onLogout()
void onLogout()
}}
>
Logout
Expand Down
2 changes: 0 additions & 2 deletions src/Components/Gaming/Modal.tsx
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
1 change: 0 additions & 1 deletion src/Components/Gaming/Quests.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
import { useEffect, useState } from 'react'

import { useAuth } from '#components/Auth'
Expand Down
5 changes: 2 additions & 3 deletions src/Components/Map/Subcomponents/ItemFormPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Profile/ProfileForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function ProfileForm() {
const layer = layers.find((l) => l.itemType.name === appState.userType)
setItem({
id: crypto.randomUUID(),
name: user ? user.first_name : '',
name: user?.first_name ?? '',
text: '',
layer,
new: true,
Expand Down
1 change: 0 additions & 1 deletion src/Components/Profile/Subcomponents/ContactInfoView.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
3 changes: 1 addition & 2 deletions src/Components/Profile/Templates/OnepagerView.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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 && <ContactInfoView heading='Du hast Fragen?' item={item} />}
{item.user_created?.first_name && <ContactInfoView heading='Du hast Fragen?' item={item} />}
{/* Description Section */}
<div className='tw-my-10 tw-mt-2 tw-px-6 tw-text-sm '>
<TextView rawText={item.text || 'Keine Beschreibung vorhanden'} />
Expand Down
5 changes: 2 additions & 3 deletions src/Components/Templates/AttestationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -49,7 +48,7 @@ export const AttestationForm = ({ api }: { api?: ItemsApi<any> }) => {

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
Expand All @@ -76,7 +75,7 @@ export const AttestationForm = ({ api }: { api?: ItemsApi<any> }) => {
'/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',
Expand Down
2 changes: 0 additions & 2 deletions src/Components/Templates/DateUserInfo.tsx
Original file line number Diff line number Diff line change
@@ -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 */
Expand Down
5 changes: 3 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
3 changes: 3 additions & 0 deletions types/Item.d.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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(
Expand Down
1 change: 1 addition & 0 deletions types/UserItem.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit ca8f5ac

Please sign in to comment.