Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mobile/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
EXPO_PUBLIC_API_URL=http://YOUR-COMPUTER-IP:8000
5 changes: 4 additions & 1 deletion mobile/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
"image": "./assets/images/splash-icon.png",
"imageWidth": 76
}
]
],
"expo-secure-store",
"expo-status-bar",
"expo-web-browser"
],
"experiments": {
"typedRoutes": true,
Expand Down
595 changes: 268 additions & 327 deletions mobile/package-lock.json

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@
"version": "1.0.0",
"main": "expo-router/entry",
"dependencies": {
"@expo/ui": "~58.0.27",
"@expo/ui": "~58.0.29",
"@expo/vector-icons": "^15.0.2",
"@react-native-async-storage/async-storage": "2.2.0",
"expo": "~58.0.23",
"expo": "~58.0.26",
"expo-constants": "~58.0.15",
"expo-device": "~58.0.5",
"expo-font": "~58.0.11",
"expo-glass-effect": "~58.0.5",
"expo-image": "~58.0.18",
"expo-linking": "~58.0.16",
"expo-router": "~58.0.30",
"expo-splash-screen": "~58.0.13",
"expo-status-bar": "~58.0.4",
"expo-symbols": "~58.0.4",
"expo-linking": "~58.0.17",
"expo-router": "~58.0.32",
"expo-secure-store": "~58.0.3",
"expo-splash-screen": "~58.0.14",
"expo-status-bar": "~58.0.5",
"expo-symbols": "~58.0.5",
"expo-system-ui": "~58.0.7",
"expo-web-browser": "~58.0.7",
"expo-web-browser": "~58.1.0",
"react": "19.3.0",
"react-dom": "19.3.0",
"react-native": "0.88.1",
Expand Down
32 changes: 32 additions & 0 deletions mobile/src/api/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { apiRequest } from './client';

export type User = {
id: number;
name: string;
email: string;
};

type LoginResponse = {
access_token: string;
token_type: string;
};

export function register(name: string, email: string, password: string): Promise<User> {
return apiRequest<User>('/register', {
method: 'POST',
body: { name, email, password },
});
}

export async function login(email: string, password: string): Promise<string> {
const data = await apiRequest<LoginResponse>('/login', {
method: 'POST',
body: { email, password },
});

return data.access_token;
}

export function getMe(token: string): Promise<User> {
return apiRequest<User>('/me', { token });
}
71 changes: 71 additions & 0 deletions mobile/src/api/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { API_URL } from './config';
const REQUEST_TIMEOUT_MS = 10000;

type RequestOptions = {
method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
body?: unknown;
token?: string | null;
};

export class ApiError extends Error {
status: number;

constructor(status: number, message: string) {
super(message);
this.status = status;
}
}

function getErrorMessage(data: unknown, status: number): string {
if (data && typeof data === 'object' && 'detail' in data) {
const detail = (data as { detail: unknown }).detail;

if (typeof detail === 'string') {
return detail;
}

if (Array.isArray(detail) && detail.length > 0) {
const first = detail[0] as { msg?: string };
if (first.msg) {
return first.msg;
}
}
}
return `Request failed with status ${status}`;
}

export async function apiRequest<T>(path: string, options: RequestOptions = {}): Promise<T> {
const headers: Record<string, string> = {
'Content-Type': 'application/json',
};

if (options.token) {
headers.Authorization = `Bearer ${options.token}`;
}

let response: Response;
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);

try {
response = await fetch(`${API_URL}${path}`, {
method: options.method ?? 'GET',
headers,
body: options.body !== undefined ? JSON.stringify(options.body) : undefined,
signal: controller.signal,
});
} catch {
// Network error: no Wi-Fi, wrong IP, backend not running
throw new ApiError(0, 'Server is not reachable. Check your connection');
} finally {
clearTimeout(timeoutId);
}

const data = await response.json().catch(() => null);

if (!response.ok) {
throw new ApiError(response.status, getErrorMessage(data, response.status));
}

return data as T;
}
5 changes: 5 additions & 0 deletions mobile/src/api/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const API_URL = process.env.EXPO_PUBLIC_API_URL;

if (!API_URL) {
throw new Error('EXPO_PUBLIC_API_URL is not set. Create mobile/.env');
}
8 changes: 4 additions & 4 deletions mobile/src/app/(tabs)/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function TabLayout() {
options={{
title: 'Start',
tabBarIcon: ({ color, size }) => (
<Ionicons name="home-outline" size={size} color={color} />
<Ionicons name="home-outline" size={size} color={color as string} />
),
}}
/>
Expand All @@ -27,7 +27,7 @@ export default function TabLayout() {
options={{
title: 'Belege',
tabBarIcon: ({ color, size }) => (
<Ionicons name="document-text-outline" size={size} color={color} />
<Ionicons name="document-text-outline" size={size} color={color as string} />
),
}}
/>
Expand All @@ -54,7 +54,7 @@ export default function TabLayout() {
options={{
title: 'Fristen',
tabBarIcon: ({ color, size }) => (
<Ionicons name="calendar-outline" size={size} color={color} />
<Ionicons name="calendar-outline" size={size} color={color as string} />
),
}}
/>
Expand All @@ -63,7 +63,7 @@ export default function TabLayout() {
options={{
title: 'Profil',
tabBarIcon: ({ color, size }) => (
<Ionicons name="person-outline" size={size} color={color} />
<Ionicons name="person-outline" size={size} color={color as string} />
),
}}
/>
Expand Down
75 changes: 73 additions & 2 deletions mobile/src/app/(tabs)/profile.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,76 @@
import PlaceholderScreen from '@/components/PlaceholderScreen';
import { Pressable, StyleSheet, Text, View } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';

import { useAuth } from '@/context/AuthContext';

export default function Profile() {
return <PlaceholderScreen title="Profil" />;
const { user, signOut } = useAuth();
const insets = useSafeAreaInsets();

return (
<View style={[styles.container, { paddingTop: insets.top + 24 }]}>
<Text style={styles.title}>Profil</Text>

<View style={styles.card}>
<Text style={styles.label}>Name</Text>
<Text style={styles.value}>{user?.name}</Text>

<Text style={styles.label}>E-Mail</Text>
<Text style={styles.value}>{user?.email}</Text>
</View>

<View style={styles.spacer} />

<Pressable style={styles.button} onPress={signOut} accessibilityRole="button">
<Text style={styles.buttonText}>Abmelden</Text>
</Pressable>
</View>
);
}

const styles = StyleSheet.create({
container: {
flex: 1,
paddingHorizontal: 24,
paddingBottom: 24,
backgroundColor: '#FFFFFF',
gap: 28,
},
title: {
fontSize: 28,
lineHeight: 34,
fontWeight: '700',
color: '#18181B',
},
card: {
gap: 4,
padding: 16,
borderWidth: 1.5,
borderColor: '#18181B',
},
label: {
marginTop: 8,
fontSize: 13,
color: '#52525B',
},
value: {
fontSize: 16,
fontWeight: '600',
color: '#18181B',
},
spacer: {
flexGrow: 1,
},
button: {
height: 52,
alignItems: 'center',
justifyContent: 'center',
borderWidth: 1.5,
borderColor: '#18181B',
},
buttonText: {
fontSize: 16,
fontWeight: '600',
color: '#18181B',
},
});
26 changes: 19 additions & 7 deletions mobile/src/app/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,42 @@
import { Stack } from 'expo-router';
import { AuthProvider, useAuth } from '@/context/AuthContext';
import { OnboardingProvider, useOnboarding } from '@/context/onboarding';

function RootNavigator() {
const { accepted, isLoading } = useOnboarding();
const { accepted, isLoading: isOnboardingLoading } = useOnboarding();
const { user, isLoading: isAuthLoading } = useAuth();

if (isLoading) {
if (isOnboardingLoading || isAuthLoading) {
return null;
}

const isLoggedIn = user !== null;

return (
<Stack screenOptions={{ headerShown: false }}>
<Stack.Protected guard={accepted}>
<Stack.Screen name="(tabs)" />
<Stack.Screen name="scan" options={{ presentation: 'modal' }} />
</Stack.Protected>
<Stack.Protected guard={!accepted}>
<Stack.Screen name="onboarding" />
</Stack.Protected>

<Stack.Protected guard={accepted && !isLoggedIn}>
<Stack.Screen name="login" />
<Stack.Screen name="register" />
</Stack.Protected>

<Stack.Protected guard={accepted && isLoggedIn}>
<Stack.Screen name="(tabs)" />
<Stack.Screen name="scan" options={{ presentation: 'modal' }} />
</Stack.Protected>
</Stack>
);
}

export default function RootLayout() {
return (
<OnboardingProvider>
<RootNavigator />
<AuthProvider>
<RootNavigator />
</AuthProvider>
</OnboardingProvider>
);
}
Loading
Loading