Skip to content

Commit

Permalink
gui/elm: Configure partial sync during Onboarding (#2175)
Browse files Browse the repository at this point in the history
Once the OAuth client used to communicate with the remote Cozy has
been created, we can offer users to configure the partial
synchronization of their remote folders.

To this end, we modify the Folder page of the Onboarding to display a
link to the OAuth client's configuration within the remote Settings
app.

For now, this link will only be displayed if the partial
synchronization flag is enabled on the Cozy.
  • Loading branch information
taratatach authored Nov 17, 2021
2 parents ac1fd54 + 3bd1864 commit 997524b
Show file tree
Hide file tree
Showing 25 changed files with 481 additions and 193 deletions.
21 changes: 21 additions & 0 deletions gui/elm/Data/AddressConfig.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Data.AddressConfig exposing (AddressConfig, init, setError)


type alias AddressConfig =
{ address : String
, error : String
, busy : Bool
}


init : AddressConfig
init =
{ address = ""
, error = ""
, busy = False
}


setError : AddressConfig -> String -> AddressConfig
setError addressConfig error =
{ addressConfig | error = error, busy = False }
13 changes: 13 additions & 0 deletions gui/elm/Data/SyncFolderConfig.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Data.SyncFolderConfig exposing
( SyncFolderConfig
, isValid
, setError
, valid
)

Expand All @@ -26,3 +27,15 @@ isValid model =

Just _ ->
False


setError : SyncFolderConfig -> String -> SyncFolderConfig
setError folderConfig error =
{ folderConfig
| error =
if error == "" then
Nothing

else
Just error
}
4 changes: 0 additions & 4 deletions gui/elm/Ports.elm
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ port module Ports exposing
, openFile
, quitAndInstall
, registerRemote
, registrationDone
, registrationError
, remove
, sendMail
Expand Down Expand Up @@ -97,9 +96,6 @@ port quitAndInstall : () -> Cmd msg
port registerRemote : String -> Cmd msg


port registrationDone : (Bool -> msg) -> Sub msg


port registrationError : (String -> msg) -> Sub msg


Expand Down
41 changes: 22 additions & 19 deletions gui/elm/Window/Onboarding.elm
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ module Window.Onboarding exposing
, view
)

import Data.SyncConfig as SyncConfig exposing (SyncConfig)
import Html exposing (..)
import Html.Attributes exposing (..)
import Locale exposing (Helpers)
import Ports
import Window.Onboarding.Address as Address
import Window.Onboarding.Context as Context exposing (Context)
import Window.Onboarding.Folder as Folder
import Window.Onboarding.Welcome as Welcome

Expand All @@ -29,18 +31,14 @@ type Page

type alias Model =
{ page : Page
, platform : String
, address : Address.Model
, folder : Folder.Model
, context : Context
}


init : String -> String -> Model
init folder platform =
{ page = WelcomePage
, platform = platform
, address = Address.init
, folder = Folder.init folder
, context = Context.init platform folder
}


Expand All @@ -51,7 +49,7 @@ init folder platform =
type Msg
= WelcomeMsg Welcome.Msg
| AddressMsg Address.Msg
| RegistrationDone
| RegistrationDone SyncConfig
| FolderMsg Folder.Msg


Expand All @@ -69,20 +67,25 @@ update msg model =

AddressMsg subMsg ->
let
( address, cmd ) =
Address.update subMsg model.address
( context, cmd ) =
Address.update subMsg model.context
in
( { model | address = address }, Cmd.map AddressMsg cmd )
( { model | context = context }, Cmd.map AddressMsg cmd )

RegistrationDone ->
( { model | page = FolderPage }, Cmd.none )
RegistrationDone syncConfig ->
( { model
| page = FolderPage
, context = Context.setSyncConfig model.context syncConfig
}
, Cmd.none
)

FolderMsg subMsg ->
let
( folder, cmd ) =
Folder.update subMsg model.folder
( context, cmd ) =
Folder.update subMsg model.context
in
( { model | folder = folder }, Cmd.map FolderMsg cmd )
( { model | context = context }, cmd )



Expand All @@ -93,7 +96,7 @@ subscriptions : Model -> Sub Msg
subscriptions model =
Sub.batch
[ Ports.registrationError (AddressMsg << Address.RegistrationError)
, Ports.registrationDone (always RegistrationDone)
, SyncConfig.gotSyncConfig RegistrationDone
, Ports.folderError (FolderMsg << Folder.SetError)
, Ports.folder (FolderMsg << Folder.FillFolder)
]
Expand All @@ -113,7 +116,7 @@ view helpers model =
, ( "on-step-folder", model.page == FolderPage )
]
]
[ Html.map WelcomeMsg (Welcome.view helpers model.platform)
, Html.map AddressMsg (Address.view helpers model.address)
, Html.map FolderMsg (Folder.view helpers model.folder)
[ Html.map WelcomeMsg (Welcome.view helpers model.context)
, Html.map AddressMsg (Address.view helpers model.context)
, Html.map FolderMsg (Folder.view helpers model.context)
]
94 changes: 46 additions & 48 deletions gui/elm/Window/Onboarding/Address.elm
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
module Window.Onboarding.Address exposing
( Model
, Msg(..)
( Msg(..)
, correctAddress
, dropAppName
, init
, setError
, update
, view
)

import Data.AddressConfig as AddressConfig exposing (AddressConfig)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
Expand All @@ -18,25 +17,7 @@ import Ports
import String exposing (contains)
import Url
import Util.Keyboard as Keyboard



-- MODEL


type alias Model =
{ address : String
, error : String
, busy : Bool
}


init : Model
init =
{ address = ""
, error = ""
, busy = False
}
import Window.Onboarding.Context as Context exposing (Context)



Expand All @@ -50,9 +31,9 @@ type Msg
| CorrectAddress


setError : Model -> String -> ( Model, Cmd msg )
setError model message =
( { model | error = message, busy = False }
setError : Context -> String -> ( Context, Cmd msg )
setError context message =
( Context.setAddressConfig context (AddressConfig.setError context.addressConfig message)
, Ports.focus ".wizard__address"
)

Expand Down Expand Up @@ -134,60 +115,77 @@ correctAddress address =
|> appendPort


update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
update : Msg -> Context -> ( Context, Cmd msg )
update msg context =
case
msg
of
FillAddress address ->
( { model | address = address, error = "", busy = False }, Cmd.none )
( Context.setAddressConfig context { address = address, error = "", busy = False }, Cmd.none )

CorrectAddress ->
( { model | address = correctAddress model.address }, Cmd.none )
let
addressConfig =
context.addressConfig

newAddressConfig =
{ addressConfig
| address = correctAddress addressConfig.address
}
in
( Context.setAddressConfig context newAddressConfig, Cmd.none )

RegisterRemote ->
if model.address == "" then
setError model "Address You don't have filled the address!"
let
addressConfig =
context.addressConfig
in
if addressConfig.address == "" then
setError context "Address You don't have filled the address!"

else if contains "@" model.address then
setError model "Address No email address"
else if contains "@" addressConfig.address then
setError context "Address No email address"

else if contains "mycosy.cloud" model.address then
setError model "Address Cozy not cosy"
else if contains "mycosy.cloud" addressConfig.address then
setError context "Address Cozy not cosy"

else
( { model | busy = True, address = correctAddress model.address }
, Ports.registerRemote (correctAddress model.address)
let
newAddressConfig =
{ addressConfig | address = correctAddress addressConfig.address, busy = True }
in
( Context.setAddressConfig context newAddressConfig
, Ports.registerRemote (correctAddress newAddressConfig.address)
)

RegistrationError error ->
setError model error
setError context error



-- VIEW


view : Helpers -> Model -> Html Msg
view helpers model =
view : Helpers -> Context -> Html Msg
view helpers context =
div
[ classList
[ ( "step", True )
, ( "step-address", True )
, ( "step-error", model.error /= "" )
, ( "step-error", context.addressConfig.error /= "" )
]
]
[ div
[ class "step-content" ]
[ Icons.cozyBig
, h1 [] [ text (helpers.t "Address Please introduce your cozy address") ]
, if model.error == "" then
, if context.addressConfig.error == "" then
p [ class "adress-helper" ]
[ text (helpers.t "Address This is the web address you use to sign in to your cozy.") ]

else
p [ class "error-message" ]
[ text (helpers.t model.error) ]
[ text (helpers.t context.addressConfig.error) ]
, div [ class "coz-form-group" ]
[ label [ class "coz-form-label" ]
[ text (helpers.t "Address Cozy address") ]
Expand All @@ -198,11 +196,11 @@ view helpers model =
[ placeholder "cloudy.mycozy.cloud"
, classList
[ ( "wizard__address", True )
, ( "error", model.error /= "" )
, ( "error", context.addressConfig.error /= "" )
]
, type_ "text"
, value model.address
, disabled model.busy
, value context.addressConfig.address
, disabled context.addressConfig.busy
, onInput FillAddress
, Keyboard.onEnter RegisterRemote
, onBlur CorrectAddress
Expand All @@ -218,10 +216,10 @@ view helpers model =
, a
[ class "btn"
, href "#"
, if model.address == "" then
, if context.addressConfig.address == "" then
attribute "disabled" "true"

else if model.busy then
else if context.addressConfig.busy then
attribute "aria-busy" "true"

else
Expand Down
38 changes: 38 additions & 0 deletions gui/elm/Window/Onboarding/Context.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module Window.Onboarding.Context exposing (Context, init, setAddressConfig, setFolderConfig, setSyncConfig)

import Data.AddressConfig as AddressConfig exposing (AddressConfig)
import Data.SyncConfig as SyncConfig exposing (SyncConfig)
import Data.SyncFolderConfig as SyncFolderConfig exposing (SyncFolderConfig)
import Url exposing (Url)


type alias Context =
{ platform : String
, addressConfig : AddressConfig
, folderConfig : SyncFolderConfig
, syncConfig : SyncConfig
}


init : String -> String -> Context
init platform folder =
{ platform = platform
, addressConfig = AddressConfig.init
, folderConfig = SyncFolderConfig.valid folder
, syncConfig = SyncConfig.init
}


setAddressConfig : Context -> AddressConfig -> Context
setAddressConfig context addressConfig =
{ context | addressConfig = addressConfig }


setSyncConfig : Context -> SyncConfig -> Context
setSyncConfig context syncConfig =
{ context | syncConfig = syncConfig }


setFolderConfig : Context -> SyncFolderConfig -> Context
setFolderConfig context folderConfig =
{ context | folderConfig = folderConfig }
Loading

0 comments on commit 997524b

Please sign in to comment.