53 lines
1.6 KiB
TypeScript
53 lines
1.6 KiB
TypeScript
import { useSuspenseQuery } from '@tanstack/react-query';
|
|
import { Navigate, createFileRoute } from '@tanstack/react-router';
|
|
import { FlaskConical } from 'lucide-react';
|
|
import {
|
|
Empty,
|
|
EmptyDescription,
|
|
EmptyHeader,
|
|
EmptyMedia,
|
|
EmptyTitle,
|
|
} from '@repo/ui/components/empty';
|
|
import { RealmSidebar } from '@/components/realm-sidebar';
|
|
import { can, realmQuery } from '@/lib/realms';
|
|
import { WIDE_SCREEN, useMediaQuery } from '@/lib/use-media-query';
|
|
|
|
export const Route = createFileRoute('/app/r/$realmId/')({
|
|
component: RealmHome,
|
|
});
|
|
|
|
function RealmHome() {
|
|
const { realmId } = Route.useParams();
|
|
const { data: realm } = useSuspenseQuery(realmQuery(realmId));
|
|
const isWide = useMediaQuery(WIDE_SCREEN);
|
|
const first = realm.cauldrons.at(0);
|
|
|
|
// Phones have no column for the realm, so its cauldrons are listed here.
|
|
if (!isWide) return <RealmSidebar realm={realm} className="flex-1" />;
|
|
// Wide screens show that column already: go straight to a cauldron.
|
|
if (first) {
|
|
return (
|
|
<Navigate
|
|
to="/app/r/$realmId/$cauldronId"
|
|
params={{ realmId, cauldronId: first.id }}
|
|
replace
|
|
/>
|
|
);
|
|
}
|
|
return (
|
|
<Empty>
|
|
<EmptyHeader>
|
|
<EmptyMedia variant="icon">
|
|
<FlaskConical aria-hidden="true" />
|
|
</EmptyMedia>
|
|
<EmptyTitle>No cauldrons yet</EmptyTitle>
|
|
<EmptyDescription>
|
|
{can(realm, 'manageCauldrons')
|
|
? 'Add one with the plus next to “Cauldrons”.'
|
|
: 'Someone who looks after this realm has to add one.'}
|
|
</EmptyDescription>
|
|
</EmptyHeader>
|
|
</Empty>
|
|
);
|
|
}
|