Skip to content

Commit 5de9857

Browse files
committed
API integration for changing notification status
1 parent 80c8170 commit 5de9857

File tree

2 files changed

+65
-19
lines changed

2 files changed

+65
-19
lines changed

src/UnisonShare/Api.elm

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,22 @@ notifications account status paginationCursor =
212212
}
213213

214214

215+
updateNotificationStatuses : Account a -> List String -> NotificationStatus -> Endpoint
216+
updateNotificationStatuses account notificationIds status =
217+
let
218+
body =
219+
Encode.object
220+
[ ( "notificationIds", Encode.list Encode.string notificationIds )
221+
, ( "status", Encode.string (Notification.statusToString status) )
222+
]
223+
in
224+
PATCH
225+
{ path = [ "users", UserHandle.toUnprefixedString account.handle, "notifications", "hub" ]
226+
, queryParams = []
227+
, body = Http.jsonBody body
228+
}
229+
230+
215231

216232
-- ORGS
217233
-- ORG ROLE ASSIGNMENTS (COLLABORATORS)

src/UnisonShare/Page/NotificationsPage.elm

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Html exposing (Html, div, footer, h1, h2, h4, span, strong, text)
66
import Html.Attributes exposing (class, classList)
77
import Json.Decode as Decode exposing (string)
88
import Json.Decode.Pipeline exposing (optional, required)
9-
import Lib.HttpApi as HttpApi
9+
import Lib.HttpApi as HttpApi exposing (HttpResult)
1010
import RemoteData exposing (RemoteData(..), WebData)
1111
import Set exposing (Set)
1212
import UI
@@ -105,9 +105,13 @@ type Msg
105105
| FetchAllNotificationsFinished (WebData PaginatedNotifications)
106106
| ToggleSelection Notification
107107
| MarkSelectionAsUnread
108+
| MarkNotificationsAsUnreadFinished (HttpResult ())
108109
| MarkSelectionAsRead
110+
| MarkNotificationsAsReadFinished (HttpResult ())
109111
| ArchiveSelection
112+
| MarkNotificationsAsArchivedFinished (HttpResult ())
110113
| UnarchiveSelection
114+
| MarkNotificationsAsUnarchivedFinished (HttpResult ())
111115

112116

113117
update : AppContext -> NotificationsRoute -> Account a -> Msg -> Model -> ( Model, Cmd Msg )
@@ -233,24 +237,50 @@ fetchNotifications_ appContext account status paginationCursorParam =
233237
|> HttpApi.perform appContext.api
234238

235239

236-
markNotificationsAsRead : AppContext -> Account a -> Cmd Msg
237-
markNotificationsAsRead _ _ =
238-
Cmd.none
239-
240-
241-
markNotificationsAsUnread : AppContext -> Account a -> Cmd Msg
242-
markNotificationsAsUnread _ _ =
243-
Cmd.none
244-
245-
246-
archiveNotifications : AppContext -> Account a -> Cmd Msg
247-
archiveNotifications _ _ =
248-
Cmd.none
249-
250-
251-
unarchiveNotifications : AppContext -> Account a -> Cmd Msg
252-
unarchiveNotifications _ _ =
253-
Cmd.none
240+
markNotificationsAsRead : AppContext -> Account a -> List String -> Cmd Msg
241+
markNotificationsAsRead appContext account notificationIds =
242+
updateNotificationStatuses
243+
MarkNotificationsAsReadFinished
244+
appContext
245+
account
246+
notificationIds
247+
Notification.Read
248+
249+
250+
markNotificationsAsUnread : AppContext -> Account a -> List String -> Cmd Msg
251+
markNotificationsAsUnread appContext account notificationIds =
252+
updateNotificationStatuses
253+
MarkNotificationsAsUnreadFinished
254+
appContext
255+
account
256+
notificationIds
257+
Notification.Unread
258+
259+
260+
archiveNotifications : AppContext -> Account a -> List String -> Cmd Msg
261+
archiveNotifications appContext account notificationIds =
262+
updateNotificationStatuses
263+
MarkNotificationsAsArchivedFinished
264+
appContext
265+
account
266+
notificationIds
267+
Notification.Archived
268+
269+
270+
unarchiveNotifications : AppContext -> Account a -> List String -> Cmd Msg
271+
unarchiveNotifications appContext account notificationIds =
272+
updateNotificationStatuses MarkNotificationsAsUnarchivedFinished
273+
appContext
274+
account
275+
notificationIds
276+
Notification.Unread
277+
278+
279+
updateNotificationStatuses : (HttpResult () -> Msg) -> AppContext -> Account a -> List String -> Notification.NotificationStatus -> Cmd Msg
280+
updateNotificationStatuses toMsg appContext account notificationIds status =
281+
ShareApi.updateNotificationStatuses account notificationIds status
282+
|> HttpApi.toRequestWithEmptyResponse toMsg
283+
|> HttpApi.perform appContext.api
254284

255285

256286

0 commit comments

Comments
 (0)