Skip to content

Commit

Permalink
fix(core): make all docs journal judgement reactive
Browse files Browse the repository at this point in the history
  • Loading branch information
CatsJuice committed Dec 24, 2024
1 parent 6c0544b commit 7ddc8a6
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { DocsService } from '@affine/core/modules/doc';
import { JournalService } from '@affine/core/modules/journal';
import { WorkspaceService } from '@affine/core/modules/workspace';
import type { DocCollection, DocMeta } from '@blocksuite/affine/store';
import { useService } from '@toeverything/infra';
import { LiveData, useLiveData, useService } from '@toeverything/infra';
import { useCallback, useMemo } from 'react';

import { useAsyncCallback } from './affine-async-hooks';
import { useAllBlockSuiteDocMeta } from './use-all-block-suite-page-meta';
import { useJournalInfoHelper } from './use-journal';

/**
* Get pageMetas excluding journal pages without updatedDate
Expand All @@ -15,13 +15,26 @@ import { useJournalInfoHelper } from './use-journal';
*/
export function useBlockSuiteDocMeta(docCollection: DocCollection) {
const pageMetas = useAllBlockSuiteDocMeta(docCollection);
const { isPageJournal } = useJournalInfoHelper();
const journalService = useService(JournalService);

const journalIds = useLiveData(
useMemo(
() =>
LiveData.computed(get =>
pageMetas
.map(meta => meta.id)
.filter(id => !!get(journalService.journalDate$(id)))
),
[pageMetas, journalService]
)
);

return useMemo(
() =>
pageMetas.filter(
pageMeta => !isPageJournal(pageMeta.id) || !!pageMeta.updatedDate
pageMeta => !journalIds.includes(pageMeta.id) || !!pageMeta.updatedDate
),
[isPageJournal, pageMetas]
[journalIds, pageMetas]
);
}

Expand Down
37 changes: 35 additions & 2 deletions tests/affine-local/e2e/all-page.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable unicorn/prefer-dom-node-dataset */
import { test } from '@affine-test/kit/playwright';
import {
changeFilter,
Expand All @@ -12,15 +11,23 @@ import {
selectMonthFromMonthPicker,
selectTag,
} from '@affine-test/kit/utils/filter';
import { openHomePage } from '@affine-test/kit/utils/load-page';
import {
openHomePage,
openJournalsPage,
} from '@affine-test/kit/utils/load-page';
import {
clickNewPageButton,
clickPageMoreActions,
getAllPage,
getBlockSuiteEditorTitle,
waitForAllPagesLoad,
waitForEditorLoad,
waitForEmptyEditor,
} from '@affine-test/kit/utils/page-logic';
import {
ensurePagePropertiesVisible,
togglePropertyListVisibility,
} from '@affine-test/kit/utils/properties';
import { clickSideBarAllPageButton } from '@affine-test/kit/utils/sidebar';
import { expect } from '@playwright/test';

Expand Down Expand Up @@ -457,3 +464,29 @@ test('create a tag and delete it', async ({ page }) => {
const newCell = page.getByTestId('tag-list-item').getByText('test-tag');
await expect(newCell).not.toBeVisible();
});

test('create a empty page and turn it into journal, should disappear in all docs', async ({
page,
}) => {
await openHomePage(page);
await waitForEditorLoad(page);
await clickNewPageButton(page);
await clickSideBarAllPageButton(page);
const docItem = page
.locator('[data-testid="page-list-item-title-text"]')
.first();
const docTitle = await docItem.textContent();
await expect(docTitle).toBe('Untitled');
// open and turn it into journal
await docItem.click();
await waitForEmptyEditor(page);
await ensurePagePropertiesVisible(page);
await togglePropertyListVisibility(page);
const journalProperty = page.locator('[data-info-id="journal"]').first();
await journalProperty.locator('[data-property-value="true"]').click();
// back to all docs, the journal page should disappear
await clickSideBarAllPageButton(page);
await waitForAllPagesLoad(page);
const newDocTitle = await docItem.textContent();
await expect(newDocTitle).not.toBe(docTitle);
});

0 comments on commit 7ddc8a6

Please sign in to comment.