Skip to content

Commit

Permalink
Confirm removal of feed
Browse files Browse the repository at this point in the history
  • Loading branch information
cruessler committed Oct 29, 2023
1 parent 673ba80 commit a81381f
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 4 deletions.
24 changes: 23 additions & 1 deletion assets/elm/app/App/Feeds.elm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Http
import Json.Encode as E
import Paths
import Request exposing (Request(..))
import Set
import String
import Task
import Time
Expand Down Expand Up @@ -45,6 +46,7 @@ init flags =
, filterBy = DontFilter
, sortBy = SortByNewestUnread
, feeds = Dict.empty
, confirmRemoveFeeds = Set.empty
, showOptions = False
, discoveryUrl = ""
, requests = Dict.empty
Expand Down Expand Up @@ -156,15 +158,35 @@ update msg model =
, Addition.post model.apiConfig candidate Msg.Addition
)

ConfirmRemoveFeed feed ->
let
id =
Feed.id feed
in
( { model | confirmRemoveFeeds = Set.insert id model.confirmRemoveFeeds }, Cmd.none )

CancelRemoveFeed feed ->
let
id =
Feed.id feed
in
( { model | confirmRemoveFeeds = Set.remove id model.confirmRemoveFeeds }, Cmd.none )

RemoveFeed feed ->
let
newRequests =
Dict.insert
(Feed.url feed)
(Model.Removal <| Request.InProgress feed)
model.requests

id =
Feed.id feed
in
( { model | requests = newRequests }
( { model
| requests = newRequests
, confirmRemoveFeeds = Set.remove id model.confirmRemoveFeeds
}
, Removal.delete model.apiConfig feed Msg.Removal
)

Expand Down
1 change: 1 addition & 0 deletions assets/elm/app/App/NewFeed.elm
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Msg
| RemoveRequest


main : Program Flags Model Msg
main =
Browser.element
{ init = init
Expand Down
2 changes: 2 additions & 0 deletions assets/elm/app/Feeds/Model.elm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Dict exposing (Dict)
import Feeds.Addition exposing (Addition)
import Feeds.Discovery exposing (Discovery)
import Feeds.Removal exposing (Removal)
import Set exposing (Set)
import Time
import Types.Feed exposing (Feed)

Expand Down Expand Up @@ -43,6 +44,7 @@ type alias Model =
, filterBy : FilterBy
, sortBy : SortBy
, feeds : Dict Int Feed
, confirmRemoveFeeds : Set Int
, showOptions : Bool
, discoveryUrl : String
, requests : Dict String Request
Expand Down
2 changes: 2 additions & 0 deletions assets/elm/app/Feeds/Msg.elm
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type Msg
| AddFeed Candidate
| RemoveResponse String
| ToggleFeed Feed
| ConfirmRemoveFeed Feed
| CancelRemoveFeed Feed
| RemoveFeed Feed
| MarkAsRead Entry
| MarkFeedAsRead Feed
Expand Down
21 changes: 18 additions & 3 deletions assets/elm/app/Feeds/View.elm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Feeds.Options as Options
import Html as H exposing (Html)
import Html.Attributes as A
import Html.Events as E
import Set
import Time
import Types.Feed as Feed exposing (..)

Expand Down Expand Up @@ -154,11 +155,25 @@ viewFeed model feed =
feed_ =
H.ul [ A.class "feed" ] (List.map (viewEntry model.timezone) entries)

id =
Feed.id feed

removeAction =
if Set.member id model.confirmRemoveFeeds then
[ H.button [ E.onClick (RemoveFeed feed) ] [ H.text "Confirm removal" ]
, H.button [ E.onClick (CancelRemoveFeed feed) ] [ H.text "Cancel" ]
]

else
[ H.button [ E.onClick (ConfirmRemoveFeed feed) ] [ H.text "Remove" ] ]

actions =
H.div [ A.class "actions" ]
[ H.button [ E.onClick (RemoveFeed feed) ] [ H.text "Remove" ]
, H.button [ E.onClick (MarkFeedAsRead feed) ] [ H.text "Mark as read" ]
]
(List.concat
[ removeAction
, [ H.button [ E.onClick (MarkFeedAsRead feed) ] [ H.text "Mark as read" ] ]
]
)

children =
[ H.h1 [ E.onClick (ToggleFeed feed) ] [ H.text <| Feed.title feed ]
Expand Down

0 comments on commit a81381f

Please sign in to comment.