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:
@@ -28,30 +28,4 @@ export const clanURIParam = (params: Params) => {
|
|||||||
return window.atob(params.clanURI);
|
return window.atob(params.clanURI);
|
||||||
};
|
};
|
||||||
|
|
||||||
export function useClanURI(opts: { force: true }): string;
|
export const useClanURI = () => clanURIParam(useParams());
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ const MockCreateMachine = (props: MockProps) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const ClanSceneController = () => {
|
const ClanSceneController = () => {
|
||||||
const clanURI = useClanURI({ force: true });
|
const clanURI = useClanURI();
|
||||||
|
|
||||||
const [dialogHandlers, setDialogHandlers] = createSignal<{
|
const [dialogHandlers, setDialogHandlers] = createSignal<{
|
||||||
resolve: ({ id }: { id: string }) => void;
|
resolve: ({ id }: { id: string }) => void;
|
||||||
@@ -191,7 +191,7 @@ const ClanSceneController = () => {
|
|||||||
cubesQuery={query}
|
cubesQuery={query}
|
||||||
onCreate={onCreate}
|
onCreate={onCreate}
|
||||||
sceneStore={() => {
|
sceneStore={() => {
|
||||||
const clanURI = useClanURI({ force: true });
|
const clanURI = useClanURI();
|
||||||
return store.sceneData?.[clanURI];
|
return store.sceneData?.[clanURI];
|
||||||
}}
|
}}
|
||||||
setMachinePos={(machineId: string, pos: [number, number]) => {
|
setMachinePos={(machineId: string, pos: [number, number]) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user