Merge pull request #339 from eikek/fix-detail-links

Fix detail links
This commit is contained in:
mergify[bot] 2020-10-18 19:53:26 +00:00 committed by GitHub
commit 5c9f214f80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 52 additions and 64 deletions

View File

@ -160,7 +160,7 @@ checkPage flags page =
defaultPage : Flags -> Page defaultPage : Flags -> Page
defaultPage flags = defaultPage flags =
if isSignedIn flags then if isSignedIn flags then
HomePage Nothing HomePage
else else
LoginPage Nothing LoginPage Nothing

View File

@ -31,6 +31,7 @@ import Page.UserSettings.Data
import Page.UserSettings.Update import Page.UserSettings.Update
import Ports import Ports
import Url import Url
import Util.Maybe
import Util.Update import Util.Update
@ -312,8 +313,8 @@ updateHome lmsg model =
let let
mid = mid =
case model.page of case model.page of
HomePage x -> HomePage ->
x Util.Maybe.fromString model.itemDetailModel.detail.item.id
_ -> _ ->
Nothing Nothing
@ -348,7 +349,7 @@ initPage model_ page =
{ model_ | page = page } { model_ | page = page }
in in
case page of case page of
HomePage _ -> HomePage ->
Util.Update.andThen2 Util.Update.andThen2
[ updateHome Page.Home.Data.Init [ updateHome Page.Home.Data.Init
, updateQueue Page.Queue.Data.StopRefresh , updateQueue Page.Queue.Data.StopRefresh

View File

@ -16,6 +16,7 @@ import Page.Queue.View
import Page.Register.View import Page.Register.View
import Page.Upload.View import Page.Upload.View
import Page.UserSettings.View import Page.UserSettings.View
import Util.Maybe
view : Model -> Html Msg view : Model -> Html Msg
@ -65,7 +66,7 @@ defaultLayout model =
[ div [ class "ui fluid container" ] [ div [ class "ui fluid container" ]
[ a [ a
[ class "header item narrow-item" [ class "header item narrow-item"
, Page.href (HomePage Nothing) , Page.href HomePage
] ]
[ img [ img
[ class "image" [ class "image"
@ -84,7 +85,7 @@ defaultLayout model =
, id "main-content" , id "main-content"
] ]
[ case model.page of [ case model.page of
HomePage _ -> HomePage ->
viewHome model viewHome model
LoginPage _ -> LoginPage _ ->
@ -180,8 +181,8 @@ viewHome model =
let let
mid = mid =
case model.page of case model.page of
HomePage x -> HomePage ->
x Util.Maybe.fromString model.itemDetailModel.detail.item.id
_ -> _ ->
Nothing Nothing
@ -218,7 +219,7 @@ loginInfo model =
] ]
] ]
[ menuEntry model [ menuEntry model
(HomePage Nothing) HomePage
[ img [ img
[ class "image icon" [ class "image icon"
, src (model.flags.config.docspellAssetPath ++ "/img/logo-mc-96.png") , src (model.flags.config.docspellAssetPath ++ "/img/logo-mc-96.png")

View File

@ -21,8 +21,8 @@ import Data.Items
import Data.UiSettings exposing (UiSettings) import Data.UiSettings exposing (UiSettings)
import Html exposing (..) import Html exposing (..)
import Html.Attributes exposing (..) import Html.Attributes exposing (..)
import Html.Events exposing (onClick)
import Markdown import Markdown
import Page exposing (Page(..))
import Util.ItemDragDrop as DD import Util.ItemDragDrop as DD
import Util.List import Util.List
import Util.String import Util.String
@ -37,7 +37,6 @@ type alias Model =
type Msg type Msg
= SetResults ItemLightList = SetResults ItemLightList
| AddResults ItemLightList | AddResults ItemLightList
| SelectItem ItemLight
| ItemDDMsg DD.Msg | ItemDDMsg DD.Msg
@ -63,19 +62,18 @@ prevItem model id =
--- Update --- Update
update : Flags -> Msg -> Model -> ( Model, Cmd Msg, Maybe ItemLight ) update : Flags -> Msg -> Model -> ( Model, Cmd Msg )
update flags msg model = update flags msg model =
let let
res = res =
updateDrag DD.init flags msg model updateDrag DD.init flags msg model
in in
( res.model, res.cmd, res.selected ) ( res.model, res.cmd )
type alias UpdateResult = type alias UpdateResult =
{ model : Model { model : Model
, cmd : Cmd Msg , cmd : Cmd Msg
, selected : Maybe ItemLight
, dragModel : DD.Model , dragModel : DD.Model
} }
@ -93,28 +91,25 @@ updateDrag dm _ msg model =
newModel = newModel =
{ model | results = list } { model | results = list }
in in
UpdateResult newModel Cmd.none Nothing dm UpdateResult newModel Cmd.none dm
AddResults list -> AddResults list ->
if list.groups == [] then if list.groups == [] then
UpdateResult model Cmd.none Nothing dm UpdateResult model Cmd.none dm
else else
let let
newModel = newModel =
{ model | results = Data.Items.concat model.results list } { model | results = Data.Items.concat model.results list }
in in
UpdateResult newModel Cmd.none Nothing dm UpdateResult newModel Cmd.none dm
SelectItem item ->
UpdateResult model Cmd.none (Just item) dm
ItemDDMsg lm -> ItemDDMsg lm ->
let let
ddd = ddd =
DD.update lm dm DD.update lm dm
in in
UpdateResult model Cmd.none Nothing ddd.model UpdateResult model Cmd.none ddd.model
@ -181,8 +176,7 @@ viewItem current settings item =
, ( "current", current == Just item.id ) , ( "current", current == Just item.id )
] ]
, id item.id , id item.id
, href "#" , Page.href (ItemDetailPage item.id)
, onClick (SelectItem item)
] ]
++ DD.draggable ItemDDMsg item.id ++ DD.draggable ItemDDMsg item.id
) )

View File

@ -632,7 +632,7 @@ update key flags inav settings msg model =
noSub ( model, Page.set key (ItemDetailPage id) ) noSub ( model, Page.set key (ItemDetailPage id) )
Nothing -> Nothing ->
noSub ( model, Page.set key (HomePage Nothing) ) noSub ( model, Page.set key HomePage )
else else
noSub ( model, Cmd.none ) noSub ( model, Cmd.none )

View File

@ -110,7 +110,7 @@ renderDetailMenu settings inav model =
) )
] ]
] ]
[ a [ class "item", Page.href (HomePage (Just model.item.id)) ] [ a [ class "item", Page.href HomePage ]
[ i [ class "arrow left icon" ] [] [ i [ class "arrow left icon" ] []
] ]
, a , a

View File

@ -11,7 +11,7 @@ import Data.UiSettings
import Html exposing (..) import Html exposing (..)
import Html.Attributes exposing (..) import Html.Attributes exposing (..)
import Html.Events exposing (..) import Html.Events exposing (..)
import Page import Page exposing (Page(..))
import Ports import Ports
import Url exposing (Url) import Url exposing (Url)
@ -73,7 +73,16 @@ init flags url key =
viewDoc : Model -> Document Msg viewDoc : Model -> Document Msg
viewDoc model = viewDoc model =
{ title = model.flags.config.appName ++ ": " ++ Page.pageName model.page let
title =
case model.page of
ItemDetailPage _ ->
model.itemDetailModel.detail.item.name
_ ->
Page.pageName model.page
in
{ title = model.flags.config.appName ++ ": " ++ title
, body = [ view model ] , body = [ view model ]
} }

View File

@ -24,7 +24,7 @@ import Util.Maybe
type Page type Page
= HomePage (Maybe String) = HomePage
| LoginPage (Maybe Page) | LoginPage (Maybe Page)
| ManageDataPage | ManageDataPage
| CollectiveSettingPage | CollectiveSettingPage
@ -39,7 +39,7 @@ type Page
isSecured : Page -> Bool isSecured : Page -> Bool
isSecured page = isSecured page =
case page of case page of
HomePage _ -> HomePage ->
True True
LoginPage _ -> LoginPage _ ->
@ -88,7 +88,7 @@ loginPage p =
pageName : Page -> String pageName : Page -> String
pageName page = pageName page =
case page of case page of
HomePage _ -> HomePage ->
"Home" "Home"
LoginPage _ -> LoginPage _ ->
@ -147,10 +147,7 @@ uploadId page =
pageToString : Page -> String pageToString : Page -> String
pageToString page = pageToString page =
case page of case page of
HomePage (Just id) -> HomePage ->
"/app/home?item=" ++ id
HomePage Nothing ->
"/app/home" "/app/home"
LoginPage referer -> LoginPage referer ->
@ -232,8 +229,8 @@ parser =
oneOf oneOf
[ Parser.map HomePage [ Parser.map HomePage
(oneOf (oneOf
[ Parser.top <?> itemQuery [ Parser.top
, s pathPrefix </> s "home" <?> itemQuery , s pathPrefix </> s "home"
] ]
) )
, Parser.map LoginPage (s pathPrefix </> s "login" <?> pageQuery) , Parser.map LoginPage (s pathPrefix </> s "login" <?> pageQuery)
@ -271,8 +268,3 @@ pageQuery =
in in
Query.string "r" Query.string "r"
|> Query.map parsePage |> Query.map parsePage
itemQuery : Query.Parser (Maybe String)
itemQuery =
Query.string "item"

View File

@ -41,6 +41,7 @@ type alias Model =
, searchTypeForm : SearchType , searchTypeForm : SearchType
, contentOnlySearch : Maybe String , contentOnlySearch : Maybe String
, dragDropData : DD.DragDropData , dragDropData : DD.DragDropData
, scrollToCard : Maybe String
} }
@ -70,6 +71,7 @@ init flags =
, contentOnlySearch = Nothing , contentOnlySearch = Nothing
, dragDropData = , dragDropData =
DD.DragDropData DD.init Nothing DD.DragDropData DD.init Nothing
, scrollToCard = Nothing
} }
@ -98,7 +100,7 @@ type Msg
| KeyUpMsg (Maybe KeyCode) | KeyUpMsg (Maybe KeyCode)
| SetContentOnly String | SetContentOnly String
| ScrollResult (Result Dom.Error ()) | ScrollResult (Result Dom.Error ())
| ClearItemDetailId (Maybe String) | ClearItemDetailId
type SearchType type SearchType

View File

@ -82,21 +82,13 @@ update mId key flags settings msg model =
flags flags
m m
model.itemListModel model.itemListModel
( cmd, id ) =
case result.selected of
Just item ->
( Page.set key (ItemDetailPage item.id), Just item.id )
Nothing ->
( Cmd.none, Nothing )
in in
withSub withSub
( { model ( { model
| itemListModel = result.model | itemListModel = result.model
, dragDropData = DD.DragDropData result.dragModel Nothing , dragDropData = DD.DragDropData result.dragModel Nothing
} }
, Cmd.batch [ Cmd.map ItemCardListMsg result.cmd, cmd ] , Cmd.batch [ Cmd.map ItemCardListMsg result.cmd ]
) )
ItemSearchResp (Ok list) -> ItemSearchResp (Ok list) ->
@ -251,18 +243,12 @@ update mId key flags settings msg model =
ScrollResult _ -> ScrollResult _ ->
let let
cmd = cmd =
Process.sleep 800 |> Task.perform (always (ClearItemDetailId mId)) Process.sleep 800 |> Task.perform (always ClearItemDetailId)
in in
withSub ( model, cmd ) withSub ( model, cmd )
ClearItemDetailId id -> ClearItemDetailId ->
-- if user clicks quickly away (e.g. on another item), the noSub ( { model | scrollToCard = Nothing }, Cmd.none )
-- deferred command should be ignored
if mId == id then
noSub ( model, Page.set key (HomePage Nothing) )
else
noSub ( model, Cmd.none )
@ -277,7 +263,10 @@ scrollToCard mId model =
in in
case mId of case mId of
Just id -> Just id ->
( model, Task.attempt ScrollResult (scroll id), Sub.none ) ( { model | scrollToCard = mId }
, Task.attempt ScrollResult (scroll id)
, Sub.none
)
Nothing -> Nothing ->
( model, Cmd.none, Sub.none ) ( model, Cmd.none, Sub.none )

View File

@ -82,7 +82,7 @@ view current flags settings model =
] ]
[ viewSearchBar flags model [ viewSearchBar flags model
, Html.map ItemCardListMsg , Html.map ItemCardListMsg
(Comp.ItemCardList.view current settings model.itemListModel) (Comp.ItemCardList.view model.scrollToCard settings model.itemListModel)
] ]
, div , div
[ classList [ classList

View File

@ -25,7 +25,7 @@ update referrer flags msg model =
AuthResp (Ok lr) -> AuthResp (Ok lr) ->
let let
gotoRef = gotoRef =
Maybe.withDefault (HomePage Nothing) referrer |> Page.goto Maybe.withDefault HomePage referrer |> Page.goto
in in
if lr.success then if lr.success then
( { model | result = Just lr, password = "" }, Cmd.batch [ setAccount lr, gotoRef ], Just lr ) ( { model | result = Just lr, password = "" }, Cmd.batch [ setAccount lr, gotoRef ], Just lr )

View File

@ -77,7 +77,7 @@ renderSuccessMsg public _ =
else else
p [] p []
[ text "Your files have been successfully uploaded. They are now being processed. Check the " [ text "Your files have been successfully uploaded. They are now being processed. Check the "
, a [ class "ui link", Page.href (HomePage Nothing) ] , a [ class "ui link", Page.href HomePage ]
[ text "Items page" [ text "Items page"
] ]
, text " later where the files will arrive eventually. Or go to the " , text " later where the files will arrive eventually. Or go to the "