33 lines
1.3 KiB
TypeScript
33 lines
1.3 KiB
TypeScript
import { useLoaderData } from 'react-router';
|
|
import { Box } from 'lucide-react';
|
|
import type { Route } from './+types/ar.$id';
|
|
import { LoadingScreen } from '~/components/ui/loading-screen';
|
|
import { StatusScreen } from '~/components/ui/status-screen';
|
|
import { ArScene } from '~/components/ar-viewer/ar-scene';
|
|
import { isNotFound } from '~/lib/errors';
|
|
import { getAsset } from '~/services/assets';
|
|
import { getSettings } from '~/services/settings';
|
|
|
|
export async function clientLoader({ params }: Route.ClientLoaderArgs) {
|
|
try {
|
|
const [asset, settings] = await Promise.all([getAsset(params.id), getSettings()]);
|
|
return { asset, settings, error: null };
|
|
} catch (error) {
|
|
return {
|
|
asset: null,
|
|
settings: null,
|
|
error: isNotFound(error) ? 'This model is no longer available.' : 'Could not load this model. Check your connection and try again.',
|
|
};
|
|
}
|
|
}
|
|
|
|
export function HydrateFallback() {
|
|
return <LoadingScreen label='Loading AR experience…' />;
|
|
}
|
|
|
|
export default function ArViewerPage() {
|
|
const { asset, settings, error } = useLoaderData<typeof clientLoader>();
|
|
if (!asset || !settings) return <StatusScreen icon={Box} title='Model not found' message={error ?? undefined} />;
|
|
return <ArScene asset={asset} settings={settings} />;
|
|
}
|