Skip to content

Commit

Permalink
ui: minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
azimut committed Apr 4, 2024
1 parent aa58fee commit ed90a06
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions frontend/src/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type alias Entry =
type State
= Starting
| Idle
| WaitingForSearch
| WaitingForResults
| ShowingResults


Expand Down Expand Up @@ -133,8 +133,8 @@ init _ =
)


newEntry : NewEntry -> Entry
newEntry { id, feedid, title, date, url } =
toEntry : NewEntry -> Entry
toEntry { id, feedid, title, date, url } =
{ id = id
, feedid = feedid
, title = title
Expand All @@ -151,10 +151,10 @@ toFeed { id, title, nEntries } =


toggleEntryDetails : Int -> List Entry -> List Entry
toggleEntryDetails id =
toggleEntryDetails entryId =
List.map
(\entry ->
if entry.id == id then
if entry.id == entryId then
{ entry | isShowingDetails = not entry.isShowingDetails }

else
Expand Down Expand Up @@ -182,10 +182,13 @@ fillDetails eDetails =


update : Msg -> Model -> ( Model, Cmd msg )
update msg ({ feeds, entries, search, now, state } as model) =
update msg ({ feeds, entries, search, state } as model) =
case msg of
InitFeeds iFeeds ->
( Model (List.map toFeed iFeeds) Dict.empty "" 0 Idle now
( { model
| feeds = List.map toFeed iFeeds
, state = Idle
}
, Cmd.none
)

Expand All @@ -211,7 +214,7 @@ update msg ({ feeds, entries, search, now, state } as model) =
( model, Cmd.none )

else
( { model | state = WaitingForSearch }, askForSearch search )
( { model | state = WaitingForResults }, askForSearch search )

NewSearchResults es ->
( newSearchResults model es, Cmd.none )
Expand All @@ -231,7 +234,7 @@ update msg ({ feeds, entries, search, now, state } as model) =
model

entry :: _ ->
{ model | entries = Dict.insert entry.feedid (List.map newEntry es) entries }
{ model | entries = Dict.insert entry.feedid (List.map toEntry es) entries }
, Cmd.none
)

Expand Down Expand Up @@ -295,7 +298,7 @@ newSearchResults model nEntries =
)
)
Dict.empty
(List.map newEntry nEntries)
(List.map toEntry nEntries)
in
{ model | feeds = feeds, entries = entries, state = ShowingResults }

Expand Down Expand Up @@ -442,7 +445,7 @@ view { feeds, entries, search, state, now } =
, viewFooter
]

WaitingForSearch ->
WaitingForResults ->
div []
[ viewHeader search
, div [ class "loader" ]
Expand Down

0 comments on commit ed90a06

Please sign in to comment.