Skip to content

Commit

Permalink
elm-format
Browse files Browse the repository at this point in the history
  • Loading branch information
swistak35 committed Mar 1, 2024
1 parent 09af2ab commit 35606a7
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 17 deletions.
18 changes: 11 additions & 7 deletions ruby_event_store-browser/elm/src/Api.elm
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ eventUrl flags eventId =

eventsUrl : Flags -> String -> Pagination.Specification -> String
eventsUrl flags streamId pagination =
Url.toString flags.apiUrl ++ "/streams/" ++ (Url.percentEncode streamId) ++ "/relationships/events" ++ (Url.Builder.toQuery (paginationQueryParameters pagination))
Url.toString flags.apiUrl ++ "/streams/" ++ Url.percentEncode streamId ++ "/relationships/events" ++ Url.Builder.toQuery (paginationQueryParameters pagination)


streamUrl : Flags -> String -> String
Expand Down Expand Up @@ -190,13 +190,17 @@ paginationQueryParameters specification =

extractQueryArgument : String -> Url.Url -> Maybe String
extractQueryArgument key location =
{ location | path = "" } -- https://github.com/elm/url/issues/17#issuecomment-482947419
|> Url.Parser.parse (Url.Parser.query (Url.Parser.Query.string key))
|> Maybe.withDefault Nothing
{ location | path = "" }
-- https://github.com/elm/url/issues/17#issuecomment-482947419
|> Url.Parser.parse (Url.Parser.query (Url.Parser.Query.string key))
|> Maybe.withDefault Nothing


specificationFromUrl : String -> Pagination.Specification
specificationFromUrl stringUrl =
case (Url.fromString stringUrl) of
Just url -> Pagination.Specification (extractQueryArgument "page[position]" url) (extractQueryArgument "page[direction]" url) (extractQueryArgument "page[count]" url)
Nothing -> Pagination.empty
case Url.fromString stringUrl of
Just url ->
Pagination.Specification (extractQueryArgument "page[position]" url) (extractQueryArgument "page[direction]" url) (extractQueryArgument "page[count]" url)

Nothing ->
Pagination.empty
11 changes: 7 additions & 4 deletions ruby_event_store-browser/elm/src/Page/ShowEvent.elm
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,14 @@ update msg model =
( { model | event = Api.Failure }, Cmd.none )

CausedStreamFetched (Ok streamResource) ->
( model,
case (causationStreamName model.event) of
( model
, case causationStreamName model.event of
Just streamName ->
Api.getEvents CausedEventsFetched model.flags streamName Pagination.empty

Nothing ->
Cmd.none
)
)

CausedStreamFetched (Err _) ->
( { model | causedEvents = Api.Failure }, Cmd.none )
Expand Down Expand Up @@ -432,10 +433,12 @@ showJsonTree rawJson treeState changeState =
|> Result.withDefault
(pre [] [ text rawJson ])


causationStreamName : Api.RemoteResource Event -> Maybe String
causationStreamName remoteResource =
causationStreamName remoteResource =
case remoteResource of
Api.Loaded event ->
event.causationStreamName

_ ->
Nothing
9 changes: 7 additions & 2 deletions ruby_event_store-browser/elm/src/Page/ShowStream.elm
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,19 @@ maybeHref streamName baseUrl link =
Just url ->
[ href (Route.paginatedStreamUrl baseUrl streamName url.specification)
]

Nothing ->
[]


paginationStyle : Maybe Api.PaginationLink -> String
paginationStyle link =
case link of
Just _ -> "text-center text-sm border-red-700 text-red-700 border rounded px-2 py-1 mr-1"
Nothing -> "text-center text-sm border rounded px-2 py-1 mr-1 text-red-700/50 border-red-700/50 cursor-not-allowed"
Just _ ->
"text-center text-sm border-red-700 text-red-700 border rounded px-2 py-1 mr-1"

Nothing ->
"text-center text-sm border rounded px-2 py-1 mr-1 text-red-700/50 border-red-700/50 cursor-not-allowed"


nextPageButton : String -> Url.Url -> Maybe Api.PaginationLink -> Html Msg
Expand Down
4 changes: 3 additions & 1 deletion ruby_event_store-browser/elm/src/Pagination.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Pagination exposing (Specification, empty)

import Url


type alias Specification =
{ position : Maybe String
, direction : Maybe String
Expand All @@ -10,4 +11,5 @@ type alias Specification =


empty : Specification
empty = Specification Nothing Nothing Nothing
empty =
Specification Nothing Nothing Nothing
3 changes: 2 additions & 1 deletion ruby_event_store-browser/elm/src/Route.elm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Route exposing (Route(..), buildUrl, decodeLocation, eventUrl, streamUrl, paginatedStreamUrl)
module Route exposing (Route(..), buildUrl, decodeLocation, eventUrl, paginatedStreamUrl, streamUrl)

import Maybe.Extra
import Pagination
Expand All @@ -13,6 +13,7 @@ type Route
= BrowseEvents String Pagination.Specification
| ShowEvent String


decodeLocation : Url.Url -> Url.Url -> Maybe Route
decodeLocation baseUrl loc =
Url.Parser.parse routeParser (urlWithoutBase baseUrl loc)
Expand Down
4 changes: 2 additions & 2 deletions ruby_event_store-browser/elm/tests/DecodersTest.elm
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ suite =
, pagination =
Pagination.empty
, links =
{ next = Just { specification = (Pagination.Specification (Just "664ada1e-2f01-4ed0-9c16-63dbc82269d2") (Just "backward") (Just "20")) }
{ next = Just { specification = Pagination.Specification (Just "664ada1e-2f01-4ed0-9c16-63dbc82269d2") (Just "backward") (Just "20") }
, prev = Nothing
, first = Nothing
, last = Just { specification = (Pagination.Specification (Just "head") (Just "forward") (Just "20")) }
, last = Just { specification = Pagination.Specification (Just "head") (Just "forward") (Just "20") }
}
}
)
Expand Down

0 comments on commit 35606a7

Please sign in to comment.