mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-05 22:55:58 +00:00
Fix initial loading notify form
This commit is contained in:
parent
93182c040e
commit
2042824ab4
@ -325,7 +325,6 @@ initPage model page =
|
|||||||
UserSettingPage ->
|
UserSettingPage ->
|
||||||
Util.Update.andThen1
|
Util.Update.andThen1
|
||||||
[ updateQueue Page.Queue.Data.StopRefresh
|
[ updateQueue Page.Queue.Data.StopRefresh
|
||||||
, updateUserSettings Page.UserSettings.Data.Init
|
|
||||||
]
|
]
|
||||||
model
|
model
|
||||||
|
|
||||||
|
@ -40,8 +40,8 @@ type alias Model =
|
|||||||
, enabled : Bool
|
, enabled : Bool
|
||||||
, schedule : Validated CalEvent
|
, schedule : Validated CalEvent
|
||||||
, scheduleModel : Comp.CalEventInput.Model
|
, scheduleModel : Comp.CalEventInput.Model
|
||||||
, formError : Maybe String
|
, formMsg : Maybe BasicResult
|
||||||
, submitResp : Maybe BasicResult
|
, loading : Int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -93,8 +93,8 @@ init flags =
|
|||||||
, enabled = False
|
, enabled = False
|
||||||
, schedule = initialSchedule
|
, schedule = initialSchedule
|
||||||
, scheduleModel = sm
|
, scheduleModel = sm
|
||||||
, formError = Nothing
|
, formMsg = Nothing
|
||||||
, submitResp = Nothing
|
, loading = 3
|
||||||
}
|
}
|
||||||
, Cmd.batch
|
, Cmd.batch
|
||||||
[ initCmd flags
|
[ initCmd flags
|
||||||
@ -103,6 +103,10 @@ init flags =
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
--- Update
|
||||||
|
|
||||||
|
|
||||||
makeSettings : Model -> Validated NotificationSettings
|
makeSettings : Model -> Validated NotificationSettings
|
||||||
makeSettings model =
|
makeSettings model =
|
||||||
let
|
let
|
||||||
@ -194,9 +198,13 @@ update flags msg model =
|
|||||||
in
|
in
|
||||||
( { model
|
( { model
|
||||||
| connectionModel = cm
|
| connectionModel = cm
|
||||||
, formError =
|
, loading = model.loading - 1
|
||||||
|
, formMsg =
|
||||||
if names == [] then
|
if names == [] then
|
||||||
Just "No E-Mail connections configured. Goto E-Mail Settings to add one."
|
Just
|
||||||
|
(BasicResult False
|
||||||
|
"No E-Mail connections configured. Goto E-Mail Settings to add one."
|
||||||
|
)
|
||||||
|
|
||||||
else
|
else
|
||||||
Nothing
|
Nothing
|
||||||
@ -205,7 +213,12 @@ update flags msg model =
|
|||||||
)
|
)
|
||||||
|
|
||||||
ConnResp (Err err) ->
|
ConnResp (Err err) ->
|
||||||
( { model | formError = Just (Util.Http.errorToString err) }, Cmd.none )
|
( { model
|
||||||
|
| formMsg = Just (BasicResult False (Util.Http.errorToString err))
|
||||||
|
, loading = model.loading - 1
|
||||||
|
}
|
||||||
|
, Cmd.none
|
||||||
|
)
|
||||||
|
|
||||||
TagIncMsg m ->
|
TagIncMsg m ->
|
||||||
let
|
let
|
||||||
@ -234,10 +247,12 @@ update flags msg model =
|
|||||||
[ update flags (TagIncMsg tagList)
|
[ update flags (TagIncMsg tagList)
|
||||||
, update flags (TagExcMsg tagList)
|
, update flags (TagExcMsg tagList)
|
||||||
]
|
]
|
||||||
model
|
{ model | loading = model.loading - 1 }
|
||||||
|
|
||||||
GetTagsResp (Err _) ->
|
GetTagsResp (Err _) ->
|
||||||
( model, Cmd.none )
|
( { model | loading = model.loading - 1 }
|
||||||
|
, Cmd.none
|
||||||
|
)
|
||||||
|
|
||||||
RemindDaysMsg m ->
|
RemindDaysMsg m ->
|
||||||
let
|
let
|
||||||
@ -278,6 +293,7 @@ update flags msg model =
|
|||||||
, enabled = s.enabled
|
, enabled = s.enabled
|
||||||
, schedule = Data.Validated.Unknown newSchedule
|
, schedule = Data.Validated.Unknown newSchedule
|
||||||
, scheduleModel = sm
|
, scheduleModel = sm
|
||||||
|
, loading = model.loading - 1
|
||||||
}
|
}
|
||||||
, Cmd.batch
|
, Cmd.batch
|
||||||
[ nc
|
[ nc
|
||||||
@ -286,12 +302,17 @@ update flags msg model =
|
|||||||
)
|
)
|
||||||
|
|
||||||
SetNotificationSettings (Err err) ->
|
SetNotificationSettings (Err err) ->
|
||||||
( { model | formError = Just (Util.Http.errorToString err) }, Cmd.none )
|
( { model
|
||||||
|
| formMsg = Just (BasicResult False (Util.Http.errorToString err))
|
||||||
|
, loading = model.loading - 1
|
||||||
|
}
|
||||||
|
, Cmd.none
|
||||||
|
)
|
||||||
|
|
||||||
Submit ->
|
Submit ->
|
||||||
case makeSettings model of
|
case makeSettings model of
|
||||||
Valid set ->
|
Valid set ->
|
||||||
( { model | formError = Nothing }
|
( { model | formMsg = Nothing }
|
||||||
, Api.submitNotifyDueItems flags set SubmitResp
|
, Api.submitNotifyDueItems flags set SubmitResp
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -300,46 +321,64 @@ update flags msg model =
|
|||||||
errMsg =
|
errMsg =
|
||||||
String.join ", " errs
|
String.join ", " errs
|
||||||
in
|
in
|
||||||
( { model | formError = Just errMsg }, Cmd.none )
|
( { model | formMsg = Just (BasicResult False errMsg) }, Cmd.none )
|
||||||
|
|
||||||
Unknown _ ->
|
Unknown _ ->
|
||||||
( { model | formError = Just "An unknown error occured" }, Cmd.none )
|
( { model | formMsg = Just (BasicResult False "An unknown error occured") }
|
||||||
|
, Cmd.none
|
||||||
|
)
|
||||||
|
|
||||||
SubmitResp (Ok res) ->
|
SubmitResp (Ok res) ->
|
||||||
( { model | submitResp = Just res, formError = Nothing }
|
( { model | formMsg = Just res }
|
||||||
, Cmd.none
|
, Cmd.none
|
||||||
)
|
)
|
||||||
|
|
||||||
SubmitResp (Err err) ->
|
SubmitResp (Err err) ->
|
||||||
( { model
|
( { model
|
||||||
| formError = Nothing
|
| formMsg = Just (BasicResult False (Util.Http.errorToString err))
|
||||||
, submitResp = Just (BasicResult False (Util.Http.errorToString err))
|
|
||||||
}
|
}
|
||||||
, Cmd.none
|
, Cmd.none
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
--- View
|
||||||
|
|
||||||
|
|
||||||
|
isFormError : Model -> Bool
|
||||||
|
isFormError model =
|
||||||
|
Maybe.map .success model.formMsg
|
||||||
|
|> Maybe.map not
|
||||||
|
|> Maybe.withDefault False
|
||||||
|
|
||||||
|
|
||||||
|
isFormSuccess : Model -> Bool
|
||||||
|
isFormSuccess model =
|
||||||
|
Maybe.map .success model.formMsg
|
||||||
|
|> Maybe.withDefault False
|
||||||
|
|
||||||
|
|
||||||
view : String -> Model -> Html Msg
|
view : String -> Model -> Html Msg
|
||||||
view extraClasses model =
|
view extraClasses model =
|
||||||
div
|
div
|
||||||
[ classList
|
[ classList
|
||||||
[ ( "ui form", True )
|
[ ( "ui form", True )
|
||||||
, ( extraClasses, True )
|
, ( extraClasses, True )
|
||||||
, ( "error"
|
, ( "error", isFormError model )
|
||||||
, model.formError
|
, ( "success", isFormSuccess model )
|
||||||
/= Nothing
|
|
||||||
|| (Maybe.map .success model.submitResp
|
|
||||||
|> Maybe.map not
|
|
||||||
|> Maybe.withDefault False
|
|
||||||
)
|
|
||||||
)
|
|
||||||
, ( "success"
|
|
||||||
, Maybe.map .success model.submitResp
|
|
||||||
|> Maybe.withDefault False
|
|
||||||
)
|
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
[ div [ class "inline field" ]
|
[ div
|
||||||
|
[ classList
|
||||||
|
[ ( "ui dimmer", True )
|
||||||
|
, ( "active", model.loading > 0 )
|
||||||
|
]
|
||||||
|
]
|
||||||
|
[ div [ class "ui text loader" ]
|
||||||
|
[ text "Loading..."
|
||||||
|
]
|
||||||
|
]
|
||||||
|
, div [ class "inline field" ]
|
||||||
[ div [ class "ui checkbox" ]
|
[ div [ class "ui checkbox" ]
|
||||||
[ input
|
[ input
|
||||||
[ type_ "checkbox"
|
[ type_ "checkbox"
|
||||||
@ -415,13 +454,9 @@ view extraClasses model =
|
|||||||
]
|
]
|
||||||
, div [ class "ui divider" ] []
|
, div [ class "ui divider" ] []
|
||||||
, div [ class "ui error message" ]
|
, div [ class "ui error message" ]
|
||||||
[ case Maybe.map .message model.submitResp of
|
[ Maybe.map .message model.formMsg
|
||||||
Just txt ->
|
|> Maybe.withDefault ""
|
||||||
text txt
|
|> text
|
||||||
|
|
||||||
Nothing ->
|
|
||||||
Maybe.withDefault "" model.formError
|
|
||||||
|> text
|
|
||||||
]
|
]
|
||||||
, div [ class "ui success message" ]
|
, div [ class "ui success message" ]
|
||||||
[ text "Successfully saved."
|
[ text "Successfully saved."
|
||||||
|
@ -39,4 +39,3 @@ type Msg
|
|||||||
| ChangePassMsg Comp.ChangePasswordForm.Msg
|
| ChangePassMsg Comp.ChangePasswordForm.Msg
|
||||||
| EmailSettingsMsg Comp.EmailSettingsManage.Msg
|
| EmailSettingsMsg Comp.EmailSettingsManage.Msg
|
||||||
| NotificationMsg Comp.NotificationForm.Msg
|
| NotificationMsg Comp.NotificationForm.Msg
|
||||||
| Init
|
|
||||||
|
@ -10,14 +10,6 @@ import Page.UserSettings.Data exposing (..)
|
|||||||
update : Flags -> Msg -> Model -> ( Model, Cmd Msg )
|
update : Flags -> Msg -> Model -> ( Model, Cmd Msg )
|
||||||
update flags msg model =
|
update flags msg model =
|
||||||
case msg of
|
case msg of
|
||||||
Init ->
|
|
||||||
let
|
|
||||||
cmd =
|
|
||||||
Cmd.map NotificationMsg
|
|
||||||
(Tuple.second (Comp.NotificationForm.init flags))
|
|
||||||
in
|
|
||||||
( model, cmd )
|
|
||||||
|
|
||||||
SetTab t ->
|
SetTab t ->
|
||||||
let
|
let
|
||||||
m =
|
m =
|
||||||
|
@ -27,6 +27,9 @@
|
|||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
.calevent-input .datetime.separator {
|
||||||
|
margin: 0 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
.default-layout .right-float {
|
.default-layout .right-float {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user