makes client selection not contanimate other tabs
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
(ns auto-ap.ssr.company-dropdown
|
||||
(:require [auto-ap.datomic :refer [conn pull-attr pull-many]]
|
||||
(:require [auto-ap.datomic :refer [conn pull-many]]
|
||||
[auto-ap.graphql.utils :refer [cleanse-query]]
|
||||
[auto-ap.logging :as alog]
|
||||
[auto-ap.solr :as solr]
|
||||
[auto-ap.ssr-routes :as ssr-routes]
|
||||
[auto-ap.ssr.hx :as hx]
|
||||
@@ -10,7 +11,9 @@
|
||||
[clojure.string :as str]
|
||||
[datomic.api :as dc]
|
||||
[hiccup2.core :as hiccup]
|
||||
[iol-ion.query :refer [can-see-client?]]))
|
||||
[iol-ion.query :refer [can-see-client?]]
|
||||
[clojure.data.json :as json]))
|
||||
|
||||
|
||||
(defn dropdown-search-results* [{:keys [options]}]
|
||||
[:ul
|
||||
@@ -25,6 +28,7 @@
|
||||
:request-method :put)
|
||||
:hx-target "#company-dropdown"
|
||||
:hx-headers (hx/json {"x-clients" (pr-str [:group group])})
|
||||
"@click" (format "globalClientSelection={group: %s}" (hx/json group))
|
||||
:hx-swap "outerHTML"
|
||||
:hx-trigger "click"}
|
||||
name]
|
||||
@@ -34,6 +38,7 @@
|
||||
:request-method :put)
|
||||
:hx-target "#company-dropdown"
|
||||
:hx-headers (format "{\"x-clients\": \"[%d]\"}" id)
|
||||
"@click" (format "globalClientSelection={selected: [%d]}" id)
|
||||
:hx-swap "outerHTML"
|
||||
:hx-trigger "click"}
|
||||
name])]])])
|
||||
@@ -64,11 +69,18 @@
|
||||
(dropdown-search-results* {:options (get-clients identity (get (:query-params request) "search-text"))})))
|
||||
|
||||
(defn dropdown [{:keys [client-selection client identity clients]}]
|
||||
(alog/peek ::clients clients)
|
||||
[:div#company-dropdown
|
||||
[:script
|
||||
(hiccup/raw
|
||||
"localStorage.setItem(\"last-client-id\", \"" (:db/id client) "\")" "\n"
|
||||
"localStorage.setItem(\"last-selected-clients\", " (pr-str (pr-str client-selection)) ")")]
|
||||
"localStorage.setItem(\"last-selected-clients\", " (json/write-str (json/write-str client-selection))
|
||||
#_(cond (:group client-selection)
|
||||
(:group client-selection)
|
||||
(:selected client-selection)
|
||||
(:selected client-selection)
|
||||
:else
|
||||
client-selection) ")")]
|
||||
[:div
|
||||
[:button#company-dropdown-button {:class "text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-4 py-2.5 text-center inline-flex items-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800"
|
||||
:type "button"}
|
||||
@@ -80,7 +92,7 @@
|
||||
|
||||
(and client
|
||||
(= 1 (count clients)))
|
||||
( :client/name client)
|
||||
(:client/name client)
|
||||
|
||||
:else
|
||||
(str (count clients) " Companies"))
|
||||
@@ -116,6 +128,8 @@
|
||||
:active-client
|
||||
:request-method :put)
|
||||
:hx-target "#company-dropdown"
|
||||
|
||||
"@click" "globalClientSelection=\"mine\""
|
||||
:hx-headers "{\"x-clients\": \":mine\"}"
|
||||
:hx-swap "outerHTML"
|
||||
:hx-trigger "click"}
|
||||
@@ -127,6 +141,7 @@
|
||||
:active-client
|
||||
:request-method :put)
|
||||
:hx-target "#company-dropdown"
|
||||
"@click" "globalClientSelection=\"all\""
|
||||
:hx-headers "{\"x-clients\": \":all\"}"
|
||||
:hx-swap "outerHTML"
|
||||
:hx-trigger "click"}
|
||||
@@ -161,7 +176,7 @@ function initCompanyDropdown() {
|
||||
(defn active-client [{:keys [identity params] :as request}]
|
||||
(assoc
|
||||
(html-response
|
||||
(dropdown {:client-selection (:client-selection (:session request))
|
||||
(dropdown {:client-selection (:client-selection request)
|
||||
:clients (:clients request)
|
||||
:client (:client request)
|
||||
:identity identity}))
|
||||
|
||||
Reference in New Issue
Block a user