5.6. Loadings on each ramp
Every loading already knows its ramp: loading.ramp. Now we need the other direction, the loadings assigned to a particular ramp. Add a getter to Ramp:
src/store/Ramp.ts
import { makeAutoObservable } from "mobx";
import { Loading } from "./Loading";
import { store } from "./Store";
export class Ramp {
// ...
get loadings(): Loading[] {
return store.loadings.filter(l => l.ramp === this);
}
}
loading.ramp points at the very same object that's in store.ramps, so === is all we need. Because it's a getter, MobX recalculates it whenever a loading moves to another ramp.
And we can use this in RampBox instead of the first loading. The store import there isn't needed anymore, so remove it:
src/components/RampBox.tsx
<main>
{ramp.loadings.map(l =>
<LoadingBox key={l.id} loading={l}/>)}
</main>
In the end we can handle the click to open the loading details. Table rows already call openLoadingDialog, so a card opens the same dialog:
src/components/LoadingBox.tsx
import { store } from "../store/Store";
// ...
return <Card className="Loading" elevation={Elevation.TWO} interactive
onClick={() => store.ui.openLoadingDialog(loading)}>
Open 0007703 on ramp C, choose ramp A and close the dialog. The card is now on A, and the table shows A too.
