Skip to content
This repository has been archived by the owner on Apr 17, 2024. It is now read-only.

Commit

Permalink
WS-442 | WMS reusable code (#71)
Browse files Browse the repository at this point in the history
* Bump PaackEng/paack-ui from 7.8.1 to 7.9.0 in /example

Bumps [PaackEng/paack-ui](https://github.com/PaackEng/paack-ui) from 7.8.1 to 7.9.0.
- [Release notes](https://github.com/PaackEng/paack-ui/releases)
- [Commits](PaackEng/paack-ui@7.8.1...7.9.0)

---
updated-dependencies:
- dependency-name: PaackEng/paack-ui
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* Bump esbuild from 0.14.0 to 0.14.1

Bumps [esbuild](https://github.com/evanw/esbuild) from 0.14.0 to 0.14.1.
- [Release notes](https://github.com/evanw/esbuild/releases)
- [Changelog](https://github.com/evanw/esbuild/blob/master/CHANGELOG.md)
- [Commits](evanw/esbuild@v0.14.0...v0.14.1)

---
updated-dependencies:
- dependency-name: esbuild
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

* Add loadUrl effect

* Add reusable code from WMS

* Apply elm-format

* Remove Paack.Remote

* Remove legacy Paack.Basics.Extra

* Add reusable code from LMO

* Add indicator to what kind of request is being made

* Fix review issues

* Bump to 3.0.0

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
chrisfls and dependabot[bot] authored Dec 22, 2021
1 parent cfef3da commit 3b3cefb
Show file tree
Hide file tree
Showing 17 changed files with 397 additions and 130 deletions.
15 changes: 15 additions & 0 deletions elm/Paack/Basics.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Paack.Basics.Extra exposing (flip, ifThenElse, maybePrepend)


flip : (a -> b -> c) -> b -> a -> c
flip applier b a =
applier a b


ifThenElse : Bool -> a -> a -> a
ifThenElse condition ifThen ifElse =
if condition then
ifThen

else
ifElse
16 changes: 0 additions & 16 deletions elm/Paack/Basics/Extra.elm

This file was deleted.

73 changes: 73 additions & 0 deletions elm/Paack/DateFormat.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
module Paack.DateFormat exposing (..)

import DateFormat exposing (..)
import Time


fullStamp : List Token
fullStamp =
[ dayOfMonthFixed
, DateFormat.text "/"
, monthFixed
, DateFormat.text "/"
, yearNumberLastTwo
, DateFormat.text " "
, hourMilitaryFixed
, DateFormat.text ":"
, minuteFixed
]


dateOnly : List Token
dateOnly =
[ dayOfMonthFixed
, DateFormat.text "/"
, monthFixed
, DateFormat.text "/"
, yearNumberLastTwo
]


timeOnly : List Token
timeOnly =
[ hourMilitaryFixed
, DateFormat.text ":"
, minuteFixed
]


shortMonthDayYear : List Token
shortMonthDayYear =
[ monthNameAbbreviated
, text " "
, DateFormat.dayOfMonthFixed
, text ", "
, yearNumber
]


sortableTime : Time.Posix -> String
sortableTime time =
format
[ yearNumber
, DateFormat.text "-"
, monthFixed
, DateFormat.text "-"
, dayOfMonthFixed
, DateFormat.text "-"
, hourMilitaryFixed
, DateFormat.text "-"
, minuteFixed
]
Time.utc
time


sortableDate : List Token
sortableDate =
[ yearNumber
, DateFormat.text "-"
, monthFixed
, DateFormat.text "-"
, dayOfMonthFixed
]
17 changes: 17 additions & 0 deletions elm/Paack/Dict.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Paack.Dict exposing (toggle)

import Dict exposing (Dict)


toggle : comparable -> object -> Dict comparable object -> Dict comparable object
toggle key value dict =
Dict.update key
(\past ->
case past of
Just _ ->
Nothing

Nothing ->
Just value
)
dict
9 changes: 7 additions & 2 deletions elm/Paack/Effects.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Paack.Effects exposing
( Effects, fromLocal
, none, batch, map
, loopMsg
, pushUrl, replaceUrl, timeHere, domFocus, domGetElement, domSetViewportOf
, loadUrl, pushUrl, replaceUrl, timeHere, domFocus, domGetElement, domSetViewportOf
, uuidGenerator, httpRequest, paackUI
, graphqlQuery, graphqlMutation
, Effect(..), apply
Expand All @@ -24,7 +24,7 @@ module Paack.Effects exposing
# Common Effects
@docs loopMsg
@docs pushUrl, replaceUrl, timeHere, domFocus, domGetElement, domSetViewportOf
@docs loadUrl, pushUrl, replaceUrl, timeHere, domFocus, domGetElement, domSetViewportOf
@docs uuidGenerator, httpRequest, paackUI
@docs graphqlQuery, graphqlMutation
Expand Down Expand Up @@ -102,6 +102,11 @@ mapEffects applier sideEffects =
-- Common side effects


loadUrl : String -> Effects msg
loadUrl =
Common.loadUrl >> fromCommon


pushUrl : String -> Effects msg
pushUrl =
Common.pushUrl >> fromCommon
Expand Down
13 changes: 11 additions & 2 deletions elm/Paack/Effects/Common.elm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Paack.Effects.Common exposing
( CommonEffect(..), mapCommonEffect
, loopMsg
, pushUrl, replaceUrl, timeHere, domGetElement, domSetViewportOf, domFocus
, loadUrl, pushUrl, replaceUrl, timeHere, domGetElement, domSetViewportOf, domFocus
, uuidGenerator, httpRequest
, GraphqlRequestEffect, HttpRequestEffect, graphqlQuery, graphqlMutation
)
Expand All @@ -17,7 +17,7 @@ module Paack.Effects.Common exposing
# Common Effectss
@docs loopMsg
@docs pushUrl, replaceUrl, timeHere, domGetElement, domSetViewportOf, domFocus
@docs loadUrl, pushUrl, replaceUrl, timeHere, domGetElement, domSetViewportOf, domFocus
@docs uuidGenerator, httpRequest
@docs GraphqlRequestEffect, HttpRequestEffect, graphqlQuery, graphqlMutation
Expand All @@ -37,6 +37,7 @@ import UUID exposing (UUID, decoder)

type CommonEffect msg
= LoopMsg msg
| LoadUrl String
| PushUrl String
| ReplaceUrl String
| TimeHere (Time.Zone -> msg)
Expand Down Expand Up @@ -74,6 +75,9 @@ mapCommonEffect fn effect =
LoopMsg msg ->
LoopMsg <| fn msg

LoadUrl url ->
LoadUrl url

PushUrl url ->
PushUrl url

Expand Down Expand Up @@ -123,6 +127,11 @@ mapCommonEffect fn effect =
}


loadUrl : String -> CommonEffect msg
loadUrl =
LoadUrl


pushUrl : String -> CommonEffect msg
pushUrl =
PushUrl
Expand Down
3 changes: 3 additions & 0 deletions elm/Paack/Effects/CommonPerformer.elm
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ effectPerform key seeds effect =
, Task.perform identity <| Task.succeed msg
)

LoadUrl url ->
( seeds, Nav.load url )

PushUrl url ->
( seeds
, Nav.pushUrl key url
Expand Down
7 changes: 5 additions & 2 deletions elm/Paack/Effects/CommonSimulator.elm
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ effectPerform index effect =
LoopMsg msg ->
loop msg

LoadUrl url ->
Nav.load url

PushUrl url ->
Nav.pushUrl url

Expand Down Expand Up @@ -71,7 +74,7 @@ httpRequest index data =
graphqlHttpQuery : Int -> GraphqlRequestEffect RootQuery msg -> SimulatedEffect msg
graphqlHttpQuery index data =
ElmHttp.post
{ url = data.url ++ "#i" ++ String.fromInt index
{ url = data.url ++ "#q" ++ String.fromInt index
, body = ElmHttp.emptyBody
, expect = graphqlExpect data
}
Expand All @@ -80,7 +83,7 @@ graphqlHttpQuery index data =
graphqlHttpMutation : Int -> GraphqlRequestEffect RootMutation msg -> SimulatedEffect msg
graphqlHttpMutation index data =
ElmHttp.post
{ url = data.url ++ "#i" ++ String.fromInt index
{ url = data.url ++ "#m" ++ String.fromInt index
, body = ElmHttp.emptyBody
, expect = graphqlExpect data
}
Expand Down
26 changes: 26 additions & 0 deletions elm/Paack/Either.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module Paack.Either exposing (..)


type Either a b
= Left a
| Right b


fromResult : Result error value -> Either error value
fromResult result =
case result of
Ok value ->
Right value

Err error ->
Left error


toResult : Either error value -> Result error value
toResult either =
case either of
Right value ->
Ok value

Left error ->
Err error
20 changes: 20 additions & 0 deletions elm/Paack/Events.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module Paack.Events exposing (onEscapeKey)

import Browser.Events as Events
import Json.Decode as Decode


onEscapeKey : msg -> Sub msg
onEscapeKey msg =
Decode.string
|> Decode.field "key"
|> Decode.andThen
(\key ->
case key of
"Escape" ->
Decode.succeed msg

_ ->
Decode.fail "Irrelevant key"
)
|> Events.onKeyUp
13 changes: 13 additions & 0 deletions elm/Paack/Json/Encode.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Paack.Json.Encode exposing (..)

import Json.Encode as Encode exposing (Value)


maybeWithNull : (data -> Value) -> Maybe data -> Value
maybeWithNull encoder maybeData =
case maybeData of
Just data ->
encoder data

Nothing ->
Encode.null
72 changes: 72 additions & 0 deletions elm/Paack/List.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
module Paack.List exposing (..)

import UUID exposing (UUID)


unique : List comparable -> List comparable
unique =
Set.fromList >> Set.toList


find : (a -> Bool) -> List a -> Maybe a
find predicate list =
case list of
[] ->
Nothing

head :: tail ->
if predicate head then
Just head

else
find predicate tail


findById : UUID -> List { a | id : UUID } -> Maybe { a | id : UUID }
findById uuid =
find (.id >> (==) uuid)


insert : { a | id : UUID } -> List { a | id : UUID } -> List { a | id : UUID }
insert item list =
list
|> List.filter (.id >> (/=) item.id)
|> (::) item


updateById : UUID -> ({ a | id : UUID } -> { a | id : UUID }) -> List { a | id : UUID } -> List { a | id : UUID }
updateById uuid applier list =
List.map
(\item ->
if item.id == uuid then
applier item

else
item
)
list


prependMaybe : Maybe a -> List a -> List a
prependMaybe maybeSomething items =
case maybeSomething of
Just something ->
something :: items

Nothing ->
items


mapHead : (a -> Maybe b) -> List a -> Maybe b
mapHead filterMap list =
case list of
[] ->
Nothing

head :: tail ->
case filterMap head of
Just match ->
Just match

Nothing ->
mapHead filterMap tail
11 changes: 11 additions & 0 deletions elm/Paack/Maybe.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Paack.Maybe exposing (fallback)


fallback : Maybe a -> Maybe a -> Maybe a
fallback replacement primary =
case primary of
Just _ ->
primary

Nothing ->
replacement
Loading

0 comments on commit 3b3cefb

Please sign in to comment.