publicimageltd / delve

Delve into your org-roam zettelkasten
GNU General Public License v3.0
189 stars 8 forks source link

Is it possible to update the DELVE DASHBOARD without closing and opening again? #20

Closed akashpal-21 closed 10 months ago

akashpal-21 commented 11 months ago

Suppose I create a new node after the DELVE DASHBOARD is created, the node doesn't show up in the dashboard, I have to close and reopen it to achieve it... Is there any way to update the dashboard with new nodes/pages without closing it ?

Currently I use this hack function to achieve this : This function will depending where the user is currently, do two things, if the user is on the Delve Dashboard, it will update it - if the user is not on the Dashboard it will simply call the (delve) function which asks the user if they want to visit any collection.

If anyone want to reuse this code, substitute 0 for your buffer name, "DASHBOARD" is the default name.

(defun delve-dashboard-update ()
  "Check if 'DELVE 0' buffer is active, close it, and re-execute (delve)."
  (interactive)
  (let ((delve-buffer (get-buffer "DELVE 0")))
    (when (and delve-buffer (get-buffer-window delve-buffer t))
      (kill-buffer delve-buffer))
    (call-interactively #'delve)))

(with-eval-after-load 'delve
  (define-key delve-mode-map (kbd "G") #'delve-dashboard-update))       ; update (close&reopen) Delve Dashboard 

My delve-dashboard-name is "0"

akashpal-21 commented 11 months ago

I have thought about the problem more, and have come up with a much better solution. This code will do what I was originally intending.

(with-eval-after-load 'delve

  (defun delve-dashboard-update ()
    "Refresh Delve Dashboard"
    (interactive)

    (let ((delve-buffer (concat "DELVE " delve-dashboard-name)))

      ;; Close Delve Dashboard if it's active & current window
      (when (and delve-buffer (get-buffer-window delve-buffer t))
    (kill-buffer delve-buffer)

    ;; Then create a new Delve dashboard
    ;; Logic from delve--new-dashboard
    (with-temp-message "Setting up dashboard..."
      (let* ((tag-queries (--map (delve--create-tag-query (-list it)) delve-dashboard-tags))
         (items (list tag-queries (mapcar #'funcall delve-dashboard-queries))))
        (delve--new-buffer delve-dashboard-name (flatten-tree items))
        (switch-to-buffer delve-buffer)
        ))
    )))

  (define-key delve-mode-map (kbd "G") #'delve-dashboard-update)

  )

This code will not work for others since it involves a line that is not originally present in delve.el, I will update this code once a new version of delve releases which adds the customisable variable 'delve-dashboard-queries. Maybe @publicimageltd can implement this in the source itself, he can produce a much cleaner code than I can.

publicimageltd commented 11 months ago

I'll look at it.

publicimageltd commented 10 months ago

I have changed the behavior of "update" (g). If queries are open, new Zettels are automatically inserted in the indented tree belonging to the query. I hope it works satisfactorily. Please have a look and then close this issue.

akashpal-21 commented 10 months ago

I have changed the behavior of "update" (g). If queries are open, new Zettels are automatically inserted in the indented tree belonging to the query. I hope it works satisfactorily. Please have a look and then close this issue.

It updates newly created nodes wonderfully - additionally, if it will not be too complicated, update on deletion of the nodes could also be incorporated in the future, in that case it can sync in these two conditions.

Best, and thank you.

publicimageltd commented 10 months ago

Ah I see, I forgot to test that direction of sync. So I'll add that next, that's a good idea.

publicimageltd commented 10 months ago

Two-way sync is set up. Have fun!

akashpal-21 commented 10 months ago

Two-way sync is set up. Have fun!

Hi, I updated to the new version and tried to test it - unfortunately it doesn't seem to be working in my case, if I open the dashboard - then create a new node - I can go the relevant query and do 'g' to update it, for example the 'last modified' query will be updated and the node will be inserted. However if I do the opposite - delete a node then update the relevant query - it complains that the file doesn't exist

Some thing like this

org-roam-db--file-hash: Opening input file: No such file or directory, /home/akash/roam/test.org

Is is problem on my end - or is this a bug?

I can press '\<delete>' to manually delete the node from the listing and then do update - everything works out then.

publicimageltd commented 10 months ago

I can't replicate the problem. Please use the test environment which can be started with bin/test-emacs from the repo's root directory to reprduce it. I just did the following in the test environment and had no error, maybe I misunderstood you:

PS: You need to install Eldev for the test environment

publicimageltd commented 10 months ago

Ah, I just found the bug. It can be reproduced when you delete the whole file, instead of just a node in a file (what I did). I'll have a look. Great bug hunting! :-)

publicimageltd commented 10 months ago

That was easy, I fixed it and close the issue again. Please open a new, clean issue if you find another bug, or if your bug was actually different and still persists.

akashpal-21 commented 10 months ago

All the bugs i could find you solved so quickly; I apologise, i understand my wording regarding node and file was not clear enough and the bug you described was exactly what I was pointing to. This issue is now solved in its entirety.

If i mange to find some other bug I will let you know, but my intuition is that if tomorrow you version bump to V.1 and call it stable - you probably don't have to change any code ever again, everything works so nicely, i cannot think of anything else to complain about!

Best.