Fork me on GitHub
#biff
<
2022-12-20
>
loganrios00:12:19

I'm working on making a top navigation bar for my site built with Biff, and I want to display certain elements based on whether the user is logged in or not (including "Sign in" and "Sign out" buttons). Given that it's an element common to all pages, I initially thought it would make the most sense to load it into app/ui.clj, as an element called by ui/page that precedes the body, like so:

(def topbar
  [:nav
   [:div.container.flex.flex-wrap.items-center.justify-between.mx-auto
    [:a.text-blue-500.text-xl.font-semibold {:href "/"} "App Title"]
    [:a.text-blue-500 {:href "/genre"} "Genres"]
    [:a.text-blue-500 {:href "/user/followed"} "Followed"]
    [:a.text-blue-500 {:href "/app"} "Dashboard"]
    [:a.text-blue-500 {:href "/app/user/settings"} "Settings"]]
   [:.h-5]])

(defn page [opts & body]
  (base
   opts
   [:.p-3.mx-auto.max-w-screen-sm.w-full
    topbar
    body]))
However, ui/page has no access to the sys map that would allow me to check if the user is logged in or not. I have a couple of hacky ways that I could try to do this--maybe make another <feat>/page that wraps ui/page on each individual route, or change ui/page itself to accepts the sys map--but I'm not sure if either of these are considered "idiomatic" for Biff. Is there any ideal, idiomatic way to do this, or am I better off chasing one of the hackier solutions above?

Jacob O'Bryant01:12:20

I just pass the system map in! i.e. opts is the system map... which is possibly confusing. I've been thinking I should rename all occurrences of sys, req, or opts to ctx and have the docs refer to it as the context map.

🙌 1
Jacob O'Bryant01:12:40

I originally used the term opts in some places because you aren't necessarily passing in the system map and thus sys felt inappropriate. So ctx feels like a more general, clearer term. (Either that or maybe stuff, data, ...)

loganrios04:12:35

Ah, I see! That is very clean. Thanks for your help 👍

macrobartfast08:12:03

cloned a Biff project to a new machine and getting File does not exist: dev when running bb dev… thoughts?

macrobartfast08:12:58

bb.edn has

{:deps {local/deps {:local/root "tasks"}}
 :tasks {dev         com.biffweb.tasks/dev
         format      com.biffweb.tasks/format
         clean       com.biffweb.tasks/clean
         deploy      com.biffweb.tasks/deploy
         soft-deploy com.biffweb.tasks/soft-deploy
         refresh     com.biffweb.tasks/refresh
         restart     com.biffweb.tasks/restart
         logs        com.biffweb.tasks/logs
         prod-repl   com.biffweb.tasks/prod-repl
         prod-dev    com.biffweb.tasks/prod-dev
         hello       wiki.treeplanet.tasks/hello

         post-receive com.biffweb.tasks/post-receive
         run-cmd      com.biffweb.tasks/run-cmd}}
and the task directory is there.

pavlosmelissinos08:12:01

what's your bb --version?

macrobartfast08:12:58

Haha! You’re onto it. Just after posting this I realized I had a very old version. I then attempted to update it with brew, but I had originally installed it on this machine with the curl script. I then reran the curl install script, and now I’m having a lot of fun as running, say, bb throws

Error: Could not find or load main class clojure.main
Caused by: java.lang.ClassNotFoundException: clojure.main
so working through that.

macrobartfast08:12:31

running bb outside the project directory works, but not inside of it. However, I’m glad to say that bb --version outside the project shows I now have Babashka v1.0.168 REPL.

macrobartfast08:12:01

(I don’t have an M1 MacBook as the OP of the issue did, fyi)

macrobartfast08:12:03

bb --version and bb work inside the Biff project directory if I rename bb.edn to something else.

pavlosmelissinos08:12:04

On my phone right now but this sounds like an issue with your #CLX41ASCS installation. I don't use brew but I think that has caused some problems in the past?

pavlosmelissinos08:12:36

I think you'll get a solution faster over at #CLX41ASCS

pavlosmelissinos08:12:18

Oh you said it works outside the project, Ican check it out in half an hour or so

macrobartfast09:12:25

Aha! I removed ~/.deps.clj and that solved the issue. This is a directory created by babashka.

👍 1
👌 1
macrobartfast09:12:52

Thank you for all the help! 😀

pavlosmelissinos09:12:42

Oh, the old version of babashka created deps.clj and confused the new one? That's interesting

macrobartfast19:12:37

I just saw a mention of deleting ~/deps.clj in that thread I linked to above and tried it. My situation is a bit unusual, though… I cloned a project down into a machine that had early versions of bb and so on. Truly a corner case and not a Biff thing, that’s for sure.

👍 1