Skip to content

Commit

Permalink
gui: Add complete sync reinitialization action (#2197)
Browse files Browse the repository at this point in the history
When the local PouchDB is corrupted, that files and folders are out of
sync between the local filesystem and the remote Cozy, the only
systemic recourse for the user is to disconnect their Desktop client
and reconnect it.

This process is tedious and users can forget to re-configure their
selective synchronization exclusions for the current computer leading
to misunderstanding and frustration.
Besides, it's also not intuitive and is usually the result of a
contact with our support.

To give users more autonomy and streamline the process, we will now
present a button in the Settings tab which will simply stop the
current synchronization, wipe the local PouchDB and restart from
scratch while reusing the current OAuth client and selective
synchronization configuration.
  • Loading branch information
taratatach authored Feb 15, 2022
2 parents f3add6b + 6cf1634 commit 4b3897e
Show file tree
Hide file tree
Showing 19 changed files with 485 additions and 252 deletions.
49 changes: 49 additions & 0 deletions gui/elm/Data/Confirmation.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
port module Data.Confirmation exposing (ConfirmationID, askForConfirmation, gotConfirmation, newId)

-- Careful! To be sure to match requests with responses, you need to have the
-- same ConfirmationID as the first tuple member in both functions.
--
-- e.g.
-- id = ConfirmationID "AreYouOK"
--
-- askForConfirmation (id, "Are you OK?")
-- gotConfirmation (id, True)


type ConfirmationID
= ConfirmationID String


type alias EncodedConfirmationID =
String


newId : String -> ConfirmationID
newId id =
ConfirmationID id


port confirm : ( EncodedConfirmationID, String ) -> Cmd msg


port confirmations : (( EncodedConfirmationID, Bool ) -> msg) -> Sub msg


askForConfirmation : ConfirmationID -> String -> Cmd msg
askForConfirmation id message =
confirm ( encode id, message )


gotConfirmation : (( ConfirmationID, Bool ) -> msg) -> Sub msg
gotConfirmation msg =
confirmations (msg << decode)


encode : ConfirmationID -> EncodedConfirmationID
encode (ConfirmationID id) =
id


decode : ( EncodedConfirmationID, Bool ) -> ( ConfirmationID, Bool )
decode ( id, confirmed ) =
( ConfirmationID id, confirmed )
2 changes: 1 addition & 1 deletion gui/elm/Data/UserAlert.elm
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ buttonClass bType =
[ "c-btn--secondary" ]

PrimaryWithDanger ->
[ "c-btn--danger-outline" ]
[ "c-btn--danger" ]

SecondaryWithDanger ->
[ "c-btn--danger-outline" ]
Expand Down
8 changes: 8 additions & 0 deletions gui/elm/Ports.elm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ port module Ports exposing
, quitAndInstall
, registerRemote
, registrationError
, reinitialization
, reinitializeSynchronization
, remove
, sendMail
, showHelp
Expand Down Expand Up @@ -109,4 +111,10 @@ port transfer : (EncodedFile -> msg) -> Sub msg
port unlinkCozy : () -> Cmd msg


port reinitializeSynchronization : () -> Cmd msg


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


port manualStartSync : () -> Cmd msg
2 changes: 1 addition & 1 deletion gui/elm/Window/Help.elm
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ view helpers model =
]
, textarea [ onInput FillBody ] [ text (bodyOrDefault helpers model) ]
, a
[ class "btn btn--msg"
[ class "c-btn c-btn--full"
, href "#"
, if model.status == Sending then
attribute "aria-busy" "true"
Expand Down
2 changes: 1 addition & 1 deletion gui/elm/Window/Onboarding/Address.elm
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ view helpers context =
, text (helpers.t "Address Example After")
]
, a
[ class "btn"
[ class "c-btn c-btn--full u-mt-1"
, href "#"
, if context.addressConfig.address == "" then
attribute "disabled" "true"
Expand Down
2 changes: 1 addition & 1 deletion gui/elm/Window/Onboarding/Folder.elm
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ view helpers context =
-- TODO: Show different error messages?
]
, a
[ class "btn u-mt-2"
[ class "c-btn c-btn--full u-mt-2"
, href "#"
, if isValid context.folderConfig then
onClick StartSync
Expand Down
2 changes: 1 addition & 1 deletion gui/elm/Window/Onboarding/Welcome.elm
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ view helpers context =
[ Icons.cozyBig
, h1 [] [ text (helpers.t "Welcome Your own private cloud") ]
, a
[ class "btn"
[ class "c-btn c-btn--full"
, href "#"
, onClick NextPage
]
Expand Down
29 changes: 28 additions & 1 deletion gui/elm/Window/Tray.elm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Window.Tray exposing
, view
)

import Data.Confirmation as Confirmation exposing (ConfirmationID)
import Data.Platform exposing (Platform)
import Data.Status as Status exposing (Status)
import Data.SyncConfig as SyncConfig exposing (SyncConfig)
Expand Down Expand Up @@ -61,6 +62,7 @@ init version platform =
type Msg
= GotSyncState SyncState
| GotSyncConfig SyncConfig
| GotConfirmation ( ConfirmationID, Bool )
| GoToCozy
| GoToFolder
| GoToTab Page
Expand Down Expand Up @@ -104,13 +106,36 @@ update msg model =
in
( { model | page = DashboardPage, settings = settings }, Cmd.none )

GotConfirmation ( id, confirmed ) ->
let
( settings, cmd ) =
Settings.update (Settings.ReinitializationConfirmed ( id, confirmed )) model.settings
in
( { model | settings = settings }, Cmd.map SettingsMsg cmd )

DashboardMsg subMsg ->
let
( dashboard, cmd ) =
Dashboard.update subMsg model.dashboard
in
( { model | dashboard = dashboard }, cmd )

SettingsMsg (Settings.GotReinitializationStatus "started") ->
let
( settings, cmd ) =
Settings.update (Settings.GotReinitializationStatus "started") model.settings

( dashboard, _ ) =
Dashboard.update Dashboard.Reset model.dashboard
in
( { model
| page = DashboardPage
, dashboard = dashboard
, settings = settings
}
, Cmd.map SettingsMsg cmd
)

SettingsMsg subMsg ->
let
( settings, cmd ) =
Expand All @@ -127,7 +152,7 @@ update msg model =
GoToTab tab ->
let
( dashboard, cmd ) =
Dashboard.update Dashboard.Reset model.dashboard
Dashboard.update Dashboard.ShowFirstPage model.dashboard
in
( { model | page = tab, dashboard = dashboard }, cmd )

Expand All @@ -152,6 +177,7 @@ subscriptions model =
[ SyncConfig.gotSyncConfig GotSyncConfig
, Ports.gototab GoToStrTab
, SyncState.gotNewState GotSyncState
, Confirmation.gotConfirmation GotConfirmation

-- Dashboard subscriptions
, Time.every 1000 (DashboardMsg << Dashboard.Tick)
Expand All @@ -163,6 +189,7 @@ subscriptions model =
, Settings.gotDiskSpace (SettingsMsg << Settings.UpdateDiskSpace)
, Ports.autolaunch (SettingsMsg << Settings.AutoLaunchSet)
, Ports.cancelUnlink (always (SettingsMsg Settings.CancelUnlink))
, Ports.reinitialization (SettingsMsg << Settings.GotReinitializationStatus)
]


Expand Down
42 changes: 32 additions & 10 deletions gui/elm/Window/Tray/Dashboard.elm
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import I18n exposing (Helpers)
import Icons
import Json.Decode as Json
import Ports
import Time
Expand Down Expand Up @@ -70,6 +71,7 @@ type Msg
| ShowMore
| ShowHelp
| Reset
| ShowFirstPage
| GotUserAlerts (List UserAlert)
| SendActionCommand UserAlert.Command UserAlert
| UserAlertSkipped UserAlert
Expand Down Expand Up @@ -118,7 +120,7 @@ update msg model =
ShowHelp ->
( model, Ports.showHelp () )

Reset ->
ShowFirstPage ->
( { model | page = 1 }, Cmd.none )

GotUserAlerts alerts ->
Expand All @@ -139,6 +141,9 @@ update msg model =
UserAlertDetails alert ->
( model, UserAlert.showDetails alert )

Reset ->
( { model | page = 1, files = [], userAlerts = [] }, Cmd.none )



-- VIEW
Expand Down Expand Up @@ -258,21 +263,38 @@ view helpers model =

filesToRender =
List.take nbFiles model.files

hasMoreFiles =
List.length model.files > nbFiles
in
section [ class "two-panes__content two-panes__content--dashboard" ]
[ viewAlerts helpers model
, div [ class "recent-files" ]
(List.map renderLine filesToRender
++ (if List.length model.files > nbFiles then
[ showMoreButton helpers ]

else
[]
)
)
, case filesToRender of
[] ->
viewEmptyFileList

_ ->
viewRecentFileList helpers filesToRender renderLine hasMoreFiles
]


viewEmptyFileList : Html Msg
viewEmptyFileList =
div [ class "recent-files recent-files--empty" ]
[ Icons.logo
, h1 [] [ text "This list is empty" ]
, p [] [ text "Files recently synchronized will show up here" ]
]


viewRecentFileList : Helpers -> List File -> (File -> Html Msg) -> Bool -> Html Msg
viewRecentFileList helpers files renderLine hasMoreFiles =
div [ class "recent-files" ]
(List.map renderLine files
++ [ viewIf hasMoreFiles (showMoreButton helpers) ]
)



--HELPERS

Expand Down
Loading

0 comments on commit 4b3897e

Please sign in to comment.