Re-render the sidebar on tab update/activation
This commit is contained in:
parent
74add41ccd
commit
3749fef8c4
@ -1,6 +1,5 @@
|
||||
(ns looped-in.background
|
||||
(:require [clojure.core.match :refer [match]]
|
||||
[cljs.core.async :refer [go <!]]
|
||||
(:require [cljs.core.async :refer [go <!]]
|
||||
[ajax.core :refer [GET]]
|
||||
[looped-in.hackernews :as hn]
|
||||
[looped-in.logging :as log]
|
||||
@ -52,13 +51,12 @@
|
||||
ids (map #(% "objectID") hits)
|
||||
num-comments (total-num-comments hits)]
|
||||
(reset! object-ids ids)
|
||||
(-> js/browser
|
||||
(.-runtime)
|
||||
(.sendMessage (clj->js {:type "objectIds"
|
||||
:ids @object-ids})))
|
||||
(set-badge-text! (str num-comments)))))
|
||||
|
||||
(defn handle-message [msg]
|
||||
(match (.-type msg)
|
||||
"popupOpened" (channel->promise (go @object-ids))
|
||||
x (log/error "Unknown popup message type" x)))
|
||||
|
||||
(defn handle-browser-action [tab]
|
||||
(-> js/browser (.-sidebarAction) (.open)))
|
||||
|
||||
@ -72,11 +70,6 @@
|
||||
(.-onUpdated)
|
||||
(.addListener handle-tab-update))
|
||||
|
||||
(-> js/browser
|
||||
(.-runtime)
|
||||
(.-onMessage)
|
||||
(.addListener handle-message))
|
||||
|
||||
(-> js/browser
|
||||
(.-browserAction)
|
||||
(.-onClicked)
|
||||
|
@ -3,7 +3,8 @@
|
||||
[goog.html.sanitizer.HtmlSanitizer :as Sanitizer]
|
||||
[cljs.core.async :refer [go <!]]
|
||||
[looped-in.hackernews :as hn]
|
||||
[looped-in.promises :refer [promise->channel]])
|
||||
[looped-in.promises :refer [promise->channel]]
|
||||
[looped-in.logging :as log])
|
||||
(:import (goog.ui Zippy)))
|
||||
|
||||
(defn log [& args]
|
||||
@ -62,12 +63,19 @@
|
||||
(log items)
|
||||
(dom/append $storiesContainer $stories)))
|
||||
|
||||
(go (-> js/browser
|
||||
(.-runtime)
|
||||
(.sendMessage #js {:type "popupOpened"})
|
||||
(promise->channel)
|
||||
(<!)
|
||||
(hn/fetch-items)
|
||||
(<!)
|
||||
((fn [items] (filter #(not (nil? %)) items)))
|
||||
(render-items)))
|
||||
(defn fetch-and-render-items [ids]
|
||||
(go (-> ids
|
||||
(hn/fetch-items)
|
||||
(<!)
|
||||
((fn [items] (filter #(not (nil? %)) items)))
|
||||
(render-items))))
|
||||
|
||||
(defn handle-message [msg]
|
||||
(case (.-type msg)
|
||||
"objectIds" (fetch-and-render-items (.-ids msg))
|
||||
(log/error (str "Unknown message type " (.-type msg)))))
|
||||
|
||||
(-> js/browser
|
||||
(.-runtime)
|
||||
(.-onMessage)
|
||||
(.addListener handle-message))
|
||||
|
Loading…
Reference in New Issue
Block a user