jbrowse-testing/reagent-test/src/reagent_test/core.cljs

74 lines
2.1 KiB
Clojure

(ns reagent-test.core
(:require [cljs.core.async :refer [<! go]]
[reagent-test.ncbi :refer [ncbi-search]]
[reagent.dom :as d]))
;; -------------------------
;; Global state
;; use this later
(def state {:search-query ""
:searching false})
(def search-query "")
;; -------------------------
;; Component data
(def action-btns [{:text "tools" :action #(js/console.log "hi")}
{:text "help" :action #(js/console.log "test4")}])
;; -------------------------
;; Components
(defn dropdown-or-action
"Render dropdown menu for an action button/menu"
[btn-item is-dropdown]
[:button {:class (if is-dropdown
"menu-button menu-dropdown-item"
"menu-button")}
:text (:text btn-item)
:on-click (let [action (:action btn-item)]
(if (nil? action)
#(dropdown-or-action btn-item true)
action))])
(defn search-form
"For searching for NCBI data"
[placeholder]
[:div {:style {:display "flex" :flex-direction "row" :align-items "center"}}
[:input {:on-change (fn [val] (set! search-query val))
:class "searchbar"
:style {:margin-right 8 :width 300}
:placeholder placeholder}]
[:select {:id "search_type" :class "searchbar" :style {:margin-right 8}}
[:option {:value "gene"} "Gene"]
[:option {:value "protein"} "Protein"]]
[:button {:class "searchbar button-primary" :on-click #(js/console.log "hi")} "Search!"]])
;; -------------------------
;; Views
(defn home-page []
[:div
[:h2 "NCBI Database Search"]
[:p "A groundbreaking, revolutionary app that does stuff."]
[:div {:class "button-container"}
(map (fn [btn] [:button
{:on-click #(dropdown-or-action btn false)
:class "menu-button"
:style {:margin-right -1}}
(:text btn)]) action-btns)]
[:br]
(search-form "Enter query...")])
;; -------------------------
;; Initialize app
(defn mount-root []
(d/render [home-page] (.getElementById js/document "app")))
(defn ^:export init! []
(mount-root))