Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add latest wods and lifts to dashboard #56

Merged
merged 1 commit into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 62 additions & 2 deletions src/com/spicy/app.clj
Original file line number Diff line number Diff line change
@@ -1,18 +1,78 @@
(ns com.spicy.app
(:require
[com.biffweb :as biff :refer [q]]
[com.spicy.middleware :as mid]
[com.spicy.movements.core :as movements]
[com.spicy.results.core :as results]
[com.spicy.results.ui :as r]
[com.spicy.settings :as settings]
[com.spicy.ui :as ui]
[com.spicy.workouts.core :as workouts]
[com.spicy.workouts.ui :as w]
[xtdb.api :as xt]))


(defn app
[{:keys [session biff/db] :as ctx}]
(let [{:user/keys [email foo bar]} (xt/entity db (:uid session))]
(ui/page {:session session} [:div "TODO"])))
(let [{:user/keys [email foo bar]} (xt/entity db (:uid session))
wod-results (map second (q db '{:find [d (pull r [*
{:result/type
[*
{:result/workout [*]}
{:result-set/_parent [*]}]}])]
:in [[user]]
:where [[r :result/user user]
[r :result/type type]
[r :result/date d]
[type :result/workout]]
:limit 5
:order-by [[d :desc]]}
[(:uid session)]))
strength-results (map second (q db '{:find [d (pull r [*
{:result/type
[*
{:result/movement [*]}
{:result-set/_parent [*]}]}])]
:in [[user]]
:where [[r :result/user user]
[r :result/type type]
[r :result/date d]
[type :result/movement]]
:limit 5
:order-by [[d :desc]]}
[(:uid session)]))]
(ui/page
{:session session}
(ui/panel [:div.flex.gap-4
[:div.p-4.border-2.border-black.bg-white
[:h2.text-2xl.font-bold "Latest WODs"]
(if (zero? (count wod-results))
[:div.flex.flex-col.items-center
[:p "Log a WOD result to see it show up here!"]
[:a.btn {:href "/app/workouts"} "View Workouts"]]
[:div (map (fn [result]
(let [{:keys [workout name date] :as normalized} (r/normalized-result result)]
[:div.mb-2
[:a.text-lg.font-sans {:href (str "/app/workouts/" (:xt/id workout))} [:h3.font-sans name]]
[:div
[:span.font-bold (w/display-summed-score normalized)]
[:span.text-gray-700.ml-2 date]]])) wod-results)])]
[:div.p-4.border-2.border-black.bg-white
[:h2.text-2xl.font-bold "Latest Lifts"]
(if (zero? (count strength-results))
[:div.flex.flex-col.items-center
[:p "Log a lift to see it show up here!"]
[:a.btn {:href "/app/movements"} "View Movements"]]

[:div (map (fn [result]
(let [{:keys [movement name date sets] :as normalized} (r/normalized-result result)]
[:div.mb-2
[:a.text-lg.font-sans {:href (str "/app/movements/" (:xt/id movement))} [:h3.font-sans.capitalize (str name " (" (movements/sets-n-reps sets) ")")]]
[:div
[:span.font-bold (apply max (map #(if (= :pass (:result-set/status %))
(:result-set/weight %)
0) sets))]
[:span.text-gray-700.ml-2 date]]])) strength-results)])]]))))


(def about-page
Expand Down
50 changes: 24 additions & 26 deletions src/com/spicy/movements/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
[:div.flex.flex-wrap.justify-center.sm:justify-between.gap-4.mt-8
[:h1.text-5xl.w-fit.self-center "Movements"]
[:select.btn.text-base.w-32.h-12.teal-focus.hover:cursor-pointer {:name "type"
:onchange "window.open('?type=' + this.value,'_self')"}
:onchange "window.open('?type=' + this.value,'_self')"}
[:option.text-base {:value :strength :selected (or (= (:type params) "stregnth") (empty? (:type params)))} "Strength"]
[:option.text-base {:value :gymnastic :selected (= (:type params) "gymnastic")} "Gymnastic"]
[:option.text-base {:value :monostructural :selected (= (:type params) "monostructural")} "Cardio"]]]
Expand Down Expand Up @@ -180,14 +180,16 @@
[{:keys [biff/db path-params session] :as ctx}]
(let [movement-id (parse-uuid (:id path-params))
m (xt/entity db movement-id)
movement-results (biff/q db '{:find (pull result [* {:result/type
[*
{:result-set/_parent [*]}]}])
:in [[user movement]]
:where [[result :result/user user]
[result :result/type type]
[type :result/movement movement]]}
[(:uid session) movement-id])
movement-results (map second (biff/q db '{:find [date (pull result [* {:result/type
[*
{:result-set/_parent [*]}]}])]
:in [[user movement]]
:where [[result :result/user user]
[result :result/type type]
[result :result/date date]
[type :result/movement movement]]
:order-by [[date :desc]]}
[(:uid session) movement-id]))
workouts (biff/q db '{:find (pull w [*])
:in [[movement user]]
:where [[w :workout/name]
Expand Down Expand Up @@ -238,17 +240,13 @@
:class (str "appearance-none p-7 border-2 border-r-0 border-black cursor-pointer "
"checked:bg-brand-teal checked:text-brand-teal checked:color-brand-teal hover:bg-brand-teal checked:border-black checked:ring-0 checked:ring-offset-0 checked:ring-brand-teal checked:ring-opacity-100 focus:outline-none focus:ring-0 focus:ring-offset-0 focus:ring-opacity-100")
:value :hit
:type :checkbox}]
]]
[:input{:name (str "weight-" set-number)
:type :checkbox}]]]
[:input {:name (str "weight-" set-number)
:id (str "weight-" set-number)
:class (str "p-4 border-2 border-black w-1/2 text-center font-bold teal-focus ")
:required true
:type :number}]
[:p.m-0.bg-white.p-4.border-2.border-l-0.border-black.font-medium.whitespace-nowrap (str "x " reps " reps")]

]
])
[:p.m-0.bg-white.p-4.border-2.border-l-0.border-black.font-medium.whitespace-nowrap (str "x " reps " reps")]]])


(defn get-constant-strength-sets
Expand Down Expand Up @@ -298,16 +296,16 @@
:reps reps})])
[:div.flex.flex-col.justify-center.items-center.gap-4
[:input.pink-input.teal-focus.mt-4.mx-auto
{:type "date"
:name "date"
:value (biff/format-date
(biff/now) "YYYY-MM-dd")}]
[:textarea#notes
{:name "notes"
:placeholder "notes"
:rows 7
:class (str "w-full pink-input teal-focus")}]
[:button.btn "Submit"]])))
{:type "date"
:name "date"
:value (biff/format-date
(biff/now) "YYYY-MM-dd")}]
[:textarea#notes
{:name "notes"
:placeholder "notes"
:rows 7
:class (str "w-full pink-input teal-focus")}]
[:button.btn "Submit"]])))


(defn variable-reps-form
Expand Down
2 changes: 1 addition & 1 deletion src/com/spicy/results/ui.clj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
(let [{:keys [workout movement description sets name notes date]} (normalized-result result)]
[:div.flex.flex-col.max-w-sm.sm:max-w-xl.mx-auto#result-ui
[:.flex.flex-row.items-baseline.justify-between.mb-3
[:a.text-2xl.font-bold {:href (str "/app/workouts/" (string/lower-case name))} name]
[:a.text-2xl.font-bold {:href (str "/app/workouts/" (:xt/id workout))} name]
[:p.whitespace-pre-wrap.sm:text-left.max-w-xs.text-gray-700.mb-0 date]]
[:.flex.justify-between
[:div.flex.flex-col.gap-2
Expand Down