(page "index.html" (:require [cure53.dom-purify :as dom-purify]) (:require-macros [feed-archive.let-promise :refer [let-promise]])) (defc state {"base-url" "http://roachnotes.com" "pull-time" "" "feeds" []}) (defc= pull-time (get state "pull-time")) (defc= feeds (get state "feeds")) (defn setup-state [base-url] (let-promise [[resp (js/fetch (str base-url "/current"))] [data (.json resp)]] (swap! state merge (js->clj data)))) (defc= base-url (get state "base-url")) (cell= (setup-state base-url)) (defn make-feed-getter [out-cell] (fn [base-url path] (let-promise [[resp (js/fetch (str base-url "/" path))] [data (.json resp)]] (reset! out-cell (js->clj data))))) (defn get-feed-entry-cells [base-url feed] (let [feed-cell (cell {}) items (cell= (get feed-cell "items")) item-count (cell= (count items)) get-feed (make-feed-getter feed-cell) path (cell= (get feed "path" "")) url (cell= (get feed "url" "")) title (cell= (get feed "title" ""))] (cell= (get-feed base-url path)) [url title path feed-cell items item-count])) (defn make-item-getter [out-cell] (fn [base-url feed-path item-path] (let-promise [[resp (js/fetch (str base-url "/" feed-path item-path))] [data (.json resp)]] (reset! out-cell (js->clj data))))) (defn get-item-cells [item] (let [item-cell (cell {}) get-item (make-item-getter item-cell)] [get-item (cell= (get item "title")) (cell= (get item "path")) (cell= (get item-cell "link")) (cell= (.sanitize js/DOMPurify (get item-cell "content")))])) (cell= (println pull-time)) (html (head (link :href "app.css" :rel "stylesheet" :type "text/css")) (body (loop-tpl :bindings [feed feeds] (let [[url title path feed-cell items item-count] (get-feed-entry-cells base-url feed)] (section (if-tpl (cell= (> item-count 0)) (article (h2 title) (p url) (ul (loop-tpl :bindings [item items] (let [[get-item title item-path link content] (get-item-cells item)] (li (h3 (a :href link title) " " (button :click #(get-item @base-url @path @item-path) ">>")) (p :html content) )))))))))))