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

Display and navigate b/w organisations in the sidebar #12

Merged
merged 18 commits into from
Oct 1, 2019

Conversation

prabhanshuguptagit
Copy link
Contributor

No description provided.

@prabhanshuguptagit prabhanshuguptagit changed the title Sidebar navigate orgs Display and navigate b/w organisations in the sidebar Sep 16, 2019

(defn retrieve-by-user
[user-id]
{:success (vec (db/retrieve-by-user user-id))})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the conversion to vector?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to convert the db response from a clojure sequence to valid JSON for the HTTP response. I missed the fact that it's already being taken care of by the wrap-json-response middleware. Getting rid of this.

@@ -49,6 +50,7 @@
(:user @formdata)
(fn [res]
(swap! error assoc :message "")
(user-api/get-data!)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The on-click fn here is the same as that in login.cljs.
Maybe you can extract these out into one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this bit needs some refactoring. I'm planning on doing that in a separate PR in #14 .

@prabhanshuguptagit prabhanshuguptagit marked this pull request as ready for review September 19, 2019 12:42

(defn retrieve-by-user
[request]
(let [{user-id :id} (:identity request)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(let [{user-id :id} (:identity request)]
(let [user-id (get-in request [:identity :id])]

@@ -9,8 +9,9 @@
[villagebook.config :as config]))

(def apiroutes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(def apiroutes
(def api-routes

@@ -1,11 +1,18 @@
(ns villagebookUI.api.organisation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capitals in the ns name seems odd.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes🤷‍♂ but decided to stick with it, changing would be too much effort.

:error-handler error-handler-fn}))
{:handler handler-fn
:error-handler error-handler-fn
:finally finally-fn}))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation seems off here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also just call them success-handler, error-handler, and finalizer. The -fn seems unnecessary, but ymmv.

@@ -19,7 +20,10 @@
[:form.inline-block {:on-submit (fn [e]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract this handler function out. Don't write more than a line of code inside the view, it isn't as tangible, and is not testable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(.preventDefault e) can stay perhaps, because it is specific to the view.

@@ -46,6 +47,7 @@
(:user @formdata)
(fn [res]
(swap! error assoc :message "")
(fetchers/fetch-user!)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract out the on-click function here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will refactor this bit in #14

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merged #14 into this branch.

@@ -27,7 +28,7 @@
(let [formdata (r/atom {})
error (r/atom {})]
(fn []
(if @store/user
(if (user-store/read)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Structure this as a guard clause instead? Also, extract the else part into another function, login-form perhaps. This will improve the legibility of this function, and let you reuse the form elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've refactored this here in a separate WIP PR.

(doall
(for [org (org-store/get-all)
:let [id (:id org)]]
[:li.item {:key (:id org)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[:li.item {:key (:id org)
[:li.item {:key id

[:a.sidebar-link [utils/patch "#5fcc5f"] "Org 1"]]
[:li.item
[:a.sidebar-link [utils/patch "#ff8383"] "Org 2"]]
(doall
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure the doall is necessary here?

Copy link
Contributor Author

@prabhanshuguptagit prabhanshuguptagit Sep 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed since for generates a lazy sequence. Unless the sequence is expanded in place, reagent can't know if an atom is being de-refed in the sequence and can't make re-renders based on it (org-store/get-selected in this case). Relevant thread

(defn fetch-user! []
(user-api/get-data
(fn [res]
(user-store/add! res))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this just user-store/add!? Why wrap another fn around it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

user-store/add! only adds the user map to the state. fetch-user! makes a call to the user API and stores the result (a user map) in the state. Made this a separate function since this bit of code gets repeated at a number of places throughout the app.

@prabhanshuguptagit prabhanshuguptagit merged commit e0f9050 into master Oct 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants