feat(core): page info adapter for journal (#5561)

Page info adapter + schema.
Adapted for journal features.

![image](https://github.com/toeverything/AFFiNE/assets/584378/2731ed2b-a125-4d62-b658-f2aff49d0e17)
This commit is contained in:
Peng Xiao
2024-01-22 08:25:27 +00:00
parent 8b92cc0cae
commit 735e1cb117
18 changed files with 412 additions and 68 deletions

View File

@@ -1,5 +1,6 @@
import { usePageMetaHelper } from '@affine/core/hooks/use-block-suite-page-meta';
import { useBlockSuiteWorkspacePage } from '@affine/core/hooks/use-block-suite-workspace-page';
import { timestampToLocalDate } from '@affine/core/utils';
import { DebugLogger } from '@affine/debug';
import {
fetchWithTraceReport,
@@ -176,11 +177,7 @@ export const useSnapshotPage = (
export const historyListGroupByDay = (histories: DocHistory[]) => {
const map = new Map<string, DocHistory[]>();
for (const history of histories) {
const day = new Date(history.timestamp).toLocaleDateString(undefined, {
year: 'numeric',
month: 'short',
day: 'numeric',
});
const day = timestampToLocalDate(history.timestamp);
const list = map.get(day) ?? [];
list.push(history);
map.set(day, list);

View File

@@ -10,6 +10,7 @@ import { useIsWorkspaceOwner } from '@affine/core/hooks/affine/use-is-workspace-
import { useAsyncCallback } from '@affine/core/hooks/affine-async-hooks';
import { useUserSubscription } from '@affine/core/hooks/use-subscription';
import { waitForCurrentWorkspaceAtom } from '@affine/core/modules/workspace';
import { timestampToLocalTime } from '@affine/core/utils';
import { SubscriptionPlan } from '@affine/graphql';
import { Trans } from '@affine/i18n';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
@@ -88,14 +89,6 @@ const ModalContainer = ({
);
};
const localTimeFormatter = new Intl.DateTimeFormat('en', {
timeStyle: 'short',
});
const timestampToLocalTime = (ts: string) => {
return localTimeFormatter.format(new Date(ts));
};
interface HistoryEditorPreviewProps {
ts?: string;
snapshotPage?: Page;

View File

@@ -19,7 +19,7 @@ export const JournalWeekDatePicker = ({
page,
}: JournalWeekDatePickerProps) => {
const handleRef = useRef<WeekDatePickerHandle>(null);
const { journalDate } = useJournalInfoHelper(page.meta);
const { journalDate } = useJournalInfoHelper(workspace, page.id);
const { openJournal } = useJournalHelper(workspace);
const [date, setDate] = useState(
(journalDate ?? dayjs()).format('YYYY-MM-DD')

View File

@@ -19,9 +19,11 @@ export const AppSidebarJournalButton = ({
}: AppSidebarJournalButtonProps) => {
const t = useAFFiNEI18N();
const currentPageId = useAtomValue(currentPageIdAtom);
const currentPage = currentPageId ? workspace.getPage(currentPageId) : null;
const { openToday } = useJournalHelper(workspace);
const { journalDate, isJournal } = useJournalInfoHelper(currentPage?.meta);
const { journalDate, isJournal } = useJournalInfoHelper(
workspace,
currentPageId
);
const params = useParams();
const isJournalActive = isJournal && !!params.pageId;