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

fix: daily notes should update reactively #2035

Merged
merged 1 commit into from
Feb 22, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/cljs/athens/reactive.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@


;; Ratoms
;; NB: p/pull will not throw on missing ident, and will update the ratom when it exists.

(defn get-reactive-linked-references
"For node and block page references UI."
Expand Down
15 changes: 5 additions & 10 deletions src/cljs/athens/views/pages/daily_notes.cljs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
(ns athens.views.pages.daily-notes
(:require
[athens.common-db :as common-db]
[athens.dates :as dates]
[athens.db :as db]
[athens.reactive :as reactive]
[athens.style :refer [DEPTH-SHADOWS]]
[athens.views.pages.node-page :as node-page]
[re-frame.core :refer [dispatch subscribe]]
Expand Down Expand Up @@ -37,17 +36,13 @@
:opacity "0.5"}))


(defn safe-pull-many
"Need a safe pull because block/uid doesn't exist yet in datascript, but is found in :daily-notes/items.
(defn reactive-pull-many
"Need a reactive pull because block/uid doesn't exist yet in datascript, but is found in :daily-notes/items.
This happens because (dispatch [:daily-note/next (dates/get-day)]) updates re-frame faster than the datascript tx can happen

Bug: It's still possible for a day to not get created. The UI for this just shows an empty page without a title. Acceptable bug :)"
[ids]
(keep
(fn [uid]
(try (common-db/get-block @db/dsdb [:block/uid uid])
(catch js/Error _e nil)))
ids))
(keep #(reactive/get-reactive-block-document [:block/uid %]) ids))


;; Components
Expand All @@ -59,7 +54,7 @@
(fn []
(if (empty? @note-refs)
(dispatch [:daily-note/next (dates/get-day)])
(let [notes (safe-pull-many @note-refs)]
(let [notes (reactive-pull-many @note-refs)]
[:div#daily-notes (use-style daily-notes-scroll-area-style)
(doall
(for [{:keys [block/uid]} notes]
Expand Down
6 changes: 4 additions & 2 deletions test/e2e/basic.spec.ts → test/e2e/boot.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { expect } from '@playwright/test';
import { test } from './electron-test';
import { waitForBoot } from './utils';
import { waitForBoot, pageTitleLocator, todaysDate } from './utils';

test('basic test', async ({ page }) => {
test('boot test', async ({ page }) => {
await waitForBoot(page);
// The search button on the toolbar is visible.
await expect(page.locator('text=Find or create a page').first()).toBeVisible();
// Todays daily note is visible.
await expect(page.locator(pageTitleLocator)).toHaveText(await todaysDate(page));
});
7 changes: 7 additions & 0 deletions test/e2e/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,10 @@ export const deleteCurrentPage = async (page:Page) => {
await page.click('button:has-text("Delete Page")');
await page.click('button:nth-child(6)');
}

export const todaysDate = async (page:Page) => {
// This gets today's date as formatted by athens itself.
const todaysDate = await page.evaluate(`athens.dates.get_day()`);
const dateTitle = todaysDate.arr[3];
return dateTitle;
};