1port module Vanilla exposing (main)
3import BigInt exposing (BigInt)
4import Browser exposing (Document)
5import Element exposing (..)
6import Element.Border as Border
7import Heroicons.Outline
8import Json.Decode as JD
13import Ur.Constructor as C
14import Ur.Deconstructor as D
18import Widget.Icon as Icon
19import Widget.Material as Material
24 "http://localhost:8080"
27main : Ur.Run.Program Model Msg
38 [ Ur.logIn url "lidlut-tabwed-pillex-ridrup"
39 |> Cmd.map (result (Debug.toString >> Error) (always Noop))
40 , Ur.getShipName url |> Cmd.map (result (always Noop) GotShipName)
44 , path = [ "entries", "all" ]
48 (D.cell (D.const D.cord "jrnl")
49 (D.list (D.cell D.bigint D.cord))
51 |> D.map (\( (), ( (), listings ) ) -> GotListings listings)
58 , subscriptions = always Sub.none
59 , createEventSource = createEventSource
60 , urbitSubscriptions =
61 \{ entries, shipName } ->
62 case ( entries, shipName ) of
63 ( Just _, Just ship ) ->
67 , path = [ "updates" ]
68 , deconstructor = decodeJournalUpdate |> D.map GotUpdate
73 , onEventSourceMsg = onEventSourceMessage
74 , onUrlChange = \_ -> Noop
75 , onUrlRequest = \_ -> Noop
76 , urbitUrl = \_ -> url
82 , entries : Maybe (List ( BigInt, String ))
84 , shipName : Maybe String
91 | GotListings (List ( BigInt, String ))
92 | GotUpdate JournalUpdate
93 | UpdateNewEntry String
96 | RunCmd (Ur.Cmd.Cmd Msg)
100update : Msg -> Model -> ( Model, Ur.Cmd.Cmd Msg )
104 ( model, Ur.Cmd.none )
107 ( { model | error = err }, Ur.Cmd.none )
109 GotListings entries ->
110 ( { model | entries = Just entries }, Ur.Cmd.none )
114 applyAction oldEntries =
117 ( id, txt ) :: oldEntries
122 (\(( key, _ ) as value) ->
131 oldEntries |> List.filter (\( key, _ ) -> key /= id)
134 model.entries |> Maybe.map applyAction
136 ( { model | entries = newEntries }, Ur.Cmd.none )
138 UpdateNewEntry txt ->
139 ( { model | newEntry = txt }, Ur.Cmd.none )
146 , mark = "journal-action"
147 , noun = C.cell (C.cord "del") (C.bigint id)
152 ( { model | newEntry = "" }
159 , mark = "journal-action"
160 , noun = C.cell (C.cord "add") (C.cell (time |> Time.posixToMillis |> BigInt.fromInt |> C.bigint) (C.cord txt))
171 ( { model | shipName = Just name }, Ur.Cmd.none )
180decodeJournalUpdate : D.Deconstructor JournalUpdate
183 [ (D.cell (D.const D.cord "add") <| D.cell D.bigint D.cord) |> D.map (\( (), ( id, txt ) ) -> Add id txt)
184 , D.cell (D.const D.cord "edit") (D.cell D.bigint D.cord) |> D.map (\( (), ( id, txt ) ) -> Edit id txt)
185 , D.cell (D.const D.cord "del") D.bigint |> D.map (\( (), id ) -> Delete id)
188 |> D.map (\( (), upd ) -> upd)
191view : Model -> Document Msg
195 ([ el [ alignTop ] (text model.error)
197 [ Widget.textInput (Material.textInput Material.defaultPalette)
199 , text = model.newEntry
200 , placeholder = Nothing
201 , label = "New entry"
202 , onChange = UpdateNewEntry
204 , Widget.iconButton (Material.containedButton Material.defaultPalette)
206 , icon = Icon.elmHeroicons Heroicons.Outline.check
207 , onPress = AddEntry model.newEntry |> Just
211 |> Maybe.withDefault []
216 , Border.shadow { offset = ( 0, 5 ), size = 1, blur = 10, color = rgba 0 0 0 0.3 }
221 [ paragraph [] [ text txt ]
222 , Widget.iconButton (Material.containedButton Material.defaultPalette)
224 , icon = Icon.elmHeroicons Heroicons.Outline.trash
225 , onPress = DeleteEntry id |> Just
229 |> column [ spacing 10, centerX ]
231 |> column [ spacing 18, centerX ]
238result : (a -> c) -> (b -> c) -> Result a b -> c
248port createEventSource : String -> Cmd msg
251port onEventSourceMessage : (JD.Value -> msg) -> Sub msg
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list