-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving to using useSWR for the ServicesAPI
- Loading branch information
1 parent
b09f185
commit 298161e
Showing
7 changed files
with
98 additions
and
247 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { ServiceContainer, Service } from "@/types/ServiceTypes"; | ||
|
||
export const sortServicesByRoute = ( | ||
service: ServiceContainer | ||
): ServiceContainer => { | ||
const sort = (serviceArray: Service[]) => { | ||
serviceArray.sort((a, b) => { | ||
if (!a.routeShortName || !b.routeShortName) { | ||
return Number.MAX_VALUE; | ||
} | ||
return a.routeShortName.localeCompare(b.routeShortName, undefined, { | ||
numeric: true, | ||
sensitivity: "base", | ||
}); | ||
}); | ||
}; | ||
sort(service.allServices); | ||
sort(service.cancelledServices); | ||
sort(service.earlyServices); | ||
sort(service.lateServices); | ||
sort(service.onTimeServices); | ||
sort(service.unknownServices); | ||
|
||
return service; | ||
}; | ||
|
||
export const sortServicesResponseByStatus = (data: Service[]) => { | ||
const serviceHolder: ServiceContainer = { | ||
cancelledServices: [], | ||
earlyServices: [], | ||
onTimeServices: [], | ||
unknownServices: [], | ||
allServices: [], | ||
lateServices: [], | ||
}; | ||
|
||
for (let i = 0; i < data.length; i += 1) { | ||
const service = data[i]; | ||
service.vehicleId = service.vehicle_id; | ||
if (service.status === "EARLY") { | ||
serviceHolder.earlyServices.push(service); | ||
} else if (service.status === "LATE") { | ||
serviceHolder.lateServices.push(service); | ||
} else if (service.status === "ONTIME") { | ||
serviceHolder.onTimeServices.push(service); | ||
} else if (service.status === "UNKNOWN") { | ||
serviceHolder.unknownServices.push(service); | ||
} else if (service.status === "CANCELLED") { | ||
serviceHolder.cancelledServices.push(service); | ||
} | ||
|
||
if (service.status !== "CANCELLED") { | ||
serviceHolder.allServices.push(service); | ||
} | ||
} | ||
|
||
const sortedServices = sortServicesByRoute(serviceHolder); | ||
return sortedServices; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
298161e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
missinglink – ./
missinglink-grange-pro.vercel.app
missinglink-drab.vercel.app
missinglink-git-main-grange-pro.vercel.app
missinglink.link
www.missinglink.link