#30: Tremendous progress, now understand reg-sub model

Although there's no actual collection of data from the back end, the user interface is now mostly working. And, I flatter myself, looking good.
This commit is contained in:
simon 2017-03-24 10:32:31 +00:00
parent 9392091428
commit d36c58b44c
12 changed files with 112 additions and 114 deletions

View file

@ -19,9 +19,18 @@
* USA. * USA.
*/ */
h1 {
width:100%;
background-color: rgb(7, 57, 106);
color: white;
font-family: "Archivo Black", "Sans Bold", "Arial Black", sans-serif;
font-weight: normal;
margin-top: 0;
}
/* desktops and laptops, primarily. Adapted to mouse; targets may be small */ /* desktops and laptops, primarily. Adapted to mouse; targets may be small */
@media all and (min-device-width: 1025px) { @media all and (min-device-width: 1025px) {
/* top-of-page navigation, not editable, provided by Smeagol */ /* top-of-page navigation, not editable, provided by Smeagol */
#nav{ #nav{
margin: 0; margin: 0;

View file

@ -373,8 +373,7 @@ th {
h1 { h1 {
/* I wouldn't normally use a px value, but the menu icon is 49px wide */ /* I wouldn't normally use a px value, but the menu icon is 49px wide */
padding: 0.25em 5%; padding: 0.25em 5%;
padding-left: 100px; padding-left: 75px;
text-align: right;
} }
.hidden { .hidden {

View file

@ -12,7 +12,7 @@
[youyesyet.ui-utils :as ui] [youyesyet.ui-utils :as ui]
[youyesyet.views.about :as about] [youyesyet.views.about :as about]
[youyesyet.views.electors :as electors] [youyesyet.views.electors :as electors]
[youyesyet.views.home :as home] [youyesyet.views.issue :as issue]
[youyesyet.views.issues :as issues] [youyesyet.views.issues :as issues]
[youyesyet.views.map :as maps] [youyesyet.views.map :as maps]
[youyesyet.views.followup-request :as request]) [youyesyet.views.followup-request :as request])
@ -22,12 +22,12 @@
(defn about-page [] (defn about-page []
(about/panel)) (about/panel))
(defn home-page []
(home/panel))
(defn issues-page [] (defn issues-page []
(issues/panel)) (issues/panel))
(defn issue-page []
(issue/panel))
(defn map-page [] (defn map-page []
(maps/panel)) (maps/panel))
@ -35,16 +35,16 @@
(request/panel)) (request/panel))
(def pages (def pages
{:home #'home-page {:about #'about-page
:issues #'issues-page :issues #'issues-page
:issue #'issue-page
:map #'map-page :map #'map-page
:about #'about-page}) })
(defn page [] (defn page []
[:div [:div
[:header [:header
[ui/navbar] [ui/navbar]]
[:h1 "You yes yet?"]]
[(pages @(rf/subscribe [:page]))]]) [(pages @(rf/subscribe [:page]))]])
;; ------------------------- ;; -------------------------
@ -60,6 +60,9 @@
(secretary/defroute "/issues" [] (secretary/defroute "/issues" []
(rf/dispatch [:set-active-page :issues])) (rf/dispatch [:set-active-page :issues]))
(secretary/defroute "/issue/:issue" {issue :issue}
(rf/dispatch [:set-issue issue]))
(secretary/defroute "/map" [] (secretary/defroute "/map" []
(rf/dispatch [:set-active-page :map])) (rf/dispatch [:set-active-page :map]))
@ -76,9 +79,6 @@
;; ------------------------- ;; -------------------------
;; Initialize app ;; Initialize app
(defn fetch-docs! []
(GET (str js/context "/docs")
{:handler #(rf/dispatch [:set-docs %])}))
(defn mount-components [] (defn mount-components []
(r/render [#'page] (.getElementById js/document "app"))) (r/render [#'page] (.getElementById js/document "app")))
@ -86,6 +86,5 @@
(defn init! [] (defn init! []
(rf/dispatch-sync [:initialize-db]) (rf/dispatch-sync [:initialize-db])
(load-interceptors!) (load-interceptors!)
(fetch-docs!)
(hook-browser-navigation!) (hook-browser-navigation!)
(mount-components)) (mount-components))

View file

@ -30,4 +30,22 @@
;;; 'client-state'. ;;; 'client-state'.
(def default-db (def default-db
{:page :home}) ;;; the currently displayed 'page' within the app.
{:page :home
;;; the currently selected address, if any.
:address {:address "13 Imaginary Terrace, IM1 3TE"}
;;; a list of the addresses in the current location at which there
;;; are electors registered.
:addresses []
;;; electors at the currently selected address
:electors [{:name "Alan Anderson" :gender :male :intention :no}
{:name "Ann Anderson" :gender :female}
{:name "Alex Anderson" :gender :fluid :intention :yes}
{:name "Andy Anderson" :intention :yes}]
;;; the issues selected for the issues page on this day.
:issues {"Currency" "Scotland could keep the Pound, or use the Euro. But we could also set up a new currency of our own. Yada yada yada"
"Monarchy" "Scotland could keep the Queen. This is an issue to be decided after independence. Yada yada yada"
"Defence" "Scotland will not have nuclear weapons, and will probably not choose to engage in far-off wars. But we could remain members of NATO"}
;;; the issue from among those issues which is currently selected.
:issue "Currency"
})

View file

@ -13,6 +13,7 @@
(assoc db :page page))) (assoc db :page page)))
(reg-event-db (reg-event-db
:set-docs :set-issue
(fn [db [_ docs]] (fn [db [_ issue]]
(assoc db :docs docs))) (assoc (assoc db :issue issue) :page :issue)))

View file

@ -7,6 +7,11 @@
(:page db))) (:page db)))
(reg-sub (reg-sub
:docs :issues
(fn [db _] (fn [db _]
(:docs db))) (:issues db)))
(reg-sub
:issue
(fn [db _]
(:issue db)))

View file

@ -33,6 +33,8 @@
(defn panel (defn panel
"Generate the about panel." "Generate the about panel."
[] []
[:div
[:h1 "You Yes Yet?"]
[:div.container {:id "main-container"} [:div.container {:id "main-container"}
[:h2 "Pre-alpha/proof of concept"] [:h2 "Pre-alpha/proof of concept"]
[:p [:p
@ -55,4 +57,4 @@
[:img {:src "img/gnu.small.png" :alt "Free Software Foundation" :height "24" :width "24"}] [:img {:src "img/gnu.small.png" :alt "Free Software Foundation" :height "24" :width "24"}]
" Licensed under the " " Licensed under the "
[:a {:href "http://www.gnu.org/licenses/gpl-2.0.html"} [:a {:href "http://www.gnu.org/licenses/gpl-2.0.html"}
"GNU General Public License v2.0"]]]) "GNU General Public License v2.0"]]]])

View file

@ -32,6 +32,14 @@
;;; See https://github.com/simon-brooke/youyesyet/blob/master/doc/specification/userspec.md#electors-view ;;; See https://github.com/simon-brooke/youyesyet/blob/master/doc/specification/userspec.md#electors-view
;;; The design for this panel is one column per elector within the address.
;;; Each column contains
;;; 1. a stick figure identifying gender (for recognition);
;;; 2. the elector's name;
;;; 3. one icon for each option on the ballot;
;;; 4. an 'issues' icon.
;;; The mechanics of how this panel is laid out don't matter.
(defn panel (defn panel
"Generate the electors panel." "Generate the electors panel."
[] []

View file

@ -1,49 +0,0 @@
(ns youyesyet.views.home
(:require [re-frame.core :as rf]
[markdown.core :refer [md->html]]
[youyesyet.ui-utils :as ui]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;
;;;; youyesyet.views.electors: home view for youyesyet.
;;;;
;;;; This program is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU General Public License
;;;; as published by the Free Software Foundation; either version 2
;;;; of the License, or (at your option) any later version.
;;;;
;;;; This program is distributed in the hope that it will be useful,
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;;; GNU General Public License for more details.
;;;;
;;;; You should have received a copy of the GNU General Public License
;;;; along with this program; if not, write to the Free Software
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
;;;; USA.
;;;;
;;;; Copyright (C) 2016 Simon Brooke for Radical Independence Campaign
;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; The pattern from the re-com demo (https://github.com/Day8/re-com) is to have
;;; one source file/namespace per view. Each namespace contains a function 'panel'
;;; whose output is an enlive-style specification of the view to be redered.
;;; I propose to follow this pattern. This file will provide the home view.
(defn panel
"Generate the home panel."
[]
[:div.container {:id "main-container"}
(ui/big-link "About" "#/about")
(ui/big-link "Map" "#/map")
[:div.jumbotron
[:h1 "You Yes Yet?"]
[:p "Time to start building your site!"]
[:p [:a.btn.btn-primary.btn-lg {:href "http://luminusweb.net"} "Learn more »"]]]])
(when-let [docs @(rf/subscribe [:docs])]
[:div.row
[:div.col-md-12
[:div {:dangerouslySetInnerHTML
{:__html (md->html docs)}}]]])

View file

@ -1,5 +1,5 @@
(ns youyesyet.views.issue (ns youyesyet.views.issue
(:require [re-frame.core :refer [reg-sub]] (:require [re-frame.core :refer [reg-sub subscribe]]
[youyesyet.ui-utils :as ui] [youyesyet.ui-utils :as ui]
[youyesyet.views.issues :as issues])) [youyesyet.views.issues :as issues]))
@ -31,3 +31,16 @@
;;; one source file/namespace per view. Each namespace contains a function 'panel' ;;; one source file/namespace per view. Each namespace contains a function 'panel'
;;; whose output is an enlive-style specification of the view to be redered. ;;; whose output is an enlive-style specification of the view to be redered.
;;; I propose to follow this pattern. This file will (eventually) provide the single issue view. ;;; I propose to follow this pattern. This file will (eventually) provide the single issue view.
(defn panel
"Generate the issue panel."
[]
(let [issue @(subscribe [:issue])
issues @(subscribe [:issues])]
[:div
[:h1 issue]
[:div.container {:id "main-container"}
(ui/back-link)
[:div {:id "issue"}
[:div {:id "issue-text"}
(issues issue)]]]]))

View file

@ -1,5 +1,5 @@
(ns youyesyet.views.issues (ns youyesyet.views.issues
(:require [re-frame.core :refer [reg-sub]] (:require [re-frame.core :refer [reg-sub subscribe]]
[youyesyet.ui-utils :as ui])) [youyesyet.ui-utils :as ui]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -33,26 +33,14 @@
;;; See https://github.com/simon-brooke/youyesyet/blob/master/doc/specification/userspec.md#issues-view ;;; See https://github.com/simon-brooke/youyesyet/blob/master/doc/specification/userspec.md#issues-view
(def *issues* ;;; Simple list of the issues of the day.
;;; this is a dummy for the map fetched at load-time
{"Currency" "Lorem ipsum dolar sit amet"
"Head of state" "Lorem ipsum dolar sit amet"
"NATO and defence" "Lorem ipsum dolar sit amet"})
(defn get-issues-fn
"This is a temporary dummy for the function which will pull the issues from
the server."
[]
*issues*)
;;; By memoising the function we arange that it is called only once
(def get-issues (memoize get-issues-fn))
(defn panel (defn panel
"Generate the issues panel." "Generate the issues panel."
[] []
(let [issues @(subscribe [:issues])]
[:div
[:h1 "Issues"]
[:div.container {:id "main-container"} [:div.container {:id "main-container"}
(ui/back-link) (ui/back-link)
[:div {:id "issue-list"} [:div {:id "issue-list"}
] (map (fn [k] (ui/big-link k (str "#/issue/" k))) (keys issues))]]]))
(map (fn [k] (ui/big-link k (str "#/issue/" k))) (keys (get-issues)))])

View file

@ -41,6 +41,11 @@
;;; Note that this is raw reagent stylee; it should be refactoed into re-frame stylee ;;; Note that this is raw reagent stylee; it should be refactoed into re-frame stylee
;;; when I understand it better. ;;; when I understand it better.
;;; There should be one flag on the map for each address record currently in frame.
;;; Clicking the flag sets that address as the current address in the app state,
;;; and redirects to the electors view. How we handle blocks of flats needs further
;;; thought.
;; which provider to use ;; which provider to use
(def *map-provider* :osm) (def *map-provider* :osm)