๐Ÿ“ฆ sleepyfran / duets

๐Ÿ“„ CityPrompt.fs ยท 35 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35[<AutoOpen>]
module rec Duets.Cli.Components.CityPrompt

open Duets.Agents
open Duets.Cli.Text
open Duets.Entities
open Duets.Simulation

/// <summary>
/// Shows a prompt to select a city, with the current city at the top and the
/// rest ordered alphabetically.
/// </summary>
/// <param name="prompt">Prompt to show the user</param>
let showCityPrompt prompt =
    let currentCity = Queries.World.currentCity (State.get ())

    showOptionalChoicePrompt
        prompt
        Generic.cancel
        (fun (city: City) ->
            if city.Id = currentCity.Id then
                $"{Generic.cityName city.Id} (Current)" |> Styles.highlight
            else
                Generic.cityName city.Id)
        (sortedCities currentCity)

/// Lists all available cities with the current one at the top.
let private sortedCities currentCity =
    let allButCurrentCity =
        Queries.World.allCities
        |> List.filter (fun city -> city.Id <> currentCity.Id)
        |> List.sortBy (fun city -> Generic.cityName city.Id)

    currentCity :: allButCurrentCity