Skip to content

Commit

Permalink
Merge pull request #37 from krystxf/feat/ios-app
Browse files Browse the repository at this point in the history
feat: ios app
  • Loading branch information
krystxf authored Nov 12, 2024
2 parents 004bb02 + d69afb0 commit b272ece
Show file tree
Hide file tree
Showing 29 changed files with 1,024 additions and 192 deletions.
1 change: 0 additions & 1 deletion apps/backend/src/config/cache-module.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ export const cacheModuleConfig: CacheModuleAsyncOptions = {
port: parseInt(process.env.REDIS_PORT || "6379"),
},
}),
max: 1_000,
}),
};
2 changes: 1 addition & 1 deletion apps/backend/src/modules/departure/departure.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { toArray } from "src/utils/array.utils";
@ApiTags("departure")
@Controller("departure")
@UseInterceptors(CacheInterceptor, LogInterceptor)
@CacheTTL(2_000)
@CacheTTL(4 * 1000)
export class DepartureController {
constructor(private readonly departureService: DepartureService) {}

Expand Down
56 changes: 56 additions & 0 deletions apps/mobile/metro-now/common/components/route-name.view.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// metro-now
// https://github.com/krystxf/metro-now

import SwiftUI

struct RouteNameIconView: View {
let label: String
let background: Color

var body: some View {
Text(label.uppercased())
.font(.system(size: 12, weight: .bold))
.foregroundStyle(.white)
.fixedSize(horizontal: true, vertical: true)
.frame(width: 26, height: 26)
.background(Rectangle().fill(background))
.clipShape(.rect(cornerRadius: 6))
}
}

#Preview {
RouteNameIconView(
label: "a",
background: .green
)

RouteNameIconView(
label: "b",
background: .yellow
)

RouteNameIconView(
label: "c",
background: .red
)

RouteNameIconView(
label: "28",
background: .purple
)

RouteNameIconView(
label: "99",
background: .black
)

RouteNameIconView(
label: "149",
background: .blue
)

RouteNameIconView(
label: "912",
background: .black
)
}
1 change: 1 addition & 0 deletions apps/mobile/metro-now/common/const/api-const.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
// https://github.com/krystxf/metro-now

let ENDPOINT: String = "https://api.metronow.dev"
// let ENDPOINT: String = "http://localhost:3001"
45 changes: 44 additions & 1 deletion apps/mobile/metro-now/common/managers/network-manager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import Foundation

final class NetworkManager {
static let shared = NetworkManager()
static let shared = NetworkManager(
)

private init() {}

Expand Down Expand Up @@ -50,6 +51,48 @@ final class NetworkManager {
task.resume()
}

func getAllStops(
completed: @escaping (Result<[ApiStop], FetchErrorNew>) -> Void
) {
guard let url = URL(string: "\(ENDPOINT)/stop/all") else {
completed(.failure(.invalidUrl))
return
}

let task = URLSession.shared.dataTask(
with: URLRequest(url: url)
) {
data, response, error in

if let _ = error {
completed(.failure(.general))
return
}

guard let response = response as? HTTPURLResponse, response.statusCode == 200 else {
completed(.failure(.invalidResponse))
return
}

guard let data else {
completed(.failure(.invalidData))
return
}

do {
let decoder = JSONDecoder()
let decodedResponse = try decoder.decode([ApiStop].self, from: data)
completed(.success(decodedResponse))
return
} catch {
completed(.failure(.invalidData))
return
}
}

task.resume()
}

func getDepartures(
stopIds: [String], platformIds: [String], completed: @escaping (Result<[ApiDeparture], FetchErrorNew>) -> Void
) {
Expand Down
64 changes: 64 additions & 0 deletions apps/mobile/metro-now/common/utils/get-color-by-route-name.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// metro-now
// https://github.com/krystxf/metro-now

import SwiftUI

private let FALLBACK_COLOR: Color = .black

func getColorByRouteName(_ metroLine: MetroLine?) -> Color {
switch metroLine {
case .A:
.green
case .B:
.yellow
case .C:
.red
default: FALLBACK_COLOR
}
}

func getColorByRouteName(_ routeNumber: Int?) -> Color {
guard let routeNumber else {
return FALLBACK_COLOR
}

// tram
if routeNumber < 100 {
if routeNumber >= 90 {
return .black
}

return .purple
}

// bus
if routeNumber >= 900 {
return .black
}

return .blue
}

func getColorByRouteName(_ routeName: String?) -> Color {
guard let routeName else {
return FALLBACK_COLOR
}

if let routeNumber = Int(routeName) {
return getColorByRouteName(routeNumber)
} else if let metroLine = MetroLine(rawValue: routeName) {
return getColorByRouteName(metroLine)
}

// ferry
if routeName.hasPrefix("P") {
return Color.blue
}

// funicular
if routeName.hasPrefix("LD") {
return Color.blue
}

return FALLBACK_COLOR
}
13 changes: 0 additions & 13 deletions apps/mobile/metro-now/common/utils/metro-line.utils.swift

This file was deleted.

10 changes: 4 additions & 6 deletions apps/mobile/metro-now/metro-now Watch App/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ struct ContentView: View {

var body: some View {
VStack {
if
let location = locationManager.location,
let stops,
let closestStop = findClosestStop(to: location, stops: stops)
if let location = locationManager.location,
let stops,
let closestStop = findClosestStop(to: location, stops: stops)
{
MainPage(
StopDeparturesView(
title: closestStop.name,
platforms: closestStop.platforms.map {
platform in
Expand All @@ -31,7 +30,6 @@ struct ContentView: View {
)
}
)

} else {
ProgressView()
}
Expand Down

This file was deleted.

78 changes: 0 additions & 78 deletions apps/mobile/metro-now/metro-now Watch App/pages/main-page.swift

This file was deleted.

Loading

1 comment on commit b272ece

@vercel
Copy link

@vercel vercel bot commented on b272ece Nov 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please # to comment.