Skip to content

Commit

Permalink
Clean up types for cars by vehicle type
Browse files Browse the repository at this point in the history
  • Loading branch information
ruchernchong committed Nov 22, 2024
1 parent f5a955e commit d5f8386
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
15 changes: 9 additions & 6 deletions config/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Battery, Droplet, Fuel, Zap } from "lucide-react";
import { VEHICLE_TYPE_MAP } from "@/constants";
import { slugify } from "@/utils/slugify";
import type { APP_ENV, LinkItem } from "@/types";
import type { AppEnv, LinkItem, VehicleType } from "@/types";

export const DOMAIN_NAME = "sgcarstrends.com";
const API_VERSION = "v1";
Expand Down Expand Up @@ -84,11 +84,14 @@ export const VEHICLE_TYPE_LINKS: LinkItem[] = [
{ label: "Sports Utility Vehicle" },
{ label: "Coupe/Convertible" },
]
.map((link) => ({
...link,
label: VEHICLE_TYPE_MAP[link.label] || link.label,
href: `/cars/vehicle-types/${slugify(link.label)}`,
}))
.map((link) => {
const label = link.label as VehicleType;
return {
...link,
label: VEHICLE_TYPE_MAP[label] || label,
href: `/cars/vehicle-types/${slugify(link.label)}`,
};
})
.sort((a, b) => a.label.localeCompare(b.label));

export const COE_LINKS: LinkItem[] = [
Expand Down
4 changes: 2 additions & 2 deletions constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { VEHICLE_TYPE } from "@/types";
import type { VehicleType } from "@/types";

export const CARS = {
TABLE: {
Expand All @@ -21,7 +21,7 @@ export const MAKE = {
},
};

export const VEHICLE_TYPE_MAP: Record<string, string> = {
export const VEHICLE_TYPE_MAP: Partial<Record<VehicleType, string>> = {
"Multi-purpose Vehicle": "MPV",
"Multi-purpose Vehicle/Station-wagon": "MPV",
"Sports Utility Vehicle": "SUV",
Expand Down
4 changes: 2 additions & 2 deletions types/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FUEL_TYPE } from "@/config";
import type { LucideIcon } from "lucide-react";

export type VEHICLE_TYPE =
export type VehicleType =
| "Coupe/ Convertible"
| "Hatchback"
| "Multi-purpose Vehicle"
Expand All @@ -16,7 +16,7 @@ export interface Car {
make: string;
importer_type?: string;
fuel_type: FUEL_TYPE;
vehicle_type: VEHICLE_TYPE;
vehicle_type: VehicleType;
number: number;
selected?: boolean;
}
Expand Down

0 comments on commit d5f8386

Please sign in to comment.