add some bounty sorting

This commit is contained in:
pablodip 2018-01-18 05:45:42 +01:00
parent 26c740517b
commit bdbdc2e2d2
5 changed files with 67 additions and 42 deletions

View File

@ -2,7 +2,9 @@
(:require [reagent.core :as r] (:require [reagent.core :as r]
[re-frame.core :as rf] [re-frame.core :as rf]
[commiteth.common :refer [moment-timestamp [commiteth.common :refer [moment-timestamp
issue-url]])) issue-url]]
[commiteth.handlers :as handlers]
[commiteth.db :as db]))
(defn bounty-item [bounty] (defn bounty-item [bounty]
@ -60,40 +62,44 @@
(defn bounties-filters [] (defn bounties-filters []
[:div.open-bounties-filter [:div.open-bounties-filter
[bounties-filter "Value"] [bounties-filter "Value"]
[bounties-filter "Type"] [bounties-filter "Currency"]
[bounties-filter "Language"]
[bounties-filter "Date"] [bounties-filter "Date"]
[bounties-filter "More"]]) [bounties-filter "Owner"]])
(defn bounties-sort [] (defn bounties-sort []
(let [open? (r/atom false)] (let [open? (r/atom false)]
(fn [] (fn []
[:div.open-bounties-sort (let [current-sorting (rf/subscribe [::db/bounty-sorting-type])]
{:tab-index 0 [:div.open-bounties-sort
:on-blur #(reset! open? false)} {:tab-index 0
[:div.open-bounties-sort-element :on-blur #(reset! open? false)}
{:on-click #(swap! open? not)} [:div.open-bounties-sort-element
"Most Recent" {:on-click #(swap! open? not)}
[:div.icon-forward-white-box (db/bounty-sorting-types @current-sorting)
[:img [:div.icon-forward-white-box
{:src "icon-forward-white.svg"}]]] [:img
(when @open? {:src "icon-forward-white.svg"}]]]
[:div.open-bounties-sort-element-tooltip (when @open?
"TOOLTIP"])]))) [:div.open-bounties-sort-element-tooltip
(for [[sorting-type sorting-name] db/bounty-sorting-types]
[:div.open-bounties-sort-type
{:on-click #(do
(reset! open? false)
(rf/dispatch [::handlers/set-bounty-sorting-type sorting-type]))}
sorting-name])])]))))
(defn bounties-list [open-bounties] (defn bounties-list [open-bounties]
(let [order (rf/subscribe [:bounties-order])] [:div.ui.container.open-bounties-container
[:div.ui.container.open-bounties-container [:div.open-bounties-header "Bounties"]
[:div.open-bounties-header "Bounties"] [:div.open-bounties-filter-and-sort
[:div.open-bounties-filter-and-sort [bounties-filters]
[bounties-filters] [bounties-sort]]
[bounties-sort]] (if (empty? open-bounties)
(if (empty? open-bounties) [:div.view-no-data-container
[:div.view-no-data-container [:p "No recent activity yet"]]
[:p "No recent activity yet"]] (into [:div.ui.items]
(into [:div.ui.items] (for [bounty open-bounties]
(for [bounty open-bounties] [bounty-item bounty])))])
[bounty-item bounty])))]))
(defn bounties-page [] (defn bounties-page []

View File

@ -1,14 +1,19 @@
(ns commiteth.db) (ns commiteth.db)
(def bounty-sorting-types {::bounty-sorting-type|most-recent "Most recent"
::bounty-sorting-type|lowest-value "Lowest value"
::bounty-sorting-type|highest-value "Highest value"
::bounty-sorting-type|owner "Owner"})
(def default-db (def default-db
{:page :bounties {:page :bounties
:user nil :user nil
:repos-loading? false :repos-loading? false
:repos {} :repos {}
:activity-feed-loading? false :activity-feed-loading? false
:open-bounties-loading? false :open-bounties-loading? false
:open-bounties [] :open-bounties []
:owner-bounties {} :owner-bounties {}
:top-hunters [] :top-hunters []
:activity-feed [] :activity-feed []
:bounties-order ::bounties-order|most-recent}) ::bounty-sorting-type ::bounty-sorting-type|most-recent})

View File

@ -453,3 +453,8 @@
(fn [db [_]] (fn [db [_]]
(.removeEventListener js/window "click" close-dropdown) (.removeEventListener js/window "click" close-dropdown)
(assoc db :user-dropdown-open? false))) (assoc db :user-dropdown-open? false)))
(reg-event-db
::set-bounty-sorting-type
(fn [db [_ sorting-type]]
(assoc db ::db/bounty-sorting-type sorting-type)))

View File

@ -1,5 +1,6 @@
(ns commiteth.subscriptions (ns commiteth.subscriptions
(:require [re-frame.core :refer [reg-sub]])) (:require [re-frame.core :refer [reg-sub]]
[commiteth.db :as db]))
(reg-sub (reg-sub
:db :db
@ -82,6 +83,6 @@
(:user-dropdown-open? db))) (:user-dropdown-open? db)))
(reg-sub (reg-sub
:bounties-order ::db/bounty-sorting-type
(fn [db _] (fn [db _]
(:bounties-order db))) (::db/bounty-sorting-type db)))

View File

@ -484,8 +484,7 @@
.open-bounties-sort-element-tooltip { .open-bounties-sort-element-tooltip {
position: absolute; position: absolute;
right: 0; right: 0;
//margin-top: 12px; //padding: 16px 0;
padding: 16px 24px;
min-width: 200px; min-width: 200px;
border-radius: 8px; border-radius: 8px;
background-color: #1e3751; background-color: #1e3751;
@ -496,6 +495,15 @@
color: #ffffff; color: #ffffff;
} }
.open-bounties-sort-type {
padding: 19px 24px;
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.open-bounties-sort-type:hover {
cursor: pointer;
}
.icon-forward-white-box { .icon-forward-white-box {
width: 24px; width: 24px;
height: 24px; height: 24px;