@@ -7,6 +7,8 @@ import Html exposing (Html, code, div, header, pre, span, text)
77import Html.Attributes exposing (class , style )
88import List.Nonempty as NEL
99import String.Extra exposing (pluralize )
10+ import UI.Click as Click
11+ import UI.Icon as Icon
1012import UI.Tooltip as Tooltip
1113import UnisonShare.DefinitionDiff as DefinitionDiff exposing (DefinitionDiff (..) , DiffDetails , DiffLine (..) , DiffSegment (..) )
1214
@@ -113,21 +115,25 @@ viewDiffLine viewSeg changeIndicator gutterWidth line =
113115 []
114116
115117
116- viewCollapsed : (DiffLine -> Html msg ) -> DefinitionDiff .Collapsed -> Html msg
117- viewCollapsed viewLine collapsed =
118+ viewCollapsed : ViewConfig msg -> (DiffLine -> Html msg ) -> Int -> DefinitionDiff .Collapsed -> Html msg
119+ viewCollapsed cfg viewLine index collapsed =
118120 case collapsed of
119121 DefinitionDiff . Collapsed lines ->
120122 let
121123 numCollapsedLines =
122124 List . length lines
123125 in
124- div [ class " collapsed-section" ]
125- [ text
126- ( String . fromInt numCollapsedLines
127- ++ pluralize " line " " lines " numCollapsedLines
128- ++ " hidden..."
129- )
130- ]
126+ Click . onClick ( cfg. toExpandCollapsedDiffSectionMsg { index = index } )
127+ |> Click . view
128+ [ class " collapsed-section" ]
129+ [ Icon . view Icon . dots
130+ , text
131+ ( String . fromInt numCollapsedLines
132+ ++ pluralize " line " " lines " numCollapsedLines
133+ ++ " hidden"
134+ )
135+ , Icon . view Icon . dots
136+ ]
131137
132138 DefinitionDiff . NotCollapsed lines ->
133139 div [] ( List . map viewLine lines)
@@ -149,14 +155,14 @@ diffLength collapsedLines =
149155 |> List . sum
150156
151157
152- viewDiff : ( Bool -> SyntaxConfig msg ) -> DiffDetails -> Html msg
153- viewDiff toSyntaxConfig { left, right } =
158+ viewDiff : ViewConfig msg -> DiffDetails -> Html msg
159+ viewDiff cfg { left, right } =
154160 let
155161 toGutterWidth len =
156162 String . length ( String . fromInt len)
157163
158164 toViewDiffSegment isNew =
159- viewDiffSegment ( toSyntaxConfig isNew)
165+ viewDiffSegment ( cfg . toSyntaxConfig isNew)
160166
161167 viewLeftDiffLine =
162168 viewDiffLine ( toViewDiffSegment False )
@@ -169,10 +175,10 @@ viewDiff toSyntaxConfig { left, right } =
169175 ( toGutterWidth ( diffLength right))
170176
171177 before =
172- List . map ( viewCollapsed viewLeftDiffLine) left
178+ List . indexedMap ( viewCollapsed cfg viewLeftDiffLine) left
173179
174180 after =
175- List . map ( viewCollapsed viewRightDiffLine) right
181+ List . indexedMap ( viewCollapsed cfg viewRightDiffLine) right
176182 in
177183 div [ class " diff-side-by-side" ]
178184 [ pre [ class " monochrome diff-side left" ]
@@ -186,14 +192,20 @@ viewDiff toSyntaxConfig { left, right } =
186192 ]
187193
188194
189- view : (Bool -> SyntaxConfig msg ) -> DefinitionDiff -> Html msg
190- view toSyntaxConfig defDiff =
195+ type alias ViewConfig msg =
196+ { toSyntaxConfig : Bool -> SyntaxConfig msg
197+ , toExpandCollapsedDiffSectionMsg : { index : Int } -> msg
198+ }
199+
200+
201+ view : ViewConfig msg -> DefinitionDiff -> Html msg
202+ view cfg defDiff =
191203 case defDiff of
192204 Diff details ->
193- div [] [ viewDiff toSyntaxConfig details ]
205+ div [] [ viewDiff cfg details ]
194206
195207 Mismatched { left, right } ->
196208 div [ class " diff-side-by-side" ]
197- [ pre [ class " monochrome diff-side" ] [ code [] ( viewSegments ( toSyntaxConfig False ) " mismatched old" left) ]
198- , pre [ class " monochrome diff-side" ] [ code [] ( viewSegments ( toSyntaxConfig True ) " mismatched new" right) ]
209+ [ pre [ class " monochrome diff-side" ] [ code [] ( viewSegments ( cfg . toSyntaxConfig False ) " mismatched old" left) ]
210+ , pre [ class " monochrome diff-side" ] [ code [] ( viewSegments ( cfg . toSyntaxConfig True ) " mismatched new" right) ]
199211 ]
0 commit comments