mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-15 05:37:32 +00:00
feat: cmd click support for journal sidebar (#7792)
fix AF-1214 The titles are also corrected: 
This commit is contained in:
@@ -2,12 +2,13 @@ import type { DateCell } from '@affine/component';
|
|||||||
import { DatePicker, IconButton, Menu, Scrollable } from '@affine/component';
|
import { DatePicker, IconButton, Menu, Scrollable } from '@affine/component';
|
||||||
import { MoveToTrash } from '@affine/core/components/page-list';
|
import { MoveToTrash } from '@affine/core/components/page-list';
|
||||||
import { useTrashModalHelper } from '@affine/core/hooks/affine/use-trash-modal-helper';
|
import { useTrashModalHelper } from '@affine/core/hooks/affine/use-trash-modal-helper';
|
||||||
|
import { useDocCollectionPageTitle } from '@affine/core/hooks/use-block-suite-workspace-page-title';
|
||||||
import {
|
import {
|
||||||
useJournalHelper,
|
useJournalHelper,
|
||||||
useJournalInfoHelper,
|
useJournalInfoHelper,
|
||||||
useJournalRouteHelper,
|
useJournalRouteHelper,
|
||||||
} from '@affine/core/hooks/use-journal';
|
} from '@affine/core/hooks/use-journal';
|
||||||
import { useNavigateHelper } from '@affine/core/hooks/use-navigate-helper';
|
import { WorkbenchLink } from '@affine/core/modules/workbench';
|
||||||
import { useI18n } from '@affine/i18n';
|
import { useI18n } from '@affine/i18n';
|
||||||
import {
|
import {
|
||||||
EdgelessIcon,
|
EdgelessIcon,
|
||||||
@@ -41,14 +42,18 @@ const CountDisplay = ({
|
|||||||
}: { count: number; max?: number } & HTMLAttributes<HTMLSpanElement>) => {
|
}: { count: number; max?: number } & HTMLAttributes<HTMLSpanElement>) => {
|
||||||
return <span {...attrs}>{count > max ? `${max}+` : count}</span>;
|
return <span {...attrs}>{count > max ? `${max}+` : count}</span>;
|
||||||
};
|
};
|
||||||
interface PageItemProps extends HTMLAttributes<HTMLDivElement> {
|
interface PageItemProps
|
||||||
|
extends Omit<HTMLAttributes<HTMLAnchorElement>, 'onClick'> {
|
||||||
docRecord: DocRecord;
|
docRecord: DocRecord;
|
||||||
right?: ReactNode;
|
right?: ReactNode;
|
||||||
}
|
}
|
||||||
const PageItem = ({ docRecord, right, className, ...attrs }: PageItemProps) => {
|
const PageItem = ({ docRecord, right, className, ...attrs }: PageItemProps) => {
|
||||||
const title = useLiveData(docRecord.title$);
|
|
||||||
const mode = useLiveData(docRecord.mode$);
|
const mode = useLiveData(docRecord.mode$);
|
||||||
const workspace = useService(WorkspaceService).workspace;
|
const workspace = useService(WorkspaceService).workspace;
|
||||||
|
const title = useDocCollectionPageTitle(
|
||||||
|
workspace.docCollection,
|
||||||
|
docRecord.id
|
||||||
|
);
|
||||||
const { isJournal } = useJournalInfoHelper(
|
const { isJournal } = useJournalInfoHelper(
|
||||||
workspace.docCollection,
|
workspace.docCollection,
|
||||||
docRecord.id
|
docRecord.id
|
||||||
@@ -60,8 +65,9 @@ const PageItem = ({ docRecord, right, className, ...attrs }: PageItemProps) => {
|
|||||||
? EdgelessIcon
|
? EdgelessIcon
|
||||||
: PageIcon;
|
: PageIcon;
|
||||||
return (
|
return (
|
||||||
<div
|
<WorkbenchLink
|
||||||
aria-label={title}
|
aria-label={title}
|
||||||
|
to={`/${docRecord.id}`}
|
||||||
className={clsx(className, styles.pageItem)}
|
className={clsx(className, styles.pageItem)}
|
||||||
{...attrs}
|
{...attrs}
|
||||||
>
|
>
|
||||||
@@ -70,7 +76,7 @@ const PageItem = ({ docRecord, right, className, ...attrs }: PageItemProps) => {
|
|||||||
</div>
|
</div>
|
||||||
<span className={styles.pageItemLabel}>{title}</span>
|
<span className={styles.pageItemLabel}>{title}</span>
|
||||||
{right}
|
{right}
|
||||||
</div>
|
</WorkbenchLink>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -177,14 +183,11 @@ const DailyCountEmptyFallback = ({ name }: { name: NavItemName }) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
const JournalDailyCountBlock = ({ date }: JournalBlockProps) => {
|
const JournalDailyCountBlock = ({ date }: JournalBlockProps) => {
|
||||||
const workspace = useService(WorkspaceService).workspace;
|
|
||||||
const nodeRef = useRef<HTMLDivElement>(null);
|
const nodeRef = useRef<HTMLDivElement>(null);
|
||||||
const t = useI18n();
|
const t = useI18n();
|
||||||
const [activeItem, setActiveItem] = useState<NavItemName>('createdToday');
|
const [activeItem, setActiveItem] = useState<NavItemName>('createdToday');
|
||||||
const docRecords = useLiveData(useService(DocsService).list.docs$);
|
const docRecords = useLiveData(useService(DocsService).list.docs$);
|
||||||
|
|
||||||
const navigateHelper = useNavigateHelper();
|
|
||||||
|
|
||||||
const getTodaysPages = useCallback(
|
const getTodaysPages = useCallback(
|
||||||
(field: 'createDate' | 'updatedDate') => {
|
(field: 'createDate' | 'updatedDate') => {
|
||||||
return sortPagesByDate(
|
return sortPagesByDate(
|
||||||
@@ -267,9 +270,6 @@ const JournalDailyCountBlock = ({ date }: JournalBlockProps) => {
|
|||||||
<div className={styles.dailyCountContent} ref={nodeRef}>
|
<div className={styles.dailyCountContent} ref={nodeRef}>
|
||||||
{renderList.map((pageRecord, index) => (
|
{renderList.map((pageRecord, index) => (
|
||||||
<PageItem
|
<PageItem
|
||||||
onClick={() =>
|
|
||||||
navigateHelper.openPage(workspace.id, pageRecord.id)
|
|
||||||
}
|
|
||||||
tabIndex={name === activeItem ? 0 : -1}
|
tabIndex={name === activeItem ? 0 : -1}
|
||||||
key={index}
|
key={index}
|
||||||
docRecord={pageRecord}
|
docRecord={pageRecord}
|
||||||
@@ -297,7 +297,6 @@ const ConflictList = ({
|
|||||||
className,
|
className,
|
||||||
...attrs
|
...attrs
|
||||||
}: ConflictListProps) => {
|
}: ConflictListProps) => {
|
||||||
const navigateHelper = useNavigateHelper();
|
|
||||||
const workspace = useService(WorkspaceService).workspace;
|
const workspace = useService(WorkspaceService).workspace;
|
||||||
const currentDoc = useService(DocService).doc;
|
const currentDoc = useService(DocService).doc;
|
||||||
const { setTrashModal } = useTrashModalHelper(workspace.docCollection);
|
const { setTrashModal } = useTrashModalHelper(workspace.docCollection);
|
||||||
@@ -335,7 +334,6 @@ const ConflictList = ({
|
|||||||
</IconButton>
|
</IconButton>
|
||||||
</Menu>
|
</Menu>
|
||||||
}
|
}
|
||||||
onClick={() => navigateHelper.openPage(workspace.id, docRecord.id)}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|||||||
Reference in New Issue
Block a user