chore(ui): simplify clan uri params

Now that everything lives under `/clans/:clanURI` we don't need to handle the case where the param might be null.
This commit is contained in:
Brian McGee
2025-07-22 17:03:33 +01:00
parent 5f290fed7f
commit dd3051d62b
2 changed files with 3 additions and 29 deletions

View File

@@ -28,30 +28,4 @@ export const clanURIParam = (params: Params) => {
return window.atob(params.clanURI);
};
export function useClanURI(opts: { force: true }): string;
export function useClanURI(opts: { force: boolean }): string | null;
export function useClanURI(
opts: { force: boolean } = { force: false },
): string | null {
const maybe = () => {
const params = useParams();
if (!params.clanURI) {
return null;
}
const clanURI = clanURIParam(params);
if (!clanURI) {
throw new Error(
"Could not decode clan URI from params: " + params.clanURI,
);
}
return clanURI;
};
const uri = maybe();
if (!uri && opts.force) {
throw new Error(
"ClanURI is not set. Use this function only within contexts, where clanURI is guaranteed to have been set.",
);
}
return uri;
}
export const useClanURI = () => clanURIParam(useParams());

View File

@@ -90,7 +90,7 @@ const MockCreateMachine = (props: MockProps) => {
};
const ClanSceneController = () => {
const clanURI = useClanURI({ force: true });
const clanURI = useClanURI();
const [dialogHandlers, setDialogHandlers] = createSignal<{
resolve: ({ id }: { id: string }) => void;
@@ -191,7 +191,7 @@ const ClanSceneController = () => {
cubesQuery={query}
onCreate={onCreate}
sceneStore={() => {
const clanURI = useClanURI({ force: true });
const clanURI = useClanURI();
return store.sceneData?.[clanURI];
}}
setMachinePos={(machineId: string, pos: [number, number]) => {