forked from rajun/ar-test
feat: add customer AR page route
This commit is contained in:
parent
cad384b52c
commit
ccba71b80c
32
app/routes/ar.$id.tsx
Normal file
32
app/routes/ar.$id.tsx
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
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} />;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user