on master help sign in
Added ship name request
commit6b517b82e125656ab3f7315d4d02174e9cc2df90 authoriko <mail@iko.soy> dateSat 17 Jun 2023, 11:37 (3 years ago) parent4d67b18
2 files changed+28−7
example/src/Main.elm+14−7 src/Ur.elm+14
example/src/Main.elm+14−7
@@ -27,10 +27,12 @@ main =
2727 ( { error = ""
2828 , entries = Nothing
2929 , newEntry = ""
30+ , shipName = Nothing
3031 }
3132 , Cmd.batch
3233 [ Ur.logIn "http://localhost:8080" "lidlut-tabwed-pillex-ridrup"
3334 |> Cmd.map (result (Debug.toString >> Error) (always Noop))
35+ , Ur.getShipName "http://localhost:8080" |> Cmd.map (result (always Noop) GotShipName)
3436 , Ur.Requests.scry
3537 { url = "http://localhost:8080"
3638 , agent = "journal"
@@ -51,18 +53,18 @@ main =
5153 , subscriptions = always Sub.none
5254 , createEventSource = createEventSource
5355 , urbitSubscriptions =
54− \{ entries } ->
55− case entries of
56− Nothing ->
57− Ur.Sub.none
58−
59− Just _ ->
56+ \{ entries, shipName } ->
57+ case ( entries, shipName ) of
58+ ( Just _, Just ship ) ->
6059 Ur.Sub.subscribe
61− { ship = "~zod"
60+ { ship = ship
6261 , app = "journal"
6362 , path = [ "updates" ]
6463 , deconstructor = decodeJournalUpdate |> D.map GotUpdate
6564 }
65+
66+ _ ->
67+ Ur.Sub.none
6668 , onEventSourceMsg = onEventSourceMessage
6769 , onUrlChange = \_ -> Noop
6870 , onUrlRequest = \_ -> Noop
@@ -74,6 +76,7 @@ type alias Model =
7476 { error : String
7577 , entries : Maybe (List ( BigInt, String ))
7678 , newEntry : String
79+ , shipName : Maybe String
7780 }
7881
7982
@@ -86,6 +89,7 @@ type Msg
8689 | DeleteEntry BigInt
8790 | AddEntry String
8891 | RunCmd (Ur.Cmd.Cmd Msg)
92+ | GotShipName String
8993
9094
9195update : Msg -> Model -> ( Model, Ur.Cmd.Cmd Msg )
@@ -158,6 +162,9 @@ update msg model =
158162 RunCmd cmd ->
159163 ( model, cmd )
160164
165+ GotShipName name ->
166+ ( { model | shipName = Just name }, Ur.Cmd.none )
167+
161168
162169type JournalUpdate
163170 = Add BigInt String
src/Ur.elm+14
@@ -5,6 +5,7 @@ module Ur exposing
55 , Noun(..)
66 , Path
77 , cue
8+ , getShipName
89 , jam
910 , logIn
1011 , mat
@@ -53,6 +54,19 @@ logIn root password =
5354 }
5455
5556
57+getShipName : String -> Cmd (Result Http.Error String)
58+getShipName root =
59+ Http.riskyRequest
60+ { url = root ++ "/~/name"
61+ , method = "GET"
62+ , headers = []
63+ , timeout = Nothing
64+ , tracker = Nothing
65+ , body = Http.emptyBody
66+ , expect = Http.expectString identity
67+ }
68+
69+
5670type Noun
5771 = Cell ( Noun, Noun )
5872 | Atom Atom