Skip to content

Commit

Permalink
refactor: update return types to React.JSX.Element for better type co…
Browse files Browse the repository at this point in the history
…nsistency
  • Loading branch information
Robert27 committed Dec 18, 2024
1 parent 0b2aa37 commit 0176e05
Show file tree
Hide file tree
Showing 136 changed files with 541 additions and 405 deletions.
4 changes: 2 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended-type-checked",
"plugin:@typescript-eslint/stylistic-type-checked",
"plugin:@typescript-eslint/strict",
"plugin:@typescript-eslint/stylistic",
"plugin:react/recommended",
"prettier"
],
Expand Down
11 changes: 9 additions & 2 deletions src/api/anonymous-api.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */

/* eslint-disable @typescript-eslint/no-unsafe-member-access */

/* eslint-disable @typescript-eslint/no-unsafe-return */

/* eslint-disable @typescript-eslint/no-explicit-any */
import { Platform } from 'react-native'

import packageInfo from '../../package.json'
Expand All @@ -14,7 +21,7 @@ export class APIError extends Error {
public data: object

constructor(status: number, data: object) {
super(`${JSON.stringify(data)} (${status})`)
super(`${JSON.stringify(data)} (${status.toString()})`)
this.status = status
this.data = data
}
Expand Down Expand Up @@ -50,7 +57,7 @@ export class AnonymousAPIClient {

try {
return await resp.json()
} catch (e) {
} catch {
throw new Error(`Response is not valid JSON (${await resp.text()})`)
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/api/authenticated-api.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/* eslint-disable @typescript-eslint/no-unsafe-call */

/* eslint-disable @typescript-eslint/no-unsafe-assignment */

/* eslint-disable @typescript-eslint/no-unsafe-member-access */

/* eslint-disable @typescript-eslint/no-unsafe-return */

/* eslint-disable @typescript-eslint/no-explicit-any */

/* eslint-disable @typescript-eslint/no-unsafe-argument */
import {
type Exams,
Expand Down Expand Up @@ -38,6 +48,7 @@ export class AuthenticatedAPIClient extends AnonymousAPIClient {
* @param {object} params Request data
* @returns {object}
*/
// eslint-disable-next-line @typescript-eslint/require-await
async requestAuthenticated(params: object): Promise<any> {
console.debug(params)
return this.sessionHandler(async (session: any) => {
Expand Down
4 changes: 2 additions & 2 deletions src/api/thi-session-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export async function callWithSession<T>(
await saveSecure('session', session)
storage.set('sessionCreated', Date.now().toString())
storage.set('isStudent', isStudent.toString())
} catch (e) {
} catch {
throw new NoSessionError()
}
}
Expand All @@ -145,7 +145,7 @@ export async function callWithSession<T>(
await saveSecure('session', session)
storage.set('sessionCreated', Date.now().toString())
storage.set('isStudent', isStudent.toString())
} catch (e) {
} catch {
throw new NoSessionError()
}
return await method(session)
Expand Down
8 changes: 4 additions & 4 deletions src/app/(flow)/onboarding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import Animated, {
import { useSafeAreaInsets } from 'react-native-safe-area-context'
import { createStyleSheet, useStyles } from 'react-native-unistyles'

export default function OnboardingScreen(): JSX.Element {
export default function OnboardingScreen(): React.JSX.Element {
const { t, i18n } = useTranslation('flow')
const setOnboarded = useFlowStore((state) => state.setOnboarded)
const toggleUpdated = useFlowStore((state) => state.toggleUpdated)
Expand Down Expand Up @@ -73,7 +73,7 @@ export default function OnboardingScreen(): JSX.Element {
},
]

const ContinueButton = (): JSX.Element => {
const ContinueButton = (): React.JSX.Element => {
const { styles } = useStyles(stylesheet)
return (
<Pressable
Expand Down Expand Up @@ -111,7 +111,7 @@ export default function OnboardingScreen(): JSX.Element {
const [isWhobbleDisabled, setWhobbleDisabled] = useState(true)
const window = Dimensions.get('window')

const CardsElement = (): JSX.Element => {
const CardsElement = (): React.JSX.Element => {
const { styles } = useStyles(stylesheet)
return (
<Animated.View style={[styles.boxesContainer, styles.boxes]}>
Expand Down Expand Up @@ -183,7 +183,7 @@ export default function OnboardingScreen(): JSX.Element {
)
}

const LegalArea = (): JSX.Element => {
const LegalArea = (): React.JSX.Element => {
const legalAnimatedStyle = useAnimatedStyle(() => ({
opacity: legalOpacity.value,
transform: [{ translateY: legalTranslateY.value }],
Expand Down
2 changes: 1 addition & 1 deletion src/app/(flow)/whatsnew.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Animated, {
} from 'react-native-reanimated'
import { createStyleSheet, useStyles } from 'react-native-unistyles'

export default function WhatsNewScreen(): JSX.Element {
export default function WhatsNewScreen(): React.JSX.Element {
const { styles } = useStyles(stylesheet)
const changelog: Changelog = changelogData as Changelog
const { t, i18n } = useTranslation('flow')
Expand Down
21 changes: 9 additions & 12 deletions src/app/(screens)/about.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
} from 'react-native'
import { createStyleSheet, useStyles } from 'react-native-unistyles'

export default function About(): JSX.Element {
export default function About(): React.JSX.Element {
const router = useRouter()
const { styles } = useStyles(stylesheet)
const { t } = useTranslation(['settings'])
Expand Down Expand Up @@ -97,17 +97,17 @@ export default function About(): JSX.Element {
web: 'Mail',
},
onPress: async () =>
await Linking.openURL(
(await Linking.openURL(
'mailto:[email protected]?subject=Feedback%20Neuland-Next'
),
)) as Promise<void>,
},
{
title: 'App Website',
icon: linkIcon,
onPress: async () =>
await Linking.openURL(
(await Linking.openURL(
`https://next.neuland.app/${i18n.language === 'en' ? 'en/' : ''}`
),
)) as Promise<void>,
},
{
title:
Expand Down Expand Up @@ -173,7 +173,7 @@ export default function About(): JSX.Element {
preset: 'done',
})
}
const isCollected = unlockedAppIcons?.includes('cat')
const isCollected = unlockedAppIcons.includes('cat')
if (!isCollected) {
trackEvent('EasterEgg', { easterEgg: 'aboutLogo' })
if (Platform.OS === 'ios') addUnlockedAppIcon('cat')
Expand All @@ -184,19 +184,15 @@ export default function About(): JSX.Element {
}
const [pressCount, setPressCount] = useState(0)
const handleWebsitePress = (): void => {
Linking.openURL('https://neuland-ingolstadt.de/').catch((err) => {
console.error('Failed to open URL:', err)
})
void Linking.openURL('https://neuland-ingolstadt.de/')
}

const handleContributorsPress = (): void => {
const url =
'https://next.neuland.app/' +
(i18n.language === 'en' ? 'en/' : '') +
'about/contributors'
Linking.openURL(url).catch((err) => {
console.error('Failed to open URL:', err)
})
void Linking.openURL(url)
}
return (
<>
Expand All @@ -215,6 +211,7 @@ export default function About(): JSX.Element {
>
<View style={styles.logoIcon}>
<Image
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-require-imports
source={require('@/assets/appIcons/default.png')}
alt="Neuland Next Logo"
style={styles.logoImage}
Expand Down
8 changes: 5 additions & 3 deletions src/app/(screens)/accent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
useStyles,
} from 'react-native-unistyles'

export default function Theme(): JSX.Element {
export default function Theme(): React.JSX.Element {
const { styles } = useStyles(stylesheet)

const accentColor = usePreferencesStore((state) => state.accentColor)
Expand All @@ -31,7 +31,7 @@ export default function Theme(): JSX.Element {
}: {
color: ColorBoxColor
code: string
}): JSX.Element => {
}): React.JSX.Element => {
const { styles } = useStyles(stylesheet)
const themeAccentColor =
UnistylesRuntime.themeName === 'dark' ? color.dark : color.light
Expand Down Expand Up @@ -99,7 +99,9 @@ export default function Theme(): JSX.Element {
}[]
}

const ColorBoxMatrix = ({ colors }: ColorBoxMatrixProps): JSX.Element => {
const ColorBoxMatrix = ({
colors,
}: ColorBoxMatrixProps): React.JSX.Element => {
const { styles } = useStyles(stylesheet)
return (
<View style={styles.colorMatrixContainer}>
Expand Down
7 changes: 5 additions & 2 deletions src/app/(screens)/appIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */

/* eslint-disable @typescript-eslint/no-require-imports */
import ErrorView from '@/components/Error/ErrorView'
import Divider from '@/components/Universal/Divider'
import PlatformIcon from '@/components/Universal/Icon'
Expand Down Expand Up @@ -35,7 +38,7 @@ iconImages = {

export const appIcons = Object.keys(iconImages)

export default function AppIconPicker(): JSX.Element {
export default function AppIconPicker(): React.JSX.Element {
const { styles } = useStyles(stylesheet)
const unlockedAppIcons = usePreferencesStore(
(state) => state.unlockedAppIcons
Expand All @@ -48,7 +51,7 @@ export default function AppIconPicker(): JSX.Element {
}

categories.exclusive = categories.exclusive.filter((icon) => {
if (unlockedAppIcons?.includes(icon)) {
if (unlockedAppIcons.includes(icon)) {
return true
} else {
return false
Expand Down
4 changes: 2 additions & 2 deletions src/app/(screens)/calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
} from 'react-native'
import { createStyleSheet, useStyles } from 'react-native-unistyles'

export default function CalendarPage(): JSX.Element {
export default function CalendarPage(): React.JSX.Element {
const { userKind = USER_GUEST } = React.useContext(UserKindContext)
const { styles } = useStyles(stylesheet)
const { t } = useTranslation('common')
Expand Down Expand Up @@ -73,7 +73,7 @@ export default function CalendarPage(): JSX.Element {
const scrollY = new Animated.Value(0)
const pages = ['events', 'exams']

const CalendarFooter = (): JSX.Element => {
const CalendarFooter = (): React.JSX.Element => {
return (
<View style={styles.footerContainer}>
<Text style={styles.footerText1}>
Expand Down
2 changes: 1 addition & 1 deletion src/app/(screens)/changelog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useTranslation } from 'react-i18next'
import { Linking, ScrollView, Text, View } from 'react-native'
import { createStyleSheet, useStyles } from 'react-native-unistyles'

export default function Theme(): JSX.Element {
export default function Theme(): React.JSX.Element {
const { styles } = useStyles(stylesheet)
const changelog = changelogData as Changelog
const { t, i18n } = useTranslation(['settings'])
Expand Down
35 changes: 19 additions & 16 deletions src/app/(screens)/clEvent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { linkIcon } from '@/components/Universal/Icon'
import ShareHeaderButton from '@/components/Universal/ShareHeaderButton'
import useCLParamsStore from '@/hooks/useCLParamsStore'
import { type LanguageKey } from '@/localization/i18n'
import { type FormListSections } from '@/types/components'
import { type FormListSections, SectionGroup } from '@/types/components'
import {
formatFriendlyDateTime,
formatFriendlyDateTimeRange,
Expand All @@ -15,15 +15,15 @@ import { useTranslation } from 'react-i18next'
import { Linking, ScrollView, Share, Text, View } from 'react-native'
import { createStyleSheet, useStyles } from 'react-native-unistyles'

export default function ClEventDetail(): JSX.Element {
export default function ClEventDetail(): React.JSX.Element {
const { styles } = useStyles(stylesheet)
const navigation = useNavigation()
const clEvent = useCLParamsStore((state) => state.selectedClEvent)

const { t, i18n } = useTranslation('common')
const isMultiDayEvent =
clEvent?.startDateTime != null &&
clEvent?.endDateTime != null &&
clEvent.endDateTime != null &&
new Date(clEvent.startDateTime).toDateString() !==
new Date(clEvent.endDateTime).toDateString()

Expand Down Expand Up @@ -71,32 +71,35 @@ export default function ClEventDetail(): JSX.Element {
},
]
: [
...(clEvent?.startDateTime != null
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
...(clEvent.startDateTime != null
? [
{
title: t('pages.event.begin'),
value: formatFriendlyDateTime(
new Date(clEvent.startDateTime)
),
value:
formatFriendlyDateTime(
new Date(clEvent.startDateTime)
) ?? undefined,
},
]
: []),
...(clEvent?.endDateTime != null
...(clEvent.endDateTime != null
? [
{
title: t('pages.event.end'),
value: formatFriendlyDateTime(
new Date(clEvent.endDateTime)
),
value:
formatFriendlyDateTime(
new Date(clEvent.endDateTime)
) ?? undefined,
},
]
: []),
]),
...(clEvent?.location != null && clEvent?.location !== ''
...(clEvent?.location != null && clEvent.location !== ''
? [
{
title: t('pages.event.location'),
value: clEvent?.location,
value: clEvent.location,
},
]
: []),
Expand Down Expand Up @@ -139,15 +142,15 @@ export default function ClEventDetail(): JSX.Element {
},
}
: null,
].filter((item) => item != null) as any,
].filter((item) => item != null) as SectionGroup[],
},
]
: []),
...(clEvent?.descriptions != null
? [
{
header: t('pages.event.description'),
item: clEvent?.descriptions[i18n.language as LanguageKey],
item: clEvent.descriptions[i18n.language as LanguageKey],
},
]
: []),
Expand All @@ -168,7 +171,7 @@ export default function ClEventDetail(): JSX.Element {
adjustsFontSizeToFit={true}
numberOfLines={2}
>
{clEvent?.titles[i18n.language as LanguageKey]}
{clEvent.titles[i18n.language as LanguageKey]}
</Text>
</View>
<View style={styles.formList}>
Expand Down
2 changes: 1 addition & 1 deletion src/app/(screens)/clEvents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { useTranslation } from 'react-i18next'
import { Animated, View, useWindowDimensions } from 'react-native'
import { createStyleSheet, useStyles } from 'react-native-unistyles'

export default function Events(): JSX.Element {
export default function Events(): React.JSX.Element {
const { t } = useTranslation('common')
const { styles } = useStyles(stylesheet)
const results = useQueries({
Expand Down
Loading

0 comments on commit 0176e05

Please sign in to comment.