WeightliftingNZ / lifter-api

Access athlete and competition results for weightlifting.
https://lifter.shivan.xyz
MIT License
1 stars 1 forks source link

Refactor: lift tables #36

Closed shivan-s closed 2 years ago

shivan-s commented 2 years ago

Currently lifts tables for the athlete detail view and competition detail view are duplicated and could possibly combine together into a single component (despite having different columns).

In fact, with all lift tables. It might be better to pass an object through than an array of strings (see example below).

Examples: How it is done:

const COLUMNS_TO_SHOW: (keyof CompetitionListObjectProps)[] = [
  "name",
  "date_start",
  "lifts_count",
  "location",
];

How it should be (maybe?):

interface Column {
  id: keyof LiftObjectProps;
  label: string;
  minWidth?: number;
  align?: "right" | "left" | "center";
  format?: (value: number) => string;
  extra?: { [key: string]: string };
}

const columns: Column[] = [
  { id: "lottery_number", label: "Lott." },
  { id: "athlete_name", label: "Name" },
  { id: "athlete_yearborn", label: "Birthyear" },
  { id: "team", label: "Team" },
  { id: "bodyweight", label: "Weight" },
  { id: "snatch_first_weight", label: "1", align: "center" },
  { id: "snatch_second_weight", label: "2", align: "center" },
  { id: "snatch_third_weight", label: "3", align: "center" },
  { id: "cnj_first_weight", label: "1", align: "center" },
  { id: "cnj_second_weight", label: "2", align: "center" },
  { id: "cnj_third_weight", label: "3", align: "center" },
  {
    id: "total_lifted",
    label: "Total",
    align: "center",
    extra: { fontWeight: "bold" },
  },
  { id: "placing", label: "Place", align: "center" },
];