Skip to content

Commit

Permalink
client: fixed eslint and typescript errors
Browse files Browse the repository at this point in the history
  • Loading branch information
GGORG0 committed Feb 5, 2025
1 parent 2aaa3f2 commit d80c1a9
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 40 deletions.
7 changes: 2 additions & 5 deletions mapkom_client/app/(tabs)/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ import * as MapLibreNative from '@maplibre/maplibre-react-native';
import { CameraRef } from '@maplibre/maplibre-react-native';
import { Platform, StyleSheet } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { useCallback, useMemo, useRef, useState } from 'react';
import { useMemo, useRef, useState } from 'react';
import { useForegroundPermissions } from 'expo-location';
import MapFabStack from '@/lib/components/MapFabStack';
import React from 'react';
import { useSocketIoListener } from '@/lib/providers/SocketIoProvider';
import { feature, featureCollection } from '@turf/helpers';
import iconTramPointer from '@/assets/images/iconTramPointer.png';
import iconTramSmall from '@/assets/images/iconTramSmall.png';
import iconBusPointer from '@/assets/images/iconBusPointer.png';
import iconBusSmall from '@/assets/images/iconBusSmall.png';
import { VehicleLocation } from '@/lib/vehicle';
import { SheetManager } from 'react-native-actions-sheet';
import { useMapStyleString } from '@/lib/hooks/useMapStyle';
import useLocationMarkers from '@/lib/hooks/useLocationMarkers';
Expand All @@ -39,7 +36,7 @@ export default function Index() {
const markers = useLocationMarkers();
const [selectedMarker, setSelectedMarker] = useState<string | null>(null);
const mapFilters = useMemo(
() => getMapFilters(selectedMarker),
() => getMapFilters<'native'>(selectedMarker),
[selectedMarker],
);

Expand Down
17 changes: 6 additions & 11 deletions mapkom_client/app/(tabs)/index.web.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import { styles } from '@/lib/styles';
import { FAB, Surface } from 'react-native-paper';
import { Surface } from 'react-native-paper';
import * as MapLibreWeb from '@vis.gl/react-maplibre';
import { ImageSourcePropType, ImageURISource, StyleSheet } from 'react-native';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { useForegroundPermissions } from 'expo-location';
import MapFabStack from '@/lib/components/MapFabStack';
import { ImageURISource, StyleSheet } from 'react-native';
import { useEffect, useMemo, useState } from 'react';
import React from 'react';
import { useSocketIoListener } from '@/lib/providers/SocketIoProvider';
import { feature, featureCollection } from '@turf/helpers';
import iconTramPointer from '@/assets/images/iconTramPointer.png';
import iconTramSmall from '@/assets/images/iconTramSmall.png';
import iconBusPointer from '@/assets/images/iconBusPointer.png';
import iconBusSmall from '@/assets/images/iconBusSmall.png';
import { VehicleLocation } from '@/lib/vehicle';
import { SheetManager } from 'react-native-actions-sheet';
import useMapStyle from '@/lib/hooks/useMapStyle';
import 'maplibre-gl/dist/maplibre-gl.css';
Expand All @@ -26,7 +21,7 @@ export default function IndexWeb() {
const markers = useLocationMarkers();
const [selectedMarker, setSelectedMarker] = useState<string | null>(null);
const mapFilters = useMemo(
() => getMapFilters(selectedMarker),
() => getMapFilters<'web'>(selectedMarker),
[selectedMarker],
);

Expand All @@ -37,7 +32,7 @@ export default function IndexWeb() {
return (
<Surface style={styles.screen}>
<MapLibreWeb.Map
mapStyle={mapStyle as MapLibreWeb.MapStyle}
mapStyle={mapStyle as MapLibreWeb.StyleSpecification}
style={localStyles.map}
maxPitch={0}
attributionControl={false}>
Expand Down Expand Up @@ -175,7 +170,7 @@ function ClickHandler({ setSelectedMarker }: ClickHandlerProps) {
});
});
});
}, [map]);
}, [map, setSelectedMarker]);

return null;
}
Expand Down
20 changes: 11 additions & 9 deletions mapkom_client/lib/Icon.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import GlyphMap from '@expo/vector-icons/build/vendor/react-native-vector-icons/
import { ImageSourcePropType, View } from 'react-native';
import type { Props as OriginalIconProps } from 'react-native-paper/src/components/Icon';
import type { Props as OriginalButtonProps } from 'react-native-paper/src/components/Button/Button';
import { ForwardedRef } from 'react';
import type { ForwardRefComponent } from 'react-native-paper/src/utils/forwardRef';

export type MaterialCommunityIcon = keyof typeof GlyphMap;
export default MaterialCommunityIcon;
Expand Down Expand Up @@ -41,10 +41,12 @@ declare module 'react-native-paper/src/components/Icon' {
declare module 'react-native-paper/src/components/Button' {
export type Props = ReplaceProps<OriginalButtonProps, 'icon'>;

export default function Button(
props: ReplaceProps<OriginalButtonProps, 'icon'>,
ref: ForwardedRef<View>,
): React.ReactNode;
export type Button = ForwardRefComponent<
View,
ReplaceProps<OriginalButtonProps, 'icon'>
>;

export default Button;
}

declare module 'react-native-paper' {
Expand All @@ -54,8 +56,8 @@ declare module 'react-native-paper' {
export function Icon(
props: ReplaceProps<OriginalIconProps, 'source'>,
): React.ReactNode;
export function Button(
props: ReplaceProps<OriginalButtonProps, 'icon'>,
ref: ForwardedRef<View>,
): React.ReactNode;
export type Button = ForwardRefComponent<
View,
ReplaceProps<OriginalButtonProps, 'icon'>
>;
}
6 changes: 3 additions & 3 deletions mapkom_client/lib/i18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import translationPl from './pl.json';

const resources = {
en: { translation: translationEn },
"en-US": { translation: translationEn },
"en-GB": { translation: translationEn },
'en-US': { translation: translationEn },
'en-GB': { translation: translationEn },
pl: { translation: translationPl },
"pl-PL": { translation: translationPl },
'pl-PL': { translation: translationPl },
};

export default resources;
16 changes: 8 additions & 8 deletions mapkom_client/lib/mapFilters.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { useEffect, useState } from 'react';
import type { FilterExpression as NativeExpression } from '@maplibre/maplibre-react-native/src/types/MapLibreRNStyles';
import type { ExpressionSpecification as WebExpression } from 'maplibre-gl';
import type { Platform, PlatformWebStatic } from 'react-native';

type MapFilter = Platform extends PlatformWebStatic
type Platform = 'web' | 'native';

type MapFilter<P extends Platform> = P extends 'web'
? WebExpression
: NativeExpression;

type MapFilters = {
BUS: MapFilter;
TRAM: MapFilter;
type MapFilters<P extends Platform> = {
BUS: MapFilter<P>;
TRAM: MapFilter<P>;
};

type VehicleTypeFilter = ['==', ['literal', string], ['get', 'vehicleType']];
Expand All @@ -30,9 +30,9 @@ function combineFilters(
return ['all', typeFilter, selectedFilter];
}

export default function getMapFilters(
export default function getMapFilters<P extends Platform>(
selectedMarker: string | null,
): MapFilters {
): MapFilters<P> {
if (selectedMarker) {
return {
BUS: combineFilters(
Expand Down
6 changes: 4 additions & 2 deletions mapkom_client/lib/providers/BackendUrlProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ export function BackendUrlProvider({ children }: BackendUrlProviderProps) {
const scriptURL = NativeModules?.SourceCode?.scriptURL;
if (!scriptURL) return process.env.EXPO_PUBLIC_API_URL;
const url = new URL(scriptURL);
if (url.hostname.endsWith("exp.direct")) return process.env.EXPO_PUBLIC_API_URL;
if (url.hostname.endsWith('exp.direct'))
return process.env.EXPO_PUBLIC_API_URL;
return `${url.protocol}//${url.hostname}:8080`;
}) as () => string
)()
: process.env.EXPO_PUBLIC_API_URL) || 'https://mapkom-api.ggorg.xyz',
: process.env.EXPO_PUBLIC_API_URL) ||
'https://mapkom-api.ggorg.xyz',
);

// TODO: handle more than 1 city + remember the last city + detect city by location + add city selection menu
Expand Down
3 changes: 1 addition & 2 deletions mapkom_client/lib/sheets/VehicleSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
} from 'react-native-actions-sheet';
import React, {
Dispatch,
RefObject,
SetStateAction,
useCallback,
useEffect,
Expand Down Expand Up @@ -111,7 +110,7 @@ function VehicleDetailsSheetRoute() {
destroy();
}
};
}, [parentParams, vehicle]);
}, [parentParams, prevPos, vehicle]);

const listener = useCallback(
(_: string, vehicles: VehicleLocation[]) => {
Expand Down

0 comments on commit d80c1a9

Please sign in to comment.