@@ -14,7 +14,6 @@ import Shared.Api.Branches as BranchesApi
1414import Shared.Api.Prefabs as PrefabsApi
1515import Shared.Data.Branch.BranchState as BranchState
1616import Shared.Data.Event as Event
17- import Shared.Data.QuestionnaireDetail.Reply.ReplyValue exposing (ReplyValue (..) )
1817import Shared.Data.WebSockets.BranchAction.SetContentBranchAction as SetContentBranchAction exposing (SetContentBranchAction )
1918import Shared.Data.WebSockets.ClientBranchAction as ClientBranchAction
2019import Shared.Data.WebSockets.ServerBranchAction as ServerBranchAction
@@ -75,47 +74,22 @@ fetchSubrouteData appState model =
7574
7675 KMEditorRoute ( EditorRoute _ KMEditorRoute . Preview ) ->
7776 let
78- mbScrollPath =
79- Dict . keys model. previewModel. questionnaireModel. questionnaire. replies
80- |> List . sortBy String . length
81- |> List . reverse
82- |> List . head
83-
8477 mbActiveQuestionUuid =
8578 ActionResult . toMaybe model. branchModel
8679 |> Maybe . map EditorBranch . getActiveQuestionUuid
87-
88- scrollIntoView parts =
89- Ports . scrollIntoView ( " [data-path=\" " ++ String . join " ." parts ++ " \" ]" )
9080 in
91- case ( mbScrollPath, mbActiveQuestionUuid ) of
92- -- Somewhere deep in the questionnaire
93- ( Just scrollPath, Just activeQuestionUuid ) ->
94- let
95- value =
96- Dict . get scrollPath model. previewModel. questionnaireModel. questionnaire. replies
97-
98- answerPathUuid =
99- Maybe . withDefault " " <|
100- case Maybe . map . value value of
101- Just ( AnswerReply answerUuid) ->
102- Just answerUuid
103-
104- Just ( ItemListReply itemUuids) ->
105- List . head itemUuids
106-
107- _ ->
108- Nothing
109- in
110- scrollIntoView [ scrollPath, answerPathUuid, activeQuestionUuid ]
111-
112- -- Top level question in a chapter
113- ( Nothing , Just activeQuestionUuid ) ->
81+ case mbActiveQuestionUuid of
82+ Just activeQuestionUuid ->
11483 let
115- chapterUuid =
116- ActionResult . unwrap " " ( EditorBranch . getChapterUuid activeQuestionUuid ) model . branchModel
84+ scrollIntoView path =
85+ Ports . scrollIntoView ( " [data-path= \" " ++ path ++ " \" ] " )
11786 in
118- scrollIntoView [ chapterUuid, activeQuestionUuid ]
87+ -- TODO: There might be replies that are no longer accessible but there is no cleaning of replies in preview values now, so we just try to scroll them all
88+ model. previewModel. questionnaireModel. questionnaire. replies
89+ |> Dict . filter ( \ key _ -> String . endsWith activeQuestionUuid key)
90+ |> Dict . toList
91+ |> List . map ( scrollIntoView << Tuple . first)
92+ |> Cmd . batch
11993
12094 _ ->
12195 Cmd . none
0 commit comments