website/frontend/src/Debate/Helpers.elm

435 lines
16 KiB
Elm
Raw Normal View History

module Debate.Helpers exposing (..)
2024-11-15 23:28:32 -06:00
2024-11-23 02:28:14 -06:00
-- import Html exposing (div, hr)
-- import Html.Attributes as H exposing (style, title, wrap)
-- import Config.Types exposing (..)
2024-11-15 23:28:32 -06:00
import Config.Colour as T exposing (..)
import Config.Format as O exposing (..)
import Debate.Types exposing (..)
import Effect exposing (Effect)
2024-11-20 22:47:57 -06:00
import Element as E exposing (..)
import Element.Background as B exposing (..)
2024-11-15 23:28:32 -06:00
import Element.Border as D exposing (..)
2024-11-19 13:17:57 -06:00
import Element.Events as V exposing (..)
2024-11-20 22:47:57 -06:00
import Element.Font as F exposing (..)
2024-11-26 04:32:11 -06:00
import Html.Attributes exposing (form, id, style)
2024-11-15 23:28:32 -06:00
import Layouts
2024-11-23 02:28:14 -06:00
import List.Extra exposing (..)
import Maybe exposing (withDefault)
import Maybe.Extra exposing (isNothing)
2024-11-15 23:28:32 -06:00
import Page exposing (Page)
import Route exposing (Route)
import Shared
import View exposing (View)
type alias ArgMakerInput msg =
{ arg : Argument
, index : Int
, isExpanded : Bool
, maybeHeight : Maybe Int
, titleClickMsg : msg
}
argumentMaker : ArgMakerInput msg -> Element msg
argumentMaker argMakerInput =
2024-11-26 04:32:11 -06:00
-- row [ imageSpacer, E.alignLeft ]
-- [ E.image
-- (case argMakerInput.maybeHeight of
-- Nothing ->
-- [ transparent True ]
-- Just _ ->
-- [ centerX
-- , centerY
-- , alignTop
-- , D.rounded 100
-- , E.width <| px 52
-- ]
-- )
-- { src = "arguments/" ++ argMakerInput.arg.argumentImage ++ ".png"
-- , description = ""
-- }
-- ,
column
(if isNothing argMakerInput.maybeHeight then
2024-11-26 04:32:11 -06:00
[ E.htmlAttribute (id <| "arg" ++ String.fromInt argMakerInput.index)
, E.width <| px 600
]
else
2024-11-26 04:32:11 -06:00
[ E.width <| px 600, alignTop ]
)
[ titleMaker argMakerInput
2024-11-23 15:37:36 -06:00
, column
(case argMakerInput.maybeHeight of
Just h ->
[ B.color colourTheme.cardBackground
, clip
2024-11-26 04:32:11 -06:00
, htmlAttribute <| style "transition" "all .7s ease-in-out"
, roundEach { topLeft = 0, topRight = 0, bottomRight = 20, bottomLeft = 20 }
, height <|
px <|
if argMakerInput.isExpanded then
h
else
0
]
Nothing ->
[ transparent True ]
2024-11-23 15:37:36 -06:00
)
<|
List.map (\x -> x argMakerInput)
[ propositionMaker
, reductioMaker
, summaryMaker
, strengthMaker
, tableMaker
, proofTreeMaker
]
2024-11-23 02:28:14 -06:00
]
2024-11-20 22:47:57 -06:00
2024-11-23 02:28:14 -06:00
2024-11-26 04:32:11 -06:00
-- ]
titleMaker : ArgMakerInput msg -> Element msg
titleMaker argMakerInput =
2024-11-23 02:28:14 -06:00
paragraph
(paragraphBoldFormat
++ [ F.size 20
, F.color colourTheme.backgroundColour
, B.color colourTheme.highlightText
, paddingEach { top = 6, bottom = 2, left = 12, right = 12 }
, alignBottom
2024-11-26 04:32:11 -06:00
, roundEach { topLeft = 10, topRight = 10, bottomRight = 0, bottomLeft = 0 }
2024-11-23 02:28:14 -06:00
, F.center
2024-11-23 15:37:36 -06:00
, pointer
2024-11-26 04:32:11 -06:00
, htmlAttribute <| style "transition" "all 0.3s ease-in-out"
2024-11-24 01:53:40 -06:00
, mouseOver
[ B.color colourTheme.highlightTextHover
, F.color colourTheme.nonHighlightedText
]
, V.onClick <| argMakerInput.titleClickMsg
2024-11-23 02:28:14 -06:00
]
++ (case argMakerInput.maybeHeight of
Nothing ->
[ transparent True ]
Just _ ->
2024-11-26 04:32:11 -06:00
[ roundEach <|
if argMakerInput.isExpanded then
{ topLeft = 10, topRight = 10, bottomRight = 0, bottomLeft = 0 }
else
{ topLeft = 10, topRight = 10, bottomRight = 10, bottomLeft = 10 }
, F.alignLeft
]
)
2024-11-23 02:28:14 -06:00
)
[ text argMakerInput.arg.argumentTitle ]
2024-11-23 02:28:14 -06:00
propositionMaker : ArgMakerInput msg -> Element msg
propositionMaker argMakerInput =
2024-11-25 18:50:12 -06:00
row
2024-11-26 04:32:11 -06:00
[ paddingEach { top = 20, right = 30, bottom = 0, left = 30 }
, E.width fill
2024-11-25 18:50:12 -06:00
]
2024-11-23 15:37:36 -06:00
[ column
[ E.alignTop, E.alignLeft ]
2024-11-25 18:50:12 -06:00
[ paragraph
(paragraphBoldFormat
++ [ F.size 18
, E.width <| px 100
]
)
2024-11-23 15:37:36 -06:00
[ el [ tooltip below (myTooltip "A proposition is a declarative statement that can be evaluated as either true or false, and which serves as the basis for debate.") ] (text "Proposition:") |> el [ F.color colourTheme.highlightText ] ]
]
2024-11-23 15:37:36 -06:00
, column
[ E.width fill, E.alignLeft ]
2024-11-25 18:50:12 -06:00
[ paragraph (paragraphBoldFormat ++ [ F.size 18 ])
[ text argMakerInput.arg.propositionTitle
2024-11-25 18:50:12 -06:00
|> el
[ F.color colourTheme.nonHighlightedText
, F.regular
, F.size 16
]
]
]
2024-11-23 15:37:36 -06:00
]
reductioMaker : ArgMakerInput msg -> Element msg
reductioMaker argMakerInput =
case argMakerInput.arg.propositionReductio of
2024-11-23 15:37:36 -06:00
"" ->
none
reductio ->
2024-11-26 04:32:11 -06:00
row [ paddingEach { top = 8, right = 30, bottom = 0, left = 30 }, E.width fill ]
2024-11-23 15:37:36 -06:00
[ column
[ E.alignTop, E.alignLeft ]
[ paragraph (paragraphBoldFormat ++ [ F.size 18, E.width <| px 100 ])
[ el [ tooltip below (myTooltip "This is the position from which the reductio ad absurdum is derived.") ] (text "Reductio:") |> el [ F.color colourTheme.highlightText ]
]
]
, column [ E.width fill, E.alignLeft ]
[ paragraph (paragraphBoldFormat ++ [ F.size 18, spacing 3 ])
[ text reductio ]
]
]
2024-11-23 15:37:36 -06:00
summaryMaker : ArgMakerInput msg -> Element msg
summaryMaker argMakerInput =
2024-11-26 04:32:11 -06:00
row [ paddingEach { top = 10, right = 30, bottom = 0, left = 30 } ]
2024-11-23 15:37:36 -06:00
[ column
[ E.alignTop, E.alignLeft ]
[ paragraph (paragraphBoldFormat ++ [ F.size 18, E.width <| px 100 ])
[ el [ tooltip below (myTooltip "The following information provides additional context and insight into the reasoning behind the argument") ] (text "Summary:") |> el [ F.color colourTheme.highlightText ]
]
]
, column
[ E.width fill, E.alignLeft ]
2024-11-25 18:50:12 -06:00
[ paragraph
(paragraphBoldFormat
++ [ F.size 18
, spacing 3
]
)
[ text argMakerInput.arg.propositionSummary
2024-11-25 18:50:12 -06:00
|> el
[ F.color colourTheme.nonHighlightedText
, F.regular
, F.size 16
]
]
]
]
strengthMaker : ArgMakerInput msg -> Element msg
strengthMaker argMakerInput =
2024-11-25 18:50:12 -06:00
let
barMaker : Int -> Element msg
barMaker num =
el
[ E.height <| px 12
2024-11-26 04:32:11 -06:00
, E.width fill
2024-11-25 18:50:12 -06:00
, D.rounded 10
, D.color colourTheme.nonHighlightedDarkText
, D.width 2
, B.gradient
{ angle = 90
, steps =
List.concat
[ List.repeat num colourTheme.barGreen
, List.repeat (10 - num) colourTheme.barRed
]
}
, tooltip below (myTooltip (getConfidenceTooltip num))
]
none
getConfidenceTooltip : Int -> String
getConfidenceTooltip num =
case num of
0 ->
"Extremely low. Speculative reasoning."
1 ->
"Very low. Extremely weak reasoning."
2 ->
2024-11-26 04:32:11 -06:00
"Low. Weak reasoning."
2024-11-25 18:50:12 -06:00
3 ->
2024-11-26 04:32:11 -06:00
"Kinda low. Somewhat weak reasoning."
2024-11-25 18:50:12 -06:00
4 ->
"Below average. More weak than strong."
5 ->
"Moderate. OK reasoning."
6 ->
"Above average. More strong than weak."
7 ->
2024-11-26 04:32:11 -06:00
"Kinda high. Somewhat strong reasoning."
2024-11-25 18:50:12 -06:00
8 ->
2024-11-26 04:32:11 -06:00
"High. Robust reasoning."
2024-11-25 18:50:12 -06:00
9 ->
"Very high. Extremely robust reasoning."
10 ->
"Extremely high. Air tight reasoning."
_ ->
"Confidence level out of expected range."
in
2024-11-26 04:32:11 -06:00
row [ paddingEach { top = 10, right = 30, bottom = 0, left = 30 }, E.width fill ]
2024-11-25 18:50:12 -06:00
[ column
[ E.alignTop, E.alignLeft ]
[ paragraph (paragraphBoldFormat ++ [ F.size 18, E.width <| px 100 ])
[ el [ tooltip below (myTooltip "This represents my confidence in the soundness of the argument.") ] (text "Confidence:") |> el [ F.color colourTheme.highlightText ] ]
]
, column
[ E.width fill, E.alignLeft, centerY ]
[ barMaker argMakerInput.arg.argumentCertainty ]
2024-11-22 02:19:27 -06:00
]
2024-11-23 02:28:14 -06:00
tableMaker : ArgMakerInput msg -> Element msg
tableMaker argMakerInput =
2024-11-23 15:37:36 -06:00
let
formalizationMaker : List (Element msg)
formalizationMaker =
let
argumentFormatting : List (Attribute msg)
argumentFormatting =
[ centerX, F.center, spacing 3 ]
in
List.indexedMap
(\index argumentEntry ->
2024-11-26 04:32:11 -06:00
column (paragraphFormat ++ [ spacing 3, centerX, E.width fill, paddingEach { top = 10, right = 30, bottom = 0, left = 30 } ])
2024-11-23 15:37:36 -06:00
(List.indexedMap
(\premiseIndex premiseWithNotation ->
column argumentFormatting
[ paragraph paragraphHightlightedBoldText
[ text ("P" ++ String.fromInt (premiseIndex + 1) ++ ")")
, text premiseWithNotation.premise
|> el [ F.color colourTheme.nonHighlightedText, F.regular, paddingEach { top = 0, right = 0, bottom = 0, left = 5 } ]
]
, paragraph argumentFormatting
[ text ("(" ++ premiseWithNotation.notation ++ ")")
|> el [ F.color colourTheme.highlightText, F.bold ]
]
]
)
argumentEntry.premises
++ [ column argumentFormatting
[ paragraph paragraphHightlightedBoldText
[ text "C)"
, text argumentEntry.conclusion
|> el [ F.color colourTheme.nonHighlightedText, F.regular, paddingEach { top = 0, right = 0, bottom = 0, left = 5 } ]
]
, paragraph argumentFormatting
[ text ("(" ++ argumentEntry.conclusionNotation ++ ")")
|> el [ F.color colourTheme.highlightText, F.bold ]
]
]
]
)
)
argMakerInput.arg.argumentFormalization
2024-11-23 15:37:36 -06:00
in
2024-11-26 04:32:11 -06:00
column
[ centerX
, paddingEach { top = 8, right = 30, bottom = 0, left = 30 }
, E.width fill
]
2024-11-24 01:53:40 -06:00
[ wrappedRow (paragraphBoldFormat ++ [ E.alignLeft, E.width fill ])
2024-11-23 15:37:36 -06:00
[ E.table
[ spacing 0
, D.rounded 10
, D.width 2
, D.color colourTheme.nonHighlightedDarkText
, clip
]
{ data = argMakerInput.arg.definitionTable
2024-11-23 15:37:36 -06:00
, columns =
[ { header =
el
[ F.bold
, D.widthEach { bottom = 1, top = 1, left = 1, right = 1 }
, D.color colourTheme.nonHighlightedDarkText
, padding 8
]
(text "Definiendum" |> el [ F.color colourTheme.highlightText ])
, width = fill |> maximum 50
, view =
\definition ->
row
[ F.color colourTheme.highlightText
, F.bold
, D.widthEach { bottom = 1, top = 0, left = 1, right = 1 }
, D.color colourTheme.nonHighlightedDarkText
, padding 8
, E.height fill
]
[ row [ centerX ]
[ paragraph [] [ text definition.definiendum ]
]
]
}
, { header =
el
[ F.bold
, D.widthEach { bottom = 1, top = 1, left = 0, right = 1 }
, D.color colourTheme.nonHighlightedDarkText
, padding 8
]
(text "Definiens" |> el [ F.color colourTheme.highlightText ])
, width = fill
, view =
\definition ->
paragraph
[ F.color colourTheme.nonHighlightedText
, F.regular
, D.widthEach { bottom = 1, top = 0, left = 0, right = 1 }
, D.color colourTheme.nonHighlightedDarkText
, padding 8
, E.height fill
]
[ row []
[ paragraph [] [ text definition.definiens ]
]
]
}
]
}
]
, column [ centerX ] formalizationMaker
]
2024-11-23 02:28:14 -06:00
proofTreeMaker : ArgMakerInput msg -> Element msg
proofTreeMaker argMakerInput =
2024-11-26 04:32:11 -06:00
row
[ paddingEach { top = 8, right = 30, bottom = 0, left = 30 }
, centerX
, E.width fill
]
[ column [ E.width fill ]
2024-11-23 15:37:36 -06:00
[ newTabLink
(paragraphBoldFormat
++ [ F.size 18
, F.color colourTheme.backgroundColour
, B.color colourTheme.highlightText
, paddingEach { top = 6, bottom = 2, left = 12, right = 12 }
, D.rounded 10
, F.center
, E.alignRight
2024-11-26 04:32:11 -06:00
, alignBottom
2024-11-23 15:37:36 -06:00
, transitionStyle
, mouseOver
[ B.color colourTheme.highlightTextHover
, F.color colourTheme.nonHighlightedText
, D.color colourTheme.highlightTextHover
]
]
)
{ url = argMakerInput.arg.proofLink
2024-11-23 15:37:36 -06:00
, label = text "Proof Tree"
}
]
]