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

Rendering user reputation in title bar leading to lots of code duplication #18

Open
imalsogreg opened this issue Jan 23, 2014 · 2 comments
Labels

Comments

@imalsogreg
Copy link
Owner

Working on displaying logged-in-user's reputation next to his/her name in the top nav bar. This is requiring modification of every Handler that renders a page, and passing the User and all Documents to all these handlers (because the reputation-computing function needs that info).

Snap.Snaplet.Auth gives the splice , which is automatically spliced out of every AuthManager'ed template.

Can I possibly do something similar? Snaplet.ReffitUser that automatically handles loggedInUser's reputation printing?

Also, printing the reputations of comment authors and discussion point writers is making for a lot of duplicate code. Is there a way around it?

@BlairArchibald
Copy link
Collaborator

We should definitely use a similar model to that used in Snap.Snaplet.Auth by modifying the heist state at startup. This way we keep the Handlers separate from any rendering logic and should be able to just duplicate the tags in the html (which is much nicer than duplicating code within Handlers).

We should probably look to refactor more of the handlers in a similar fashion!

You would need a function i.e addReffitHesitConfig h. Which will be called within the main reffit application initializer function.

@imalsogreg
Copy link
Owner Author

Thanks, that helped me think about this. Right now reputation is never stored in the database - it's always recomputed when its needed (every page load). The situation will be different when we move to SQL b/c we don't want to do all those database queries for every page render. So this particular bit of ugliness, I will wait to fix until I see how the integration of Persist shakes out (unless you see a trivial way to get the fix into the current code - which you might).

I'm still trying to understand snaplets & heist better so I can answer questions like: "could I make a spice available by a similar mechanism to Snap.Snaplet.Auth's, throughout the site, even though computing it requires at least one database lookup per page load? Or is it better to accomplish that in Site.hs with something looking like this (prob doesn't compile - just laying out general idea):

wrapsite $ \site -> do
  docs <- query QueryAllDocs
  myUser <- lookupReffitUser =<< currentUser
  modifyHeistState . bindSplices $ reputationSplices docs myUser

"
The alternative under Persistent would look similar, except I would be making some query into a ReffitUsers table, and the reputation would be stored right in that user's row.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants