Skip to content

Commit

Permalink
Rename KeyState -> InitializationState and add identityState to Stats
Browse files Browse the repository at this point in the history
Should fix #26
  • Loading branch information
bakkdoor committed Oct 15, 2019
1 parent 3c69b13 commit 5aa3273
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 14 deletions.
7 changes: 4 additions & 3 deletions src/Data/Daemon.elm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Data.Daemon
, Error
, ErrorStatus
, GUIConfig
, KeyState(..)
, InitializationState(..)
, LogItem
, Stats
, daemonConfigDecoder
Expand Down Expand Up @@ -33,7 +33,7 @@ type ErrorStatus
= ErrorStatus String


type KeyState
type InitializationState
= Uninitialized
| Initializing
| Initialized
Expand All @@ -42,7 +42,8 @@ type KeyState
type alias Stats =
{ downloads : Int
, uploads : Int
, userKeyState : KeyState
, userKeyState : InitializationState
, identityState : InitializationState
, totalSlots : Int
, busySlots : Int
, idleSlots : Int
Expand Down
14 changes: 11 additions & 3 deletions src/MainScreen.elm
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,17 @@ update msg model =
)

UpdatedStatsFromApi stats ->
( { model | stats = stats }
, Cmd.none
)
let
newModel =
{ model | stats = stats }
in
if isIdentityInitialized newModel then
( newModel
, Cmd.none
)
else
newModel
|> openSetupWizard

VaultUserAdded vaultId email data ->
model
Expand Down
20 changes: 14 additions & 6 deletions src/Model.elm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Model exposing (..)

import Config exposing (Config)
import Data.Daemon exposing (DaemonConfig, KeyState(..), Stats)
import Data.Daemon exposing (DaemonConfig, InitializationState(..), Stats)
import Data.User exposing (Email)
import Data.Vault exposing (FlyingVault, Status, Vault, VaultId)
import Date exposing (Date)
Expand Down Expand Up @@ -206,17 +206,18 @@ statsDecoder =
decode Stats
|> requiredAt [ "stats", "downloads" ] Json.int
|> requiredAt [ "stats", "uploads" ] Json.int
|> requiredAt [ "user_key_state" ] keyStateDecoder
|> requiredAt [ "user_key_state" ] initializationStateDecoder
|> requiredAt [ "identity_state" ] initializationStateDecoder
|> requiredAt [ "slots", "total" ] Json.int
|> optionalAt [ "slots", "busy" ] Json.int 0
|> optionalAt [ "slots", "idle" ] Json.int 0
|> optionalAt [ "slots", "closed" ] Json.int 0


keyStateDecoder : Json.Decoder KeyState
keyStateDecoder =
initializationStateDecoder : Json.Decoder InitializationState
initializationStateDecoder =
let
parseKeyState s =
parseState s =
succeed <|
case s of
"initializing" ->
Expand All @@ -229,7 +230,7 @@ keyStateDecoder =
Uninitialized
in
Json.string
|> andThen parseKeyState
|> andThen parseState


loginStateDecoder : Json.Decoder LoginState
Expand Down Expand Up @@ -597,3 +598,10 @@ mainTutorial =
, onExit = [ RemoveTooltip (Tooltip.id logoutTooltip) ]
}
]


isIdentityInitialized : Model -> Bool
isIdentityInitialized { stats } =
stats
|> RemoteData.map (\s -> s.identityState /= Uninitialized)
|> RemoteData.withDefault True
2 changes: 1 addition & 1 deletion src/SetupWizard.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module SetupWizard exposing (settings, viewSettings)

import Data.Daemon exposing (KeyState(..))
import Data.Daemon exposing (InitializationState(..))
import Dialog exposing (labeledItem)
import Html exposing (Html, div, input, p, span, text)
import Html.Attributes exposing (class, type_)
Expand Down
2 changes: 1 addition & 1 deletion src/Translation.elm
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module Translation
, translate
)

import Data.Daemon exposing (KeyState, Stats)
import Data.Daemon exposing (InitializationState, Stats)
import Data.User exposing (Email)
import Data.Vault exposing (VaultId)
import Date exposing (Date)
Expand Down

0 comments on commit 5aa3273

Please sign in to comment.