on master help sign in
Clear notification after 15 seconds
commitd539085806a73e33e96e832208caf6a258d91e8b authoriko <ilyakooo0@gmail.com> dateSat 6 Aug 2022, 14:52 (4 years ago) parent13661d3
2 files changed+57−36
backend/Main.purs+1−1 frontend/Main.elm+56−35
backend/Main.purs+1−1
@@ -160,7 +160,7 @@ main = do
160160 send $ Bridge.Error "The password is wrong. Please try again."
161161 requestMasterPassword
162162 Bridge.Init -> do
163− liftEffect $ Storage.get storage TokenKey
163+ Storage.get storage TokenKey
164164 >>= \x ->
165165 Elm.send app case x of
166166 Just _ -> Bridge.LoginSuccessful
frontend/Main.elm+56−35
@@ -14,9 +14,16 @@ import Pages.Loader exposing (loader)
1414import Pages.Login as Login
1515import Pages.MasterPassword as MasterPassword
1616import Pages.Navigation as Navigation exposing (TopButton(..))
17+import Task
18+import Time
1719import Utils exposing (..)
1820
1921
22+notificationLingerSeconds : Int
23+notificationLingerSeconds =
24+ 15
25+
26+
2027type Msg
2128 = RecieveMessage String
2229 | ShowLoginPage
@@ -41,6 +48,8 @@ type Msg
4148 | Open String
4249 | CaptchaMsg Captcha.Msg
4350 | ShowCaptcha Captcha.HCaptchSiteKey
51+ | ClearNotification { currentTime : Time.Posix }
52+ | UpdateLastNotificatioTime Time.Posix
4453
4554
4655type alias CipherId =
@@ -51,12 +60,13 @@ type alias Model =
5160 { notifications : List Notification.Config
5261 , pageStack : Navigation.PageStack PageModel
5362 , userEmail : Maybe String
63+ , lastNotificationTime : Time.Posix
5464 }
5565
5666
57−appendNotification : Notification.Config -> Model -> Model
67+appendNotification : Notification.Config -> Model -> ( Model, Cmd Msg )
5868appendNotification cfg model =
59− { model | notifications = cfg :: model.notifications }
69+ ( { model | notifications = cfg :: model.notifications }, Task.perform UpdateLastNotificatioTime Time.now )
6070
6171
6272type PageModel
@@ -150,39 +160,43 @@ main =
150160
151161
152162subscriptions : Model -> Sub Msg
153−subscriptions _ =
154− getBridge ShowError
155− (\msg ->
156− case msg of
157− Bridge.NeedsLogin ->
158− ShowLoginPage
163+subscriptions model =
164+ Sub.batch
165+ ([ getBridge ShowError
166+ (\msg ->
167+ case msg of
168+ Bridge.NeedsLogin ->
169+ ShowLoginPage
159170
160− Bridge.Error err ->
161− ShowError err
171+ Bridge.Error err ->
172+ ShowError err
162173
163− Bridge.LoadCiphers ciphers ->
164− LoadCiphers ciphers
174+ Bridge.LoadCiphers ciphers ->
175+ LoadCiphers ciphers
165176
166− Bridge.LoginSuccessful ->
167− OpenCiphersScreen
177+ Bridge.LoginSuccessful ->
178+ OpenCiphersScreen
168179
169− Bridge.Reset ->
170− Reset
180+ Bridge.Reset ->
181+ Reset
171182
172− Bridge.NeedsMasterPassword { server, login } ->
173− ShowMasterPasswordPage { server = server, login = login }
183+ Bridge.NeedsMasterPassword { server, login } ->
184+ ShowMasterPasswordPage { server = server, login = login }
174185
175− Bridge.LoadCipher cipher ->
176− ShowCipherPage cipher
186+ Bridge.LoadCipher cipher ->
187+ ShowCipherPage cipher
177188
178− Bridge.RecieveEmail email ->
179− RecieveEmail email
189+ Bridge.RecieveEmail email ->
190+ RecieveEmail email
180191
181− Bridge.NeedsCaptcha uri ->
182− ShowCaptcha uri
192+ Bridge.NeedsCaptcha uri ->
193+ ShowCaptcha uri
183194
184− Bridge.CaptchaDone ->
185− PopView
195+ Bridge.CaptchaDone ->
196+ PopView
197+ )
198+ ]
199+ ++ optional (List.isEmpty model.notifications |> not) (Time.every 1000 (\t -> ClearNotification { currentTime = t }))
186200 )
187201
188202
@@ -191,6 +205,7 @@ init =
191205 ( { notifications = []
192206 , pageStack = Nonempty.singleton LoadingPage
193207 , userEmail = Nothing
208+ , lastNotificationTime = Time.millisToPosix 0
194209 }
195210 , FFI.sendBridge Bridge.Init
196211 )
@@ -235,14 +250,12 @@ update msg model =
235250 ( { model | pageStack = mapHead (always (liftModel mdl)) model.pageStack }, cmd )
236251
237252 Err err ->
238− ( appendNotification
253+ appendNotification
239254 { title = "An error had occured"
240255 , message = err
241256 , severity = Notification.Error
242257 }
243258 model
244− , cmd
245− )
246259
247260 appendPageStack : PageModel -> Model
248261 appendPageStack mdl =
@@ -257,24 +270,20 @@ update msg model =
257270 in
258271 case msg of
259272 RecieveMessage x ->
260− ( appendNotification
273+ appendNotification
261274 { title = "Got a message!"
262275 , message = x
263276 , severity = Notification.Info
264277 }
265278 model
266− , Cmd.none
267− )
268279
269280 ShowError err ->
270− ( appendNotification
281+ appendNotification
271282 { title = "Something went wrong"
272283 , message = err
273284 , severity = Notification.Error
274285 }
275286 model
276− , Cmd.none
277− )
278287
279288 CloseNotification ->
280289 ( { model | notifications = tailEmpty model.notifications }
@@ -375,6 +384,18 @@ update msg model =
375384 _ ->
376385 ( model, Cmd.none )
377386
387+ ClearNotification { currentTime } ->
388+ if Time.posixToMillis model.lastNotificationTime + notificationLingerSeconds * 1000 > Time.posixToMillis currentTime then
389+ ( model, Cmd.none )
390+
391+ else
392+ ( { model | notifications = List.tail model.notifications |> Maybe.withDefault [] }
393+ , Task.perform UpdateLastNotificatioTime Time.now
394+ )
395+
396+ UpdateLastNotificatioTime time ->
397+ ( { model | lastNotificationTime = time }, Cmd.none )
398+
378399
379400loginCallbacks : Login.Callbacks Msg
380401loginCallbacks =