Skip to content

Commit

Permalink
Add section for talks
Browse files Browse the repository at this point in the history
  • Loading branch information
Pamplemousse committed Dec 1, 2024
1 parent 3096af4 commit 03c6c78
Show file tree
Hide file tree
Showing 16 changed files with 315 additions and 7 deletions.
2 changes: 2 additions & 0 deletions elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
"elm/http": "2.0.0",
"elm/json": "1.1.3",
"elm/url": "1.0.0",
"elm-community/html-extra": "3.4.0",
"elm-explorations/markdown": "1.0.0",
"hecrj/html-parser": "2.3.4",
"justinmimbs/date": "4.1.0",
"krisajenkins/remotedata": "6.0.1"
},
"indirect": {
Expand Down
6 changes: 4 additions & 2 deletions front/elm/Commands.elm
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ module Commands exposing (fetchData)
import CatGifs.Commands exposing (fetchCatGif)
import Messages exposing (Msg(..))
import Projects.Decoders
import Talks.Decoders
import TiledList
import Url exposing (Url)


fetchData : Url -> Url -> Cmd Msg
fetchData projectsUrl catGifsUrl =
fetchData : Url -> Url -> Url -> Cmd Msg
fetchData projectsUrl talksUrl catGifsUrl =
Cmd.batch
[ Cmd.map ProjectsMsg (TiledList.fetch Projects.Decoders.decoder projectsUrl)
, Cmd.map TalksMsg (TiledList.fetch Talks.Decoders.decoder talksUrl)
, fetchCatGif catGifsUrl
]
24 changes: 24 additions & 0 deletions front/elm/Decoders.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module Decoders exposing (decodeDate, decodeUrl)

import Date exposing (Date)
import Json.Decode as Decode exposing (Decoder)
import Url exposing (Protocol(..), Url)


decodeDate : Decoder Date
decodeDate =
Decode.andThen
(\s ->
case Date.fromIsoString s of
Ok l ->
Decode.succeed l

Err e ->
Decode.fail e
)
Decode.string


decodeUrl : Decoder (Maybe Url)
decodeUrl =
Decode.map Url.fromString Decode.string
45 changes: 45 additions & 0 deletions front/elm/Lang.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
module Lang exposing (Lang(..), decoder, toString)

import Json.Decode as Decode exposing (Decoder)


type Lang
= EN
| FR


decoder : Decoder Lang
decoder =
Decode.andThen
(\s ->
case fromString s of
Ok l ->
Decode.succeed l

Err e ->
Decode.fail e
)
Decode.string


fromString : String -> Result String Lang
fromString s =
case s of
"FR" ->
Ok FR

"EN" ->
Ok EN

_ ->
Err "invalid language"


toString : Lang -> String
toString l =
case l of
FR ->
"FR"

EN ->
"EN"
7 changes: 6 additions & 1 deletion front/elm/Link.elm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Link exposing (Model, Msg(..), decoder, view)
module Link exposing (Model, Msg(..), decoder, decoderWithDefaultValue, view)

{-| This represent a link to an external resource used as a reference.
-}
Expand Down Expand Up @@ -26,6 +26,11 @@ decoder =
|> optional "value" (Decode.map Just Decode.string) Nothing


decoderWithDefaultValue : String -> Decode.Decoder Model
decoderWithDefaultValue defaultValue =
Decode.map (\slides -> { slides | value = Just defaultValue }) decoder


view : Model -> Html Msg
view link =
let
Expand Down
6 changes: 5 additions & 1 deletion front/elm/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Json.Decode exposing (decodeString)
import Messages exposing (Msg(..))
import Models exposing (Flags, Model, initialModel)
import Projects.Models exposing (projectsDefaultUrl)
import Talks.Models exposing (talksDefaultUrl)
import Update exposing (update)
import Url exposing (Protocol(..), Url)
import View exposing (view)
Expand All @@ -29,9 +30,12 @@ initialState flags url key =

projectsUrl =
flags.projectsUrl |> toUrl projectsDefaultUrl

talksUrl =
flags.talksUrl |> toUrl talksDefaultUrl
in
( initialModel key url catGifUrl
, fetchData projectsUrl catGifUrl
, fetchData projectsUrl talksUrl catGifUrl
)


Expand Down
2 changes: 2 additions & 0 deletions front/elm/Messages.elm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Browser exposing (UrlRequest)
import CatGifs.Models exposing (CatGif)
import Projects.Models exposing (Project)
import RemoteData exposing (WebData)
import Talks.Models exposing (Talk)
import TiledList
import Url exposing (Url)

Expand All @@ -15,3 +16,4 @@ type Msg
| NavigateTo String
| RedirectTo String
| ProjectsMsg (TiledList.Msg Project)
| TalksMsg (TiledList.Msg Talk)
4 changes: 4 additions & 0 deletions front/elm/Models.elm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Projects.Models exposing (Project)
import RemoteData exposing (WebData)
import Routing exposing (Route)
import SocialMedia.Models exposing (SocialMedium, initialSocialMedia)
import Talks.Models exposing (Talk)
import TiledList
import Url exposing (Url)
import Url.Parser exposing (parse)
Expand All @@ -18,11 +19,13 @@ type alias Model =
, key : Key
, route : Maybe Route
, projects : TiledList.Model Project
, talks : TiledList.Model Talk
}


type alias Flags =
{ projectsUrl : String
, talksUrl : String
, catGifsUrl : String
}

Expand All @@ -35,4 +38,5 @@ initialModel key url catGifsUrl =
, key = key
, route = Url.Parser.parse Routing.routeParser url
, projects = TiledList.initialModel
, talks = TiledList.initialModel
}
9 changes: 8 additions & 1 deletion front/elm/Routing.elm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Routing exposing (Route(..), blogPath, cvPath, meowPath, projectsPath, rootPath, routeParser)
module Routing exposing (Route(..), blogPath, cvPath, meowPath, projectsPath, rootPath, routeParser, talksPath)

import Url.Parser exposing (Parser, map, oneOf, s, top)

Expand All @@ -8,6 +8,7 @@ type Route
| CVRoute
| MeowRoute
| ProjectsRoute
| TalksRoute


routeParser : Parser (Route -> a) a
Expand All @@ -17,6 +18,7 @@ routeParser =
, map CVRoute (s cvPath)
, map MeowRoute (s meowPath)
, map ProjectsRoute (s projectsPath)
, map TalksRoute (s talksPath)
]


Expand All @@ -43,3 +45,8 @@ projectsPath =
rootPath : String
rootPath =
"/"


talksPath : String
talksPath =
"talks"
34 changes: 34 additions & 0 deletions front/elm/Talks/Decoders.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module Talks.Decoders exposing (decoder)

import Decoders exposing (decodeDate)
import Json.Decode as Decode
import Json.Decode.Pipeline exposing (optional, required)
import Lang
import Link
import Talks.Models exposing (Conference, Talk)


decoder : Decode.Decoder (List Talk)
decoder =
Decode.list talkDecoder


talkDecoder : Decode.Decoder Talk
talkDecoder =
Decode.succeed Talk
|> required "id" Decode.int
|> required "title" Decode.string
|> required "description" Decode.string
|> required "conferences" (Decode.list conferenceDecoder)


conferenceDecoder : Decode.Decoder Conference
conferenceDecoder =
Decode.succeed Conference
|> required "organisation" Decode.string
|> required "date" decodeDate
|> required "duration" Decode.int
|> required "lang" Lang.decoder
|> optional "recording" (Decode.map Just (Link.decoderWithDefaultValue "📺 recording")) Nothing
|> optional "slides" (Decode.map Just (Link.decoderWithDefaultValue "📜 slides")) Nothing
|> optional "sources" (Decode.map Just (Link.decoderWithDefaultValue "🧑\u{200D}💻 sources")) Nothing
34 changes: 34 additions & 0 deletions front/elm/Talks/Models.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module Talks.Models exposing (Conference, Talk, talksDefaultUrl)

import Date exposing (Date)
import Lang exposing (Lang)
import Link
import Url exposing (Protocol(..), Url)


type alias Id =
Int


type alias Conference =
{ organisation : String
, date : Date
, duration : Int
, lang : Lang
, recording : Maybe Link.Model
, slides : Maybe Link.Model
, sources : Maybe Link.Model
}


type alias Talk =
{ id : Id
, title : String
, description : String
, conferences : List Conference
}


talksDefaultUrl : Url
talksDefaultUrl =
Url Https "www.xaviermaso.com" Nothing "api/talks" Nothing Nothing
108 changes: 108 additions & 0 deletions front/elm/Talks/Views.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
module Talks.Views exposing (renderCurrent)

import Colours exposing (Colour, toStringLight)
import Date exposing (format, year)
import Html exposing (Html, br, div, h1, h3, i, li, span, text, ul)
import Html.Attributes exposing (class)
import Html.Events exposing (onClick)
import Html.Extra exposing (viewMaybe)
import Lang
import Link
import Talks.Models exposing (Conference, Talk)
import TiledList exposing (Msg(..))


renderCurrent : Colour -> Talk -> Html (Msg Talk)
renderCurrent colour talk =
let
allYears =
talk.conferences |> List.map (\c -> c.date |> year)

yearMin =
allYears |> List.minimum

yearMax =
allYears |> List.maximum

dates =
case ( yearMin, yearMax ) of
( Just min, Just max ) ->
Just
(case min == max of
True ->
String.fromInt max

False ->
String.fromInt min ++ "-" ++ String.fromInt max
)

_ ->
Nothing

foo =
dates |> viewMaybe (\ds -> h3 [ class "date" ] [ text ds ])
in
div [ class "row" ]
[ div [ class "col-md-12" ]
[ div [ class ("list-component-description " ++ toStringLight colour) ]
[ h1 [] [ text talk.title ]
, foo

-- , h3
-- [ class "date" ]
-- [ text dates ]
, div [ class "row" ]
[ div
[ class "col-md-12 textDesc" ]
[ text talk.description ]
]
, renderConferences talk.conferences
, i
[ class "fa fa-close fa-2x close"
, onClick (CloseDescriptionOf talk)
]
[]
]
]
]


renderConferences : List Conference -> Html (Msg Talk)
renderConferences conferences =
if List.isEmpty conferences then
div [] []

else
div []
[ br [] []
, div [ class "textDesc" ] [ text "Presented at the following venues:" ]
, conferences |> List.map renderConference |> ul [ class "list-group list-group-flush" ]
]


renderConference : Conference -> Html (Msg Talk)
renderConference c =
let
date =
c.date |> format "MMMM y"

recording =
c.recording |> viewMaybe (Link.view >> Html.map LinkMsg >> (\s -> div [] [ s, span [ class "textDesc" ] [ text (" (" ++ (c.duration |> String.fromInt) ++ "min)") ] ]))

slides =
c.slides |> viewMaybe (Link.view >> Html.map LinkMsg)

sources =
c.sources |> viewMaybe (Link.view >> Html.map LinkMsg)
in
li [ class "list-group-item" ]
[ div [ class "me-auto" ]
[ div [ class "row" ]
[ div [ class "col-md-2 textDesc" ] [ text date ]
, div [ class "col-md-3 textDesc" ] [ text ("[" ++ (c.lang |> Lang.toString) ++ "] " ++ c.organisation) ]
, div [ class "col-md-2" ] [ sources ]
, div [ class "col-md-2" ] [ slides ]
, div [ class "col-md-3" ] [ recording ]
]
]
]
Loading

0 comments on commit 03c6c78

Please sign in to comment.