feat: arg expansions working, lez go ma nigga

This commit is contained in:
isaac 2024-11-25 22:23:11 -05:00
parent 45ca7a9718
commit 1196617af5
6 changed files with 167 additions and 104 deletions

View file

@ -64,7 +64,7 @@ import Html.Attributes as H exposing (style, title, wrap)
import Layouts
import List.Extra as L exposing (..)
import Page exposing (Page)
import Ports
import Ports exposing (gotArgHeight)
import Route exposing (Route)
import Shared
import View exposing (View)
@ -91,12 +91,21 @@ toLayout model =
type alias Model =
{ argHeights : List Int }
{ argExpansions : List Bool
, argHeights : List Int
}
init : () -> ( Model, Effect Msg )
init () =
( { argHeights = List.repeat (List.length argumentList) 30 }
let
numArgs : Int
numArgs =
List.length argumentList
in
( { argExpansions = List.repeat numArgs False
, argHeights = List.repeat numArgs 0
}
, Effect.none
)
@ -106,30 +115,36 @@ init () =
type Msg
= ToggleExpandArg Int
= GotArgHeight (List Int)
| ToggleExpandArg Int
update : Msg -> Model -> ( Model, Effect Msg )
update msg model =
case msg of
ToggleExpandArg index ->
( case getAt index model.argHeights of
Nothing ->
model
Debug.log (Debug.toString model.argHeights) <|
case msg of
GotArgHeight argHeights ->
( { model | argHeights = argHeights }, Effect.none )
Just elHeight ->
{ model | argHeights = setAt index elHeight model.argHeights }
, Effect.sendCmd <| Ports.getArgHeight ()
)
ToggleExpandArg index ->
( case getAt index model.argExpansions of
Nothing ->
model
-- SUBSCRIPTIONS
Just isExpanded ->
{ model
| argExpansions =
setAt index
(not isExpanded)
model.argExpansions
}
, Effect.sendCmd <| Ports.getArgHeight <| List.length model.argHeights
)
subscriptions : Model -> Sub Msg
subscriptions model =
Sub.none
gotArgHeight GotArgHeight
@ -156,14 +171,39 @@ debateContainer shared model =
debateList : Model -> Element Msg
debateList model =
column
pageList
let
argColumn : Bool -> Element Msg
argColumn isHidden =
column
-- (explain Debug.todo ::
[ padding 30
, spacing 10
]
<|
List.map argumentMaker <|
List.map4
(\w x y z ->
{ arg = w
, index = x
, isExpanded = y
, maybeHeight =
if isHidden then
Nothing
else
z
, titleClickMsg = ToggleExpandArg x
}
)
argumentList
(List.range 0 <| List.length model.argHeights)
model.argExpansions
(List.map Just model.argHeights)
in
el
[ behindContent <| argColumn True ]
<|
List.map2 (argumentMaker ToggleExpandArg model.argHeights)
argumentList
<|
List.range 0 <|
List.length model.argHeights
argColumn False
argumentList : List Argument