Skip to content

Commit

Permalink
feat(mobile): doc property journal duplicated action (#8820)
Browse files Browse the repository at this point in the history
  • Loading branch information
CatsJuice committed Nov 21, 2024
1 parent c408d73 commit a623284
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Checkbox, DatePicker, Menu, PropertyValue } from '@affine/component';
import { MobileJournalConflictList } from '@affine/core/mobile/pages/workspace/detail/menu/journal-conflicts';
import { JournalService } from '@affine/core/modules/journal';
import { WorkbenchService } from '@affine/core/modules/workbench';
import { ViewService } from '@affine/core/modules/workbench/services/view';
Expand All @@ -15,6 +16,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import * as styles from './journal.css';
import type { PropertyValueProps } from './types';

const stopPropagation = (e: React.MouseEvent) => e.stopPropagation();
export const JournalValue = ({ onChange }: PropertyValueProps) => {
const t = useI18n();

Expand Down Expand Up @@ -75,10 +77,6 @@ export const JournalValue = ({ onChange }: PropertyValueProps) => {

const handleOpenDuplicate = useCallback(
(e: React.MouseEvent) => {
// todo: open duplicate dialog for mobile
if (BUILD_CONFIG.isMobileEdition) {
return;
}
e.stopPropagation();
workbench.openSidebar();
view.activeSidebarTab('journal');
Expand Down Expand Up @@ -141,13 +139,25 @@ export const JournalValue = ({ onChange }: PropertyValueProps) => {
) : null}

{checked && conflict ? (
<div
data-testid="conflict-tag"
className={styles.duplicateTag}
onClick={handleOpenDuplicate}
>
{t['com.affine.page-properties.property.journal-duplicated']()}
</div>
BUILD_CONFIG.isMobileEdition ? (
<Menu items={<MobileJournalConflictList date={selectedDate} />}>
<div
data-testid="conflict-tag"
className={styles.duplicateTag}
onClick={stopPropagation}
>
{t['com.affine.page-properties.property.journal-duplicated']()}
</div>
</Menu>
) : (
<div
data-testid="conflict-tag"
className={styles.duplicateTag}
onClick={handleOpenDuplicate}
>
{t['com.affine.page-properties.property.journal-duplicated']()}
</div>
)
) : null}
</div>
</PropertyValue>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,23 @@ const ConflictList = ({ docRecords }: { docRecords: DocRecord[] }) => {
));
};

export const MobileJournalConflictList = ({ date }: { date: string }) => {
const docRecordList = useService(DocsService).list;
const journalService = useService(JournalService);
const docs = useLiveData(
useMemo(() => journalService.journalsByDate$(date), [journalService, date])
);
const docRecords = useLiveData(
docRecordList.docs$.map(records =>
records.filter(v => {
return docs.some(doc => doc.id === v.id);
})
)
);

return <ConflictList docRecords={docRecords} />;
};

const ConflictListMenuItem = ({ docRecords }: { docRecords: DocRecord[] }) => {
const t = useI18n();
return (
Expand Down

0 comments on commit a623284

Please sign in to comment.