Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement/pin hidden #628

Merged
merged 4 commits into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/elm/Auth.elm
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ import View.Pin as Pin
-- INIT


init : Maybe Eos.PrivateKey -> Model
init maybePrivateKey_ =
init : Bool -> Maybe Eos.PrivateKey -> Model
init pinVisibility maybePrivateKey_ =
let
status =
case maybePrivateKey_ of
Expand All @@ -69,7 +69,7 @@ init maybePrivateKey_ =
in
{ status = status
, error = Nothing
, pinModel = initPinModel status
, pinModel = initPinModel pinVisibility status
}


Expand All @@ -84,14 +84,15 @@ type alias Model =
}


initPinModel : Status -> Pin.Model
initPinModel status =
initPinModel : Bool -> Status -> Pin.Model
initPinModel pinVisibility status =
Pin.init
{ label = "auth.pinPopup.label"
, id = "pinPopup"
, withConfirmation = False
, submitLabel = "auth.login.continue"
, submittingLabel = "auth.login.continue"
, pinVisibility = pinVisibility
}
|> Pin.withDisabled
(case status of
Expand Down Expand Up @@ -182,6 +183,7 @@ type alias SignInResponse =

type ExternalMsg
= CompletedAuth SignInResponse Model
| UpdatedShared Shared


update : Msg -> Shared -> Model -> UpdateResult
Expand All @@ -194,10 +196,14 @@ update msg shared model =
let
( newPinModel, submitStatus ) =
Pin.update subMsg model.pinModel

( newShared, submitCmd ) =
Pin.postSubmitAction newPinModel submitStatus shared SubmittedPin
in
{ model | pinModel = newPinModel }
|> UR.init
|> UR.addCmd (Pin.maybeSubmitCmd submitStatus SubmittedPin)
|> UR.addCmd submitCmd
|> UR.addExt (UpdatedShared newShared)

CompletedSignIn status (RemoteData.Success (Just ({ token } as signInResponse))) ->
let
Expand Down Expand Up @@ -311,7 +317,7 @@ authFailed error model =
| status = WithoutPrivateKey
, error = Nothing
, pinModel =
initPinModel model.status
initPinModel model.pinModel.isPinVisible model.status
|> Pin.withProblem Pin.Pin error
}
|> UR.init
Expand Down
3 changes: 3 additions & 0 deletions src/elm/Flags.elm
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type alias Flags =
, canReadClipboard : Bool
, useSubdomain : Bool
, selectedCommunity : Maybe Eos.Symbol
, pinVisibility : Bool
}


Expand All @@ -45,6 +46,7 @@ default =
, canReadClipboard = False
, useSubdomain = True
, selectedCommunity = Nothing
, pinVisibility = False
}


Expand Down Expand Up @@ -72,6 +74,7 @@ decode =
|> required "canReadClipboard" Decode.bool
|> required "useSubdomain" Decode.bool
|> required "selectedCommunity" (Decode.nullable Eos.symbolDecoder)
|> required "pinVisibility" Decode.bool


type alias Endpoints =
Expand Down
5 changes: 5 additions & 0 deletions src/elm/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,11 @@ updateGuestUResult toStatus toMsg model uResult =
( { m | session = Page.Guest { guest | feedback = feedback } }
, cmds_
)

Guest.UpdatedShared newShared ->
( { m | session = Page.Guest { guest | shared = newShared } }
, cmds_
)
)
( { model | status = toStatus uResult.model }
, []
Expand Down
13 changes: 9 additions & 4 deletions src/elm/Page/Login.elm
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ initPassphraseModel =
}


initPinModel : String -> PinModel
initPinModel passphrase =
initPinModel : Bool -> String -> PinModel
initPinModel pinVisibility passphrase =
{ isSigningIn = False
, passphrase = passphrase
, pinModel =
Expand All @@ -74,6 +74,7 @@ initPinModel passphrase =
, withConfirmation = True
, submitLabel = "auth.login.submit"
, submittingLabel = "auth.login.submitting"
, pinVisibility = pinVisibility
}
}

Expand Down Expand Up @@ -349,7 +350,7 @@ update msg model guest =
( WentToPin validPassphrase, EnteringPassphrase _ ) ->
Validate.fromValid validPassphrase
|> .passphrase
|> initPinModel
|> initPinModel guest.shared.pinVisibility
|> EnteringPin
|> UR.init
|> UR.addCmd
Expand Down Expand Up @@ -608,10 +609,14 @@ updateWithPin msg model ({ shared } as guest) =
let
( pinModel, submitStatus ) =
Pin.update subMsg model.pinModel

( newShared, submitCmd ) =
Pin.postSubmitAction pinModel submitStatus shared SubmittedPinWithSuccess
in
{ model | pinModel = pinModel }
|> UR.init
|> UR.addCmd (Pin.maybeSubmitCmd submitStatus SubmittedPinWithSuccess)
|> UR.addCmd submitCmd
|> UR.addExt (PinGuestExternal (Guest.UpdatedShared newShared))



Expand Down
16 changes: 14 additions & 2 deletions src/elm/Page/Profile.elm
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ init loggedIn profileName =
, withConfirmation = False
, submitLabel = "profile.pin.button"
, submittingLabel = "profile.pin.button"
, pinVisibility = loggedIn.shared.pinVisibility
}
, currentPin = Nothing
}
Expand Down Expand Up @@ -474,7 +475,14 @@ update msg model loggedIn =
|> UR.init

ClickedChangePin ->
{ model | isNewPinModalVisible = True }
let
oldPinInputModel =
model.pinInputModel
in
{ model
| isNewPinModalVisible = True
, pinInputModel = { oldPinInputModel | isPinVisible = loggedIn.auth.pinModel.isPinVisible }
}
|> UR.init
|> LoggedIn.withAuthentication loggedIn
model
Expand All @@ -488,10 +496,14 @@ update msg model loggedIn =
let
( newPinModel, submitStatus ) =
Pin.update subMsg model.pinInputModel

( newShared, submitCmd ) =
Pin.postSubmitAction newPinModel submitStatus loggedIn.shared SubmittedNewPin
in
{ model | pinInputModel = newPinModel }
|> UR.init
|> UR.addCmd (Pin.maybeSubmitCmd submitStatus SubmittedNewPin)
|> UR.addCmd submitCmd
|> UR.addExt (LoggedIn.UpdatedLoggedIn { loggedIn | shared = newShared })

SubmittedNewPin newPin ->
let
Expand Down
10 changes: 8 additions & 2 deletions src/elm/Ports.elm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ port module Ports exposing
, setMarkdownContent
, storeAuthToken
, storeLanguage
, storePinVisibility
, storeRecentSearches
, storeSelectedCommunitySymbol
)
Expand Down Expand Up @@ -69,12 +70,12 @@ port javascriptInPort : (Value -> msg) -> Sub msg
port storeLanguage : String -> Cmd msg


{-| Store recent searches to the `localStorage`.
{-| Store recent searches
-}
port storeRecentSearches : String -> Cmd msg


{-| Ping JS to send back the recent searches from the `localStorage`.
{-| Ping JS to send back the recent searches
-}
port getRecentSearches : () -> Cmd msg

Expand All @@ -90,6 +91,11 @@ port storeAuthToken : String -> Cmd msg
port storeSelectedCommunitySymbol : String -> Cmd msg


{-| Store whether to show or hide the pin by default
-}
port storePinVisibility : Bool -> Cmd msg


{-| Send info about a link in a MarkdownEditor to be treated on JS
-}
sendMarkdownLink : { id : String, label : String, url : String } -> Cmd msg
Expand Down
1 change: 1 addition & 0 deletions src/elm/Session/Guest.elm
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ viewPageHeader model shared =
type External
= LoggedIn Eos.PrivateKey Auth.SignInResponse
| SetFeedback Feedback.Model
| UpdatedShared Shared


type BroadcastMsg
Expand Down
6 changes: 5 additions & 1 deletion src/elm/Session/LoggedIn.elm
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ initModel shared maybePrivateKey_ accountName authToken =
, notification = Notification.init
, unreadCount = 0
, showAuthModal = False
, auth = Auth.init maybePrivateKey_
, auth = Auth.init shared.pinVisibility maybePrivateKey_
, feedback = Feedback.Hidden
, showCommunitySelector = False
, searchModel = Search.init
Expand Down Expand Up @@ -1191,6 +1191,10 @@ update msg model =
, data = Dict.fromList [ ( "username", Eos.encodeName user.account ) ]
, level = Log.Info
}

Auth.UpdatedShared newShared ->
uResult
|> UR.mapModel (\m -> { m | shared = newShared })
)

CompletedLoadUnread payload ->
Expand Down
2 changes: 2 additions & 0 deletions src/elm/Session/Shared.elm
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type alias Shared =
, canReadClipboard : Bool
, useSubdomain : Bool
, selectedCommunity : Maybe Eos.Symbol
, pinVisibility : Bool
}


Expand Down Expand Up @@ -91,6 +92,7 @@ init ({ maybeAccount, endpoints, allowCommunityCreation, tokenContract, communit
, canReadClipboard = flags.canReadClipboard
, useSubdomain = flags.useSubdomain
, selectedCommunity = flags.selectedCommunity
, pinVisibility = flags.pinVisibility
}
, case environment of
Production ->
Expand Down
29 changes: 18 additions & 11 deletions src/elm/View/Pin.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ module View.Pin exposing
, RequiredOptions
, SubmitStatus(..)
, init
, maybeSubmitCmd
, msgToString
, postSubmitAction
, update
, view
, withAttrs
Expand All @@ -25,7 +25,8 @@ import Html exposing (Html, button, div, text)
import Html.Attributes exposing (attribute, autocomplete, class, classList, disabled, maxlength, required, type_)
import Html.Events exposing (keyCode, onClick, preventDefaultOn)
import Json.Decode as Decode
import Session.Shared exposing (Translators)
import Ports
import Session.Shared exposing (Shared, Translators)
import Task
import Validate
import View.Form.Input
Expand Down Expand Up @@ -70,13 +71,14 @@ type alias RequiredOptions =
, withConfirmation : Bool
, submitLabel : String
, submittingLabel : String
, pinVisibility : Bool
}


{-| Initializes a `Model` with some initial `RequiredOptions`
-}
init : RequiredOptions -> Model
init { label, id, withConfirmation, submitLabel, submittingLabel } =
init { label, id, withConfirmation, submitLabel, submittingLabel, pinVisibility } =
{ label = label
, disabled = False
, id = id
Expand All @@ -89,8 +91,8 @@ init { label, id, withConfirmation, submitLabel, submittingLabel } =
Nothing
, placeholder = String.repeat pinLength "*"
, problems = []
, isPinVisible = True
, isPinConfirmationVisible = True
, isPinVisible = pinVisibility
, isPinConfirmationVisible = pinVisibility
, isSubmitting = False
, submitLabel = submitLabel
, submittingLabel = submittingLabel
Expand Down Expand Up @@ -306,18 +308,23 @@ update msg model =
-- UTILS


maybeSubmitCmd : SubmitStatus -> (String -> msg) -> Cmd msg
maybeSubmitCmd status toMsg =
postSubmitAction : Model -> SubmitStatus -> Shared -> (String -> msg) -> ( Shared, Cmd msg )
postSubmitAction model status shared toMsg =
case status of
NotAsked ->
Cmd.none
( shared, Cmd.none )

WithError ->
Cmd.none
( shared, Cmd.none )

Success pin ->
Task.succeed pin
|> Task.perform toMsg
( { shared | pinVisibility = model.isPinVisible }
, Cmd.batch
[ Task.succeed pin
|> Task.perform toMsg
, Ports.storePinVisibility model.isPinVisible
]
)


withDisabled : Bool -> Model -> Model
Expand Down
Loading