Use search stats to populate search menu

This commit is contained in:
eikek
2021-10-05 10:27:21 +02:00
parent e52271f9cd
commit e961a5ac10
14 changed files with 257 additions and 55 deletions

View File

@@ -9,6 +9,7 @@ module Page.Share.Data exposing (Mode(..), Model, Msg(..), PageError(..), init)
import Api
import Api.Model.ItemLightList exposing (ItemLightList)
import Api.Model.SearchStats exposing (SearchStats)
import Api.Model.ShareSecret exposing (ShareSecret)
import Api.Model.ShareVerifyResult exposing (ShareVerifyResult)
import Comp.ItemCardList
@@ -41,7 +42,6 @@ type alias Model =
, verifyResult : ShareVerifyResult
, passwordModel : PasswordModel
, pageError : PageError
, items : ItemLightList
, searchMenuModel : Comp.SearchMenu.Model
, powerSearchInput : Comp.PowerSearchInput.Model
, searchInProgress : Bool
@@ -58,7 +58,6 @@ emptyModel flags =
, passwordFailed = False
}
, pageError = PageErrorNone
, items = Api.Model.ItemLightList.empty
, searchMenuModel = Comp.SearchMenu.init flags
, powerSearchInput = Comp.PowerSearchInput.init
, searchInProgress = False
@@ -79,6 +78,7 @@ init shareId flags =
type Msg
= VerifyResp (Result Http.Error ShareVerifyResult)
| SearchResp (Result Http.Error ItemLightList)
| StatsResp (Result Http.Error SearchStats)
| SetPassword String
| SubmitPassword
| SearchMenuMsg Comp.SearchMenu.Msg

View File

@@ -91,6 +91,16 @@ update flags settings shareId msg model =
SearchResp (Err err) ->
noSub ( { model | pageError = PageErrorHttp err, searchInProgress = False }, Cmd.none )
StatsResp (Ok stats) ->
update flags
settings
shareId
(SearchMenuMsg (Comp.SearchMenu.setFromStats stats))
model
StatsResp (Err err) ->
noSub ( { model | pageError = PageErrorHttp err }, Cmd.none )
SetPassword pw ->
let
pm =
@@ -191,8 +201,14 @@ makeSearchCmd flags model =
, query = Q.renderMaybe mq
, searchMode = Just (Data.SearchMode.asString Data.SearchMode.Normal)
}
searchCmd =
Api.searchShare flags model.verifyResult.token (request xq) SearchResp
statsCmd =
Api.searchShareStats flags model.verifyResult.token (request xq) StatsResp
in
Api.searchShare flags model.verifyResult.token (request xq) SearchResp
Cmd.batch [ searchCmd, statsCmd ]
linkTargetMsg : LinkTarget -> Maybe Msg