Front: Typecheck

This commit is contained in:
Arthur Jamet
2023-09-30 11:05:08 +02:00
parent 1c17ac8b13
commit 76d70f3edd
18 changed files with 110 additions and 105 deletions
+9 -10
View File
@@ -96,7 +96,7 @@ const protectedRoutes = () =>
options: { title: 'Verify email', headerShown: false }, options: { title: 'Verify email', headerShown: false },
link: '/verify', link: '/verify',
}, },
} as const); }) as const;
const publicRoutes = () => const publicRoutes = () =>
({ ({
@@ -135,7 +135,7 @@ const publicRoutes = () =>
options: { title: 'Password reset form', headerShown: false }, options: { title: 'Password reset form', headerShown: false },
link: '/forgot_password', link: '/forgot_password',
}, },
} as const); }) as const;
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
type Route<Props = any> = { type Route<Props = any> = {
@@ -161,14 +161,13 @@ const Stack = createNativeStackNavigator<AppRouteParams & { Loading: never }>();
const RouteToScreen = const RouteToScreen =
<T extends {}>(component: Route<T>['component']) => <T extends {}>(component: Route<T>['component']) =>
// eslint-disable-next-line react/display-name // eslint-disable-next-line react/display-name
(props: NativeStackScreenProps<T & ParamListBase>) => (props: NativeStackScreenProps<T & ParamListBase>) => (
( <>
<> {component({ ...props.route.params, route: props.route } as Parameters<
{component({ ...props.route.params, route: props.route } as Parameters< Route<T>['component']
Route<T>['component'] >[0])}
>[0])} </>
</> );
);
const routesToScreens = (routes: Partial<Record<keyof AppRouteParams, Route>>) => const routesToScreens = (routes: Partial<Record<keyof AppRouteParams, Route>>) =>
Object.entries(routes).map(([name, route], routeIndex) => ( Object.entries(routes).map(([name, route], routeIndex) => (
+2 -4
View File
@@ -11,9 +11,7 @@
"resizeMode": "cover", "resizeMode": "cover",
"backgroundColor": "#ffffff" "backgroundColor": "#ffffff"
}, },
"assetBundlePatterns": [ "assetBundlePatterns": ["**/*"],
"**/*"
],
"ios": { "ios": {
"supportsTablet": true "supportsTablet": true
}, },
@@ -40,4 +38,4 @@
] ]
] ]
} }
} }
+1 -1
View File
@@ -1,4 +1,4 @@
module.exports = function(api) { module.exports = function (api) {
api.cache(true); api.cache(true);
return { return {
presets: ['babel-preset-expo'], presets: ['babel-preset-expo'],
+2 -2
View File
@@ -91,11 +91,11 @@ const BigActionButton = ({
<Box <Box
style={{ style={{
position: 'absolute', position: 'absolute',
left: '0', left: 0,
width: '100%', width: '100%',
height: '100%', height: '100%',
backgroundColor: isDark ? 'black' : 'white', backgroundColor: isDark ? 'black' : 'white',
padding: '10px', padding: 10,
}} }}
> >
<Row> <Row>
+5 -1
View File
@@ -9,6 +9,7 @@ import {
getElementRangeNode, getElementRangeNode,
} from './ElementTypes'; } from './ElementTypes';
import { ArrowDown2 } from 'iconsax-react-native'; import { ArrowDown2 } from 'iconsax-react-native';
import { useWindowDimensions } from 'react-native';
type RawElementProps = { type RawElementProps = {
element: ElementProps; element: ElementProps;
@@ -18,6 +19,7 @@ export const RawElement = ({ element }: RawElementProps) => {
const { title, icon, type, helperText, description, disabled, data } = element; const { title, icon, type, helperText, description, disabled, data } = element;
const screenSize = useBreakpointValue({ base: 'small', md: 'big' }); const screenSize = useBreakpointValue({ base: 'small', md: 'big' });
const isSmallScreen = screenSize === 'small'; const isSmallScreen = screenSize === 'small';
const { width: screenWidth } = useWindowDimensions();
return ( return (
<Column <Column
style={{ style={{
@@ -97,7 +99,9 @@ export const RawElement = ({ element }: RawElementProps) => {
<Popover.Content <Popover.Content
accessibilityLabel={`Additionnal information for ${title}`} accessibilityLabel={`Additionnal information for ${title}`}
style={{ style={{
maxWidth: isSmallScreen ? '90vw' : '20vw', maxWidth: isSmallScreen
? 0.9 * screenWidth
: 0.2 * screenWidth,
}} }}
> >
<Popover.Arrow /> <Popover.Arrow />
+1
View File
@@ -1,3 +1,4 @@
// @ts-expect-error Who does tests anyway?
import { ComponentStory, ComponentMeta } from '@storybook/react'; import { ComponentStory, ComponentMeta } from '@storybook/react';
import Loading from './Loading'; import Loading from './Loading';
-1
View File
@@ -92,7 +92,6 @@ const SongCardInfo = (props: SongCardInfoProps) => {
display: 'flex', display: 'flex',
flexDirection: 'row', flexDirection: 'row',
alignItems: 'center', alignItems: 'center',
// @ts-expect-error gap isn't yet supported by react native
gap: 5, gap: 5,
paddingHorizontal: 10, paddingHorizontal: 10,
}} }}
+2 -2
View File
@@ -96,13 +96,13 @@ const TabNavigation = () => {
setActiveTabID={setActiveTab} setActiveTabID={setActiveTab}
> >
<View <View
// @ts-expect-error Raw CSS
style={{ style={{
width: 'calc(100% - 5)', width: 'calc(100% - 5)',
height: '100%', height: '100%',
backgroundColor: 'rgba(16, 16, 20, 0.50)', backgroundColor: 'rgba(16, 16, 20, 0.50)',
borderRadius: 12, borderRadius: 12,
margin: 5, margin: 5,
// @ts-expect-error backDropFilter isn't yet supported by react native
backDropFilter: 'blur(2px)', backDropFilter: 'blur(2px)',
padding: 15, padding: 15,
}} }}
@@ -119,6 +119,7 @@ const TabNavigation = () => {
setIsCollapsed={setIsDesktopCollapsed} setIsCollapsed={setIsDesktopCollapsed}
> >
<View <View
// @ts-expect-error Raw CSS
style={{ style={{
width: 'calc(100% - 10)', width: 'calc(100% - 10)',
height: '100%', height: '100%',
@@ -126,7 +127,6 @@ const TabNavigation = () => {
borderRadius: 12, borderRadius: 12,
marginVertical: 10, marginVertical: 10,
marginRight: 10, marginRight: 10,
// @ts-expect-error backDropFilter isn't yet supported by react native
backDropFilter: 'blur(2px)', backDropFilter: 'blur(2px)',
padding: 20, padding: 20,
}} }}
+51 -51
View File
@@ -20,57 +20,57 @@ const TabNavigationButton = (props: TabNavigationButtonProps) => {
width: '100%', width: '100%',
}} }}
> >
{({ isPressed, isHovered }) => ( {({ isPressed, isHovered }) => {
<View let boxShadow: string | undefined = undefined;
style={{ if (isHovered) {
display: 'flex', boxShadow = '0px 0px 16px 0px rgba(0, 0, 0, 0.25)';
flexDirection: 'row', } else if (props.isActive) {
alignSelf: 'stretch', boxShadow = '0px 0px 8px 0px rgba(0, 0, 0, 0.25)';
alignItems: 'center', }
justifyContent: 'flex-start', return (
padding: '10px', <View
borderRadius: 8, style={{
flexGrow: 0, display: 'flex',
// @ts-expect-error BoxShadow is not in the types but I want it this may be a legitimate error on my part flexDirection: 'row',
boxShadow: (() => { alignSelf: 'stretch',
if (isHovered) { alignItems: 'center',
return '0px 0px 16px 0px rgba(0, 0, 0, 0.25)'; justifyContent: 'flex-start',
} else if (props.isActive) { padding: 10,
return '0px 0px 8px 0px rgba(0, 0, 0, 0.25)'; borderRadius: 8,
} else { flexGrow: 0,
return undefined; // @ts-expect-error boxShadow isn't yet supported by react native
} boxShadow: boxShadow,
})(), backdropFilter: 'blur(2px)',
backdropFilter: 'blur(2px)', backgroundColor: (() => {
backgroundColor: (() => { if (isPressed) {
if (isPressed) { return 'rgba(0, 0, 0, 0.1)';
return 'rgba(0, 0, 0, 0.1)'; } else if (isHovered) {
} else if (isHovered) { return 'rgba(231, 231, 232, 0.2)';
return 'rgba(231, 231, 232, 0.2)'; } else if (props.isActive) {
} else if (props.isActive) { return 'rgba(16, 16, 20, 0.5)';
return 'rgba(16, 16, 20, 0.5)'; } else {
} else { return 'transparent';
return 'transparent'; }
} })(),
})(), }}
}} >
> {props.icon && (
{props.icon && ( <View
<View style={{
style={{ marginRight: props.isCollapsed ? undefined : 10,
marginRight: props.isCollapsed ? undefined : '10px', }}
}} >
> {props.icon}
{props.icon} </View>
</View> )}
)} {!props.isCollapsed && (
{!props.isCollapsed && ( <Text numberOfLines={1} selectable={false}>
<Text numberOfLines={1} selectable={false}> {props.label}
{props.label} </Text>
</Text> )}
)} </View>
</View> );
)} }}
</Pressable> </Pressable>
); );
}; };
+14 -15
View File
@@ -50,16 +50,16 @@ const TabNavigationDesktop = (props: TabNavigationDesktopProps) => {
alignItems: 'center', alignItems: 'center',
justifyContent: 'flex-start', justifyContent: 'flex-start',
flexShrink: 0, flexShrink: 0,
padding: '10px', padding: 10,
}} }}
> >
<Image <Image
source={{ uri: icon?.at(0)?.uri }} source={{ uri: icon?.at(0)?.uri }}
style={{ style={{
aspectRatio: 1, aspectRatio: 1,
width: '40px', width: 40,
height: 'auto', height: 'auto',
marginRight: '10px', marginRight: 10,
}} }}
/> />
<Text fontSize={'2xl'} selectable={false}> <Text fontSize={'2xl'} selectable={false}>
@@ -70,9 +70,9 @@ const TabNavigationDesktop = (props: TabNavigationDesktopProps) => {
<View <View
style={{ style={{
display: 'flex', display: 'flex',
width: '300px', width: 300,
height: 'auto', height: 'auto',
padding: '32px', padding: 32,
flexDirection: 'column', flexDirection: 'column',
justifyContent: 'space-between', justifyContent: 'space-between',
alignItems: 'flex-start', alignItems: 'flex-start',
@@ -82,8 +82,7 @@ const TabNavigationDesktop = (props: TabNavigationDesktopProps) => {
<TabNavigationList <TabNavigationList
style={{ style={{
flexShrink: 0, flexShrink: 0,
// @ts-expect-error gap is not in the types because we have an old version of react-native gap: 20,
gap: '20px',
}} }}
> >
{buttons.map((button, index) => ( {buttons.map((button, index) => (
@@ -104,8 +103,8 @@ const TabNavigationDesktop = (props: TabNavigationDesktopProps) => {
<Text <Text
bold bold
style={{ style={{
paddingHorizontal: '16px', paddingHorizontal: 16,
paddingVertical: '10px', paddingVertical: 10,
fontSize: 20, fontSize: 20,
}} }}
> >
@@ -114,8 +113,8 @@ const TabNavigationDesktop = (props: TabNavigationDesktopProps) => {
{songHistory.length === 0 && ( {songHistory.length === 0 && (
<Text <Text
style={{ style={{
paddingHorizontal: '16px', paddingHorizontal: 16,
paddingVertical: '10px', paddingVertical: 10,
}} }}
> >
No songs played yet No songs played yet
@@ -133,8 +132,8 @@ const TabNavigationDesktop = (props: TabNavigationDesktopProps) => {
<View <View
key={'tab-navigation-other-' + index} key={'tab-navigation-other-' + index}
style={{ style={{
paddingHorizontal: '16px', paddingHorizontal: 16,
paddingVertical: '10px', paddingVertical: 10,
}} }}
> >
<Text numberOfLines={1}>{histoItem.name}</Text> <Text numberOfLines={1}>{histoItem.name}</Text>
@@ -144,8 +143,7 @@ const TabNavigationDesktop = (props: TabNavigationDesktopProps) => {
<Divider /> <Divider />
<TabNavigationList <TabNavigationList
style={{ style={{
// @ts-expect-error gap is not in the types because we have an old version of react-native gap: 20,
gap: '20px',
}} }}
> >
{([props.tabs.find((t) => t.id === 'settings')] as NaviTab[]).map( {([props.tabs.find((t) => t.id === 'settings')] as NaviTab[]).map(
@@ -166,6 +164,7 @@ const TabNavigationDesktop = (props: TabNavigationDesktopProps) => {
</View> </View>
</View> </View>
<ScrollView <ScrollView
// @ts-expect-error Raw CSS
style={{ style={{
height: '100%', height: '100%',
width: 'calc(100% - 300px)', width: 'calc(100% - 300px)',
+1 -2
View File
@@ -15,8 +15,7 @@ const TabNavigationList = (props: TabNavigationListProps) => {
alignItems: 'flex-start', alignItems: 'flex-start',
alignSelf: 'stretch', alignSelf: 'stretch',
flexDirection: 'column', flexDirection: 'column',
// @ts-expect-error gap is not in the types because we have an old version of react-native gap: 8,
gap: '8px',
}, },
props.style, props.style,
]} ]}
+4 -3
View File
@@ -22,8 +22,8 @@ const TabNavigationPhone = (props: TabNavigationPhoneProps) => {
> >
<View <View
style={{ style={{
padding: '16px', padding: 16,
height: '90px', height: 90,
width: '100%', width: '100%',
}} }}
> >
@@ -31,7 +31,7 @@ const TabNavigationPhone = (props: TabNavigationPhoneProps) => {
<View <View
style={{ style={{
display: 'flex', display: 'flex',
padding: '8px', padding: 8,
justifyContent: 'space-evenly', justifyContent: 'space-evenly',
flexDirection: 'row', flexDirection: 'row',
alignItems: 'center', alignItems: 'center',
@@ -56,6 +56,7 @@ const TabNavigationPhone = (props: TabNavigationPhoneProps) => {
</Center> </Center>
</View> </View>
<ScrollView <ScrollView
// @ts-expect-error Raw CSS
style={{ style={{
width: '100%', width: '100%',
height: 'calc(100% - 90px)', height: 'calc(100% - 90px)',
+3 -1
View File
@@ -79,6 +79,7 @@ const Octave = (props: OctaveProps) => {
bgHovered={isHighlighted ? highlightColor : whiteKeyBgHovered} bgHovered={isHighlighted ? highlightColor : whiteKeyBgHovered}
onKeyDown={() => onNoteDown(key)} onKeyDown={() => onNoteDown(key)}
onKeyUp={() => onNoteUp(key)} onKeyUp={() => onNoteUp(key)}
// @ts-expect-error Raw CSS
style={{ style={{
width: whiteKeyWidthExpr, width: whiteKeyWidthExpr,
height: whiteKeyHeightExpr, height: whiteKeyHeightExpr,
@@ -100,6 +101,7 @@ const Octave = (props: OctaveProps) => {
bgHovered={isHighlighted ? highlightColor : blackKeyBgHovered} bgHovered={isHighlighted ? highlightColor : blackKeyBgHovered}
onKeyDown={() => onNoteDown(key)} onKeyDown={() => onNoteDown(key)}
onKeyUp={() => onNoteUp(key)} onKeyUp={() => onNoteUp(key)}
// @ts-expect-error Raw CSS
style={{ style={{
width: blackKeyWidthExpr, width: blackKeyWidthExpr,
height: blackKeyHeightExpr, height: blackKeyHeightExpr,
@@ -107,7 +109,7 @@ const Octave = (props: OctaveProps) => {
left: `calc(calc(${whiteKeyWidthExpr} * ${ left: `calc(calc(${whiteKeyWidthExpr} * ${
i + ((i > 1) as unknown as number) + 1 i + ((i > 1) as unknown as number) + 1
}) - calc(${blackKeyWidthExpr} / 2))`, }) - calc(${blackKeyWidthExpr} / 2))`,
top: '0px', top: 0,
}} }}
text={{ text={{
color: 'white', color: 'white',
@@ -43,6 +43,7 @@ const VirtualPiano = ({
{octaveList.map((octaveNum) => { {octaveList.map((octaveNum) => {
return ( return (
<Octave <Octave
// @ts-expect-error Raw CSS
style={{ width: octaveWidthExpr, height: '100%' }} style={{ width: octaveWidthExpr, height: '100%' }}
key={octaveNum} key={octaveNum}
number={octaveNum} number={octaveNum}
@@ -103,6 +103,7 @@ function TabNavigator({
{(!isMobileView || isPanelView) && ( {(!isMobileView || isPanelView) && (
<View <View
style={[ style={[
// @ts-expect-error Raw CSS
{ {
display: 'flex', display: 'flex',
flexDirection: 'row', flexDirection: 'row',
@@ -153,8 +154,8 @@ function TabNavigator({
} }
style={{ style={{
justifyContent: 'flex-start', justifyContent: 'flex-start',
padding: '10px', padding: 10,
height: '50px', height: 50,
width: '100%', width: '100%',
}} }}
leftIcon={ leftIcon={
@@ -177,15 +178,13 @@ function TabNavigator({
</View> </View>
)} )}
{(!isMobileView || !isPanelView) && ( {(!isMobileView || !isPanelView) && (
<View <View style={[{ flex: 1, width: isMobileView ? '100%' : 700 }, contentStyle]}>
style={[{ flex: 1, width: isMobileView ? '100%' : '700px' }, contentStyle]}
>
{isMobileView && ( {isMobileView && (
<Button <Button
style={{ style={{
position: 'absolute', position: 'absolute',
top: '10px', top: 10,
left: '10px', left: 10,
zIndex: 100, zIndex: 100,
}} }}
onPress={() => setIsPanelView(true)} onPress={() => setIsPanelView(true)}
+1
View File
@@ -768,6 +768,7 @@ const ProfileView = () => {
</Text> </Text>
<ButtonBase <ButtonBase
title="Modifier profil" title="Modifier profil"
// @ts-expect-error Raw CSS
style={{ width: 'fit-content' }} style={{ width: 'fit-content' }}
type={'filled'} type={'filled'}
onPress={async () => navigation.navigate('Settings')} onPress={async () => navigation.navigate('Settings')}
+6 -3
View File
@@ -91,9 +91,10 @@ const StartPageView = () => {
iconName="user" iconName="user"
iconProvider={FontAwesome5} iconProvider={FontAwesome5}
onPress={() => navigation.navigate('Login')} onPress={() => navigation.navigate('Login')}
// @ts-expect-error Raw CSS
style={{ style={{
width: isSmallScreen ? '90%' : 'clamp(100px, 33.3%, 600px)', width: isSmallScreen ? '90%' : 'clamp(100px, 33.3%, 600px)',
height: '300px', height: 300,
margin: 'clamp(10px, 2%, 50px)', margin: 'clamp(10px, 2%, 50px)',
}} }}
/> />
@@ -116,9 +117,10 @@ const StartPageView = () => {
toast.show({ description: error as string }); toast.show({ description: error as string });
} }
}} }}
// @ts-expect-error Raw CSS
style={{ style={{
width: isSmallScreen ? '90%' : 'clamp(100px, 33.3%, 600px)', width: isSmallScreen ? '90%' : 'clamp(100px, 33.3%, 600px)',
height: '300px', height: 300,
margin: 'clamp(10px, 2%, 50px)', margin: 'clamp(10px, 2%, 50px)',
}} }}
/> />
@@ -131,8 +133,9 @@ const StartPageView = () => {
iconProvider={FontAwesome5} iconProvider={FontAwesome5}
iconName="user-plus" iconName="user-plus"
onPress={() => navigation.navigate('Signup')} onPress={() => navigation.navigate('Signup')}
// @ts-expect-error Raw CSS
style={{ style={{
height: '150px', height: 150,
width: isSmallScreen ? '90%' : 'clamp(150px, 50%, 600px)', width: isSmallScreen ? '90%' : 'clamp(150px, 50%, 600px)',
}} }}
/> />
+1 -2
View File
@@ -88,7 +88,7 @@ const HomeView = () => {
<View <View
style={{ style={{
alignSelf: 'stretch', alignSelf: 'stretch',
maxWidth: '1100px', maxWidth: 1100,
alignItems: 'stretch', alignItems: 'stretch',
flexDirection: isPhone ? 'column' : 'row', flexDirection: isPhone ? 'column' : 'row',
}} }}
@@ -186,7 +186,6 @@ const HomeView = () => {
flexWrap: 'wrap', flexWrap: 'wrap',
justifyContent: 'flex-start', justifyContent: 'flex-start',
alignItems: 'flex-start', alignItems: 'flex-start',
// @ts-expect-error - gap is not in the typings
gap: 16, gap: 16,
}} }}
> >