Skip to content

Commit

Permalink
Sort stations in combo box alphabetically (#139)
Browse files Browse the repository at this point in the history
* feat(global): add toSortedStationsAlphabetically fn;

* chore(global): remove unnecessary parentheses;

* fixed the root station to always appear on top

---------

Co-authored-by: Amar Cerim <[email protected]>
  • Loading branch information
morascode and bambooch authored Oct 25, 2024
1 parent ec9743c commit ce75cb9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 503 deletions.
10 changes: 10 additions & 0 deletions frontend/src/app/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import Station from '@/models/station.model';
import { clsx, type ClassValue } from 'clsx';
import { twMerge } from 'tailwind-merge';

export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}

export function toSortedStationsAlphabetically(stations:Station[]):Station[] {
const rootStationName = 'Zenica "AS"'

return stations.sort((a, b) => {
if (a.name === rootStationName || b.name === rootStationName) return 1;
return a.name.localeCompare(b.name);
});
}
3 changes: 2 additions & 1 deletion frontend/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import RouteSearchResult from "./routes/RouteSearchResult";
import AgencyService from "./services/agency.service";
import RouteService from "./services/route.service";
import StationService from "./services/station.service";
import { toSortedStationsAlphabetically } from "@/lib/utils";

const HomePage: React.FC = () => {
const [routeResults, setRouteResults] = useState<RouteLap[]>([]);
Expand Down Expand Up @@ -83,7 +84,7 @@ const HomePage: React.FC = () => {
const fetchStations = async () => {
try {
const fetchedStations = await StationService.getStations();
setStations(fetchedStations);
setStations(toSortedStationsAlphabetically(fetchedStations));
} catch (error) {
console.error("Error fetching stations:", error);
}
Expand Down
Loading

0 comments on commit ce75cb9

Please sign in to comment.