Skip to content

Commit

Permalink
implemented giggin page
Browse files Browse the repository at this point in the history
  • Loading branch information
BennettSRobinson committed Jun 29, 2022
1 parent 4dba292 commit d86ccdd
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 3 deletions.
2 changes: 1 addition & 1 deletion giggin/shadow-cljs.edn
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
:devtools
{:after-load giggin.core/main
:http-root "public"
:http-port 3000}}}}
:http-port 3001}}}}
6 changes: 6 additions & 0 deletions giggin/src/giggin/components/footer.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(ns giggin.components.footer)

(defn footer
[]
[:footer
[:img {:src "img/giggin-icon.png" :alt "Giggin Logo"}]])
20 changes: 20 additions & 0 deletions giggin/src/giggin/components/gigs.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(ns giggin.components.gigs
(:require [giggin.state :as state]
[giggin.helpers :refer [format-price]]))

(defn gigs
[]
(let [add-to-order #(swap! state/orders update % inc)]
[:main
[:div.gigs
(for [{:keys [id img title price desc]} (vals @state/gigs)]
[:div.gig {:key id}
[:img.gig__artwork {:src img :alt title}]
[:div.gig__body
[:div.gig__title
[:div.btn.btn--primary.float--right.tooltip
{:data-tooltip "Add to order"
:on-click #(add-to-order id)}
[:i.icon.icon--plus]] title]
[:p.gig__price (format-price price)]
[:p.gig__desc desc]]])]]))
6 changes: 6 additions & 0 deletions giggin/src/giggin/components/header.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(ns giggin.components.header)

(defn header
[]
[:header
[:img.logo {:src "img/giggin-logo.svg" :alt "Giggin Logo"}]])
51 changes: 51 additions & 0 deletions giggin/src/giggin/components/orders.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
(ns giggin.components.orders
(:require [giggin.state :as state]
[giggin.helpers :refer [format-price]]))

(defn total
[]
(->> @state/orders
(map (fn [[id quant]]
(* quant (get-in @state/gigs [id :price]))))
(reduce +)))



(defn orders
[]
(let [remove-from-order #(swap! state/orders dissoc %)
remove-all-orders #(reset! state/orders {})
decrement-order #(swap! state/orders update % dec)]
[:aside
(if (empty? @state/orders)
[:div.empty
[:div.title "You don't have any orders"]
[:div.subtitle "Click on a + to add an order"]]
[:div.order
[:div.body
(for [[id quant] @state/orders]
[:div.item {:key id}
[:div.img
[:img {:src (get-in @state/gigs [id :img])
:alt (get-in @state/gigs [id :title])}]
[:div.content
[:p.title (str (get-in @state/gigs [id :title]) " \u00D7 " quant)]]
[:div.action
[:div.price (format-price (* (get-in @state/gigs [id :price]) quant))]
[:button.btn.btn--link.tooltip
{:data-tooltip "Remove"
:on-click
#(cond
(> quant 1) (decrement-order id)
(= quant 1) (remove-from-order id))}
[:i.icon.icon--cross]]]]])]
[:div.total
[:hr]
[:div.item
[:div.content "Total"]
[:div.action
[:div.price (format-price (total))]]
[:button.btn.btn--link.tooltip
{:data-tooltip "Remove all"
:on-click #(remove-all-orders)}
[:i.icon.icon--delete]]]]])]))
14 changes: 12 additions & 2 deletions giggin/src/giggin/core.cljs
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
(ns giggin.core
(:require [reagent.core :as r]))
(:require [reagent.core :as r]
[giggin.components.header :refer [header]]
[giggin.components.gigs :refer [gigs]]
[giggin.components.orders :refer [orders]]
[giggin.components.footer :refer [footer]]))



(defn app
[]
[:div.container])
[:div.container
[header]
[gigs]
[orders]
[footer]])

(defn ^:export main
[]
Expand Down
5 changes: 5 additions & 0 deletions giggin/src/giggin/helpers.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(ns giggin.helpers)

(defn format-price
[cents]
(str " $" (/ cents 100)))
2 changes: 2 additions & 0 deletions giggin/src/giggin/state.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
(ns giggin.state
(:require [reagent.core :as r]))

(def orders (r/atom {}))

(def gigs (r/atom {:gig-01 {:id :gig-01
:title "Macaron"
:artist "Baher Khairy"
Expand Down

0 comments on commit d86ccdd

Please sign in to comment.