Skip to main content
Frontend tutorial

5.8. Ramp status and quantity in details

When you move a loading in the details dialog, it helps to see which ramps are already busy. The ramp can count its loadings:

src/store/Ramp.ts
export class Ramp {
// ...

get quantity(): number {
return this.loadings.length;
}
}

In Details.tsx, replace the intent of the ramp buttons and add the number:

src/components/Details.tsx
{ramps.map((r) => <Button key={r.id} className="ramp-button" outlined
active={r === loading.ramp} onClick={() => loading.setRamp(r)}
intent={r.isEmpty ? Intent.NONE
: r === loading.ramp ? Intent.PRIMARY : Intent.DANGER}>
{r.description}
<sup>{r.quantity > 0 && r.quantity}</sup>
</Button>)}

Every ramp with loadings shows how many it has. The loading's own ramp is blue, other busy ramps are red, and empty ones stay neutral:

Ramp buttons for loading 0007703: A neutral, B red with 1, C blue with 2, D red with 3, E red with 2, F and G neutral, then the empty-set button.

And that's the job done. All the logic we added lives in the stores: the view in UI, and the loadings, status and quantity in Ramp. The components only show it.

Before you call it finished, run the build. It runs tsc first, so it catches the type errors that the dev server lets through:

pnpm dlx pnpm@8 build

05 / ShippingBoard Lite

localhost:5173/?loading=0007703
The same dialog for 0007703 after the change: B with 1, D with 3 and E with 2 are red, C with 2 is blue, and the empty A, F and G stay neutral.

Now the dialog shows which ramps are busy.