Skip to content

Commit 9219388

Browse files
committed
Add navigation for browsing between comments
1 parent 1859c1b commit 9219388

File tree

3 files changed

+105
-1
lines changed

3 files changed

+105
-1
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
module Shared.Utils.ListUtils exposing (findNextInfinite, findPreviousInfinite)
2+
3+
import List.Extra as List
4+
5+
6+
findPrevious : a -> List a -> Maybe a
7+
findPrevious item list =
8+
case list of
9+
x :: y :: rest ->
10+
if item == y then
11+
Just x
12+
13+
else
14+
findPrevious item (y :: rest)
15+
16+
_ ->
17+
Nothing
18+
19+
20+
findPreviousInfinite : a -> List a -> Maybe a
21+
findPreviousInfinite item list =
22+
if List.head list == Just item then
23+
List.last list
24+
25+
else
26+
findPrevious item list
27+
28+
29+
findNext : a -> List a -> Maybe a
30+
findNext item list =
31+
case list of
32+
x :: y :: rest ->
33+
if item == x then
34+
Just y
35+
36+
else
37+
findNext item (y :: rest)
38+
39+
_ ->
40+
Nothing
41+
42+
43+
findNextInfinite : a -> List a -> Maybe a
44+
findNextInfinite item list =
45+
if List.last list == Just item then
46+
List.head list
47+
48+
else
49+
findNext item list

engine-wizard/elm/Wizard/Common/Components/Questionnaire.elm

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ import Shared.Markdown as Markdown
9797
import Shared.RegexPatterns as RegexPatterns
9898
import Shared.Undraw as Undraw
9999
import Shared.Utils exposing (dispatch, flip, getUuidString, listFilterJust, listInsertIf)
100+
import Shared.Utils.ListUtils as ListUtils
100101
import SplitPane
101102
import String
102103
import String.Extra as String
@@ -2458,6 +2459,35 @@ viewQuestionnaireRightPanelComments appState model path =
24582459
viewQuestionnaireRightPanelCommentsLoaded : AppState -> Model -> String -> List CommentThread -> Html Msg
24592460
viewQuestionnaireRightPanelCommentsLoaded appState model path commentThreads =
24602461
let
2462+
comments =
2463+
List.map .path <|
2464+
QuestionnaireQuestionnaire.getComments model.questionnaire
2465+
2466+
nextPrevNavigation =
2467+
if List.length comments > 1 then
2468+
let
2469+
previousCommentsPath =
2470+
Maybe.withDefault "" <|
2471+
ListUtils.findPreviousInfinite path comments
2472+
2473+
nextCommentsPath =
2474+
Maybe.withDefault "" <|
2475+
ListUtils.findNextInfinite path comments
2476+
in
2477+
div [ class "comments-navigation" ]
2478+
[ a [ onClick (OpenComments False previousCommentsPath) ]
2479+
[ fa "fas fa-arrow-left me-2"
2480+
, text (gettext "Previous" appState.locale)
2481+
]
2482+
, a [ onClick (OpenComments False nextCommentsPath) ]
2483+
[ text (gettext "Next" appState.locale)
2484+
, fa "fas fa-arrow-right ms-2"
2485+
]
2486+
]
2487+
2488+
else
2489+
emptyNode
2490+
24612491
navigationView =
24622492
if Feature.projectCommentPrivate appState model.questionnaire then
24632493
viewCommentsNavigation appState model commentThreads
@@ -2508,7 +2538,8 @@ viewQuestionnaireRightPanelCommentsLoaded appState model path commentThreads =
25082538
|> List.sum
25092539
in
25102540
div [ class "Comments" ]
2511-
[ viewCommentsResolvedSelect appState model resolvedCommentsCount
2541+
[ nextPrevNavigation
2542+
, viewCommentsResolvedSelect appState model resolvedCommentsCount
25122543
, navigationView
25132544
, resolvedThreadsView
25142545
, commentThreadsView

engine-wizard/scss/modules/Common/Components/_Questionnaire.scss

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,30 @@ $toolbar-height: 40px;
381381
}
382382

383383
.Comments {
384+
.comments-navigation {
385+
position: sticky;
386+
top: -1rem;
387+
z-index: 200;
388+
background: $gray-100;
389+
margin: -1rem -1rem 0 -1rem;
390+
padding: 0;
391+
border-bottom: 1px solid $gray-400;
392+
margin-bottom: 1rem;
393+
display: grid;
394+
grid-template-columns: 1fr 1fr;
395+
396+
a {
397+
@include not-selectable;
398+
padding: $spacer-2 $spacer-3;
399+
text-align: center;
400+
text-decoration: none;
401+
402+
&:hover {
403+
background: $gray-200;
404+
}
405+
}
406+
}
407+
384408
.form-check {
385409
background: $gray-100;
386410
margin: -1rem -1rem 0 -1rem;

0 commit comments

Comments
 (0)