From 80076a2b8f1e0142d4bbb71115433bd834020692 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Mon, 16 Nov 2020 16:00:55 -0500 Subject: [PATCH] start on posse support --- sina/src/Mi/POSSE.elm | 40 ++++++++++++++++++++++++++++++++++++ sina/src/Model.elm | 3 +++ sina/src/Page/Index.elm | 12 +++++++++-- sina/src/Page/Login.elm | 8 ++++++-- sina/src/Page/SwitchInfo.elm | 16 ++++++++------- sina/src/Page/Switches.elm | 13 ++++++++++-- 6 files changed, 79 insertions(+), 13 deletions(-) create mode 100644 sina/src/Mi/POSSE.elm diff --git a/sina/src/Mi/POSSE.elm b/sina/src/Mi/POSSE.elm new file mode 100644 index 0000000..505548d --- /dev/null +++ b/sina/src/Mi/POSSE.elm @@ -0,0 +1,40 @@ +module Mi.POSSE exposing (Post, decoder, encoder, init) + +import Json.Decode as D +import Json.Encode as E + + +init : Post +init = + { title = "" + , body = "" + , url = "" + , tags = [] + } + + +type alias Post = + { title : String + , body : String + , url : String + , tags : List String + } + + +encoder : Post -> E.Value +encoder post = + E.object + [ ( "title", E.string post.title ) + , ( "body", E.string post.body ) + , ( "url", E.string post.url ) + , ( "tags", E.list E.string post.tags ) + ] + + +decoder : D.Decoder Post +decoder = + D.map4 Post + (D.field "title" D.string) + (D.field "body" D.string) + (D.field "url" D.string) + (D.field "tags" (D.list D.string)) diff --git a/sina/src/Model.elm b/sina/src/Model.elm index 63d2ab2..8e85936 100644 --- a/sina/src/Model.elm +++ b/sina/src/Model.elm @@ -4,6 +4,7 @@ import Browser exposing (UrlRequest(..)) import Browser.Navigation as Nav import Http import Mi +import Mi.POSSE import Mi.Switch exposing (Switch) import Mi.WebMention exposing (WebMention) import Route exposing (Route, routeParser) @@ -24,6 +25,7 @@ type alias Model = , webMentions : List WebMention , switchByID : Maybe Switch , webMentionByID : Maybe WebMention + , post : Mi.POSSE.Post } @@ -66,6 +68,7 @@ init _ url key = , webMentions = [] , switchByID = Nothing , webMentionByID = Nothing + , post = Mi.POSSE.init } , Nav.pushUrl key "/login" ) diff --git a/sina/src/Page/Index.elm b/sina/src/Page/Index.elm index c18c947..31088e0 100644 --- a/sina/src/Page/Index.elm +++ b/sina/src/Page/Index.elm @@ -5,10 +5,18 @@ import Html exposing (br, h2, img, p, s, span, text) import Html.Attributes exposing (height, src, width) import Iso8601 import Layout exposing (basic, template) -import Model exposing (Model) +import Mi +import Mi.Switch exposing (Switch) -view : Model -> Document msg +type alias Model a = + { a + | tokenData : Maybe Mi.TokenData + , front : Maybe Switch + } + + +view : Model a -> Document msg view { tokenData, front } = case tokenData of Nothing -> diff --git a/sina/src/Page/Login.elm b/sina/src/Page/Login.elm index d2bf911..744795f 100644 --- a/sina/src/Page/Login.elm +++ b/sina/src/Page/Login.elm @@ -5,10 +5,14 @@ import Html exposing (button, input, p, text) import Html.Attributes exposing (placeholder, value) import Html.Events exposing (onClick, onInput) import Layout exposing (basic, template) -import Model exposing (Model, Msg(..)) +import Model exposing (Msg(..)) -view : Model -> Document Msg +type alias Model a = + { a | token : Maybe String } + + +view : Model a -> Document Msg view model = basic "Login" [ p [] [ text "Enter the secret code. Unauthorized access is prohibited." ] diff --git a/sina/src/Page/SwitchInfo.elm b/sina/src/Page/SwitchInfo.elm index ead9d6e..e1ba284 100644 --- a/sina/src/Page/SwitchInfo.elm +++ b/sina/src/Page/SwitchInfo.elm @@ -1,17 +1,19 @@ module Page.SwitchInfo exposing (view) import Browser exposing (Document) -import Browser.Navigation as Nav -import Html exposing (a, br, button, h2, img, p, span, table, td, text, th, tr) -import Html.Attributes exposing (href, src, style) -import Html.Events exposing (onClick) +import Html exposing (br, img, p, span, text) +import Html.Attributes exposing (src) import Layout exposing (template) -import Model exposing (Model, Msg(..)) +import Mi.Switch exposing (Switch) import Page exposing (format) -import Time exposing (Month(..), utc) +import Time exposing (Month(..)) -view : Model -> Document Msg +type alias Model a = + { a | switchByID : Maybe Switch } + + +view : Model a -> Document msg view { switchByID } = case switchByID of Nothing -> diff --git a/sina/src/Page/Switches.elm b/sina/src/Page/Switches.elm index b4fd3dc..a5f02f7 100644 --- a/sina/src/Page/Switches.elm +++ b/sina/src/Page/Switches.elm @@ -6,12 +6,21 @@ import Html.Attributes exposing (height, href, src, style, width) import Html.Events exposing (onClick) import Iso8601 import Layout exposing (template) -import Model exposing (Model, Msg(..)) +import Mi.Switch exposing (Switch) +import Model exposing (Msg(..)) import Page exposing (format) import Time exposing (Month(..), utc) -view : Model -> Document Msg +type alias Model a = + { a + | front : Maybe Switch + , switches : List Switch + , switchPage : Int + } + + +view : Model a -> Document Msg view { front, switches, switchPage } = let frontInfo =