migrate mobile with new endpoints

This commit is contained in:
m
2026-07-28 20:28:32 +02:00
parent d40ca87075
commit 9c699446dc
28 changed files with 799 additions and 444 deletions
+46
View File
@@ -0,0 +1,46 @@
import React, { createContext, useContext, useEffect, useState } from 'react';
import { useDeviceRegistration } from '../hooks/useDeviceRegistration';
import { useAuth } from './AuthContext';
interface DeviceContextType {
isRegistered: boolean | null;
isLoading: boolean;
deviceName: string;
register: (name: string) => Promise<{ id: string; device_name: string; role: string }>;
}
const DeviceContext = createContext<DeviceContextType | undefined>(undefined);
export function DeviceProvider({ children }: { children: React.ReactNode }) {
const { user } = useAuth();
const registration = useDeviceRegistration();
const { isRegistered, isLoading, device, register } = registration;
const value: DeviceContextType = user
? {
isRegistered,
isLoading,
deviceName: device?.name ?? '',
register,
}
: {
isRegistered: null,
isLoading: false,
deviceName: '',
register: async () => { throw new Error('Not authenticated'); },
};
return (
<DeviceContext.Provider value={value}>
{children}
</DeviceContext.Provider>
);
}
export function useDevice() {
const context = useContext(DeviceContext);
if (!context) {
throw new Error('useDevice must be used within a DeviceProvider');
}
return context;
}