Skip to content

Commit

Permalink
Merge branch 'canary' into darksky/mutate-db-with-transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
darkskygit authored Mar 14, 2024
2 parents 77f5517 + 7fdb1f2 commit 01b39ba
Show file tree
Hide file tree
Showing 20 changed files with 442 additions and 111 deletions.
3 changes: 3 additions & 0 deletions packages/common/infra/src/blocksuite/migration/fixing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export function fixWorkspaceVersion(rootDoc: YDoc) {
* Blocksuite just set the value, do nothing else.
*/
function doFix() {
if (meta.size === 0) {
return;
}
const workspaceVersion = meta.get('workspaceVersion');
if (typeof workspaceVersion !== 'number' || workspaceVersion < 2) {
transact(
Expand Down
12 changes: 7 additions & 5 deletions packages/common/infra/src/workspace/engine/sync/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,17 @@ export class SyncEngine {
this.onStatusChange.emit(s);
}
isRootDocLoaded = LiveData.from(
new Observable(observer => {
new Observable<boolean>(observer => {
observer.next(
this.status.local
? this.status.local.step > SyncPeerStep.LoadingRootDoc
: false
[this.status?.local, ...(this.status?.remotes ?? [])].some(
p => p?.rootDocLoaded === true
)
);
this.onStatusChange.on(status => {
observer.next(
status.local ? status.local.step > SyncPeerStep.LoadingRootDoc : false
[status?.local, ...(status?.remotes ?? [])].some(
p => p?.rootDocLoaded === true
)
);
});
}),
Expand Down
11 changes: 11 additions & 0 deletions packages/common/infra/src/workspace/engine/sync/peer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface SyncPeerStatus {
pendingPullUpdates: number;
pendingPushUpdates: number;
lastError: string | null;
rootDocLoaded: boolean;
}

/**
Expand Down Expand Up @@ -56,6 +57,7 @@ export class SyncPeer {
pendingPullUpdates: 0,
pendingPushUpdates: 0,
lastError: null,
rootDocLoaded: false,
};
onStatusChange = new Slot<SyncPeerStatus>();
readonly abort = new AbortController();
Expand Down Expand Up @@ -122,6 +124,7 @@ export class SyncPeer {
pendingPullUpdates: 0,
pendingPushUpdates: 0,
lastError: 'Retrying sync after 5 seconds',
rootDocLoaded: this.status.rootDocLoaded,
};
await Promise.race([
new Promise<void>(resolve => {
Expand Down Expand Up @@ -295,6 +298,13 @@ export class SyncPeer {
(await this.storage.pull(doc.guid, encodeStateVector(doc))) ?? {};
throwIfAborted(abort);

if (docData !== undefined && doc.guid === this.rootDoc.guid) {
this.status = {
...this.status,
rootDocLoaded: true,
};
}

if (docData) {
applyUpdate(doc, docData, 'load');
}
Expand Down Expand Up @@ -400,6 +410,7 @@ export class SyncPeer {
pendingPushUpdates:
this.state.pushUpdatesQueue.length + (this.state.pushingUpdate ? 1 : 0),
lastError,
rootDocLoaded: this.status.rootDocLoaded,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { toast } from '@affine/component';
import { useBlockSuiteMetaHelper } from '@affine/core/hooks/affine/use-block-suite-meta-helper';
import { useTrashModalHelper } from '@affine/core/hooks/affine/use-trash-modal-helper';
import { useBlockSuiteDocMeta } from '@affine/core/hooks/use-block-suite-page-meta';
import { Workbench } from '@affine/core/modules/workbench';
import type { Collection, Filter } from '@affine/env/filter';
import { Trans } from '@affine/i18n';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
Expand Down Expand Up @@ -33,6 +34,7 @@ const usePageOperationsRenderer = () => {
currentWorkspace.docCollection
);
const t = useAFFiNEI18N();
const workbench = useService(Workbench);

const pageOperationsRenderer = useCallback(
(page: DocMeta) => {
Expand All @@ -48,6 +50,7 @@ const usePageOperationsRenderer = () => {
isPublic={!!page.isPublic}
onDisablePublicSharing={onDisablePublicSharing}
link={`/workspace/${currentWorkspace.id}/${page.id}`}
onOpenInSplitView={() => workbench.openPage(page.id, { at: 'tail' })}
onDuplicate={() => {
duplicate(page.id, false);
}}
Expand All @@ -70,7 +73,14 @@ const usePageOperationsRenderer = () => {
/>
);
},
[currentWorkspace.id, setTrashModal, t, toggleFavorite, duplicate]
[
currentWorkspace.id,
workbench,
duplicate,
setTrashModal,
toggleFavorite,
t,
]
);

return pageOperationsRenderer;
Expand Down
19 changes: 19 additions & 0 deletions packages/frontend/core/src/components/page-list/operation-cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
toast,
Tooltip,
} from '@affine/component';
import { useAppSettingHelper } from '@affine/core/hooks/affine/use-app-setting-helper';
import type { Collection, DeleteCollectionInfo } from '@affine/env/filter';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import {
Expand All @@ -20,6 +21,7 @@ import {
MoreVerticalIcon,
OpenInNewIcon,
ResetIcon,
SplitViewIcon,
} from '@blocksuite/icons';
import { useCallback, useState } from 'react';
import { Link } from 'react-router-dom';
Expand All @@ -45,6 +47,7 @@ export interface PageOperationCellProps {
onRemoveToTrash: () => void;
onDuplicate: () => void;
onDisablePublicSharing: () => void;
onOpenInSplitView: () => void;
}

export const PageOperationCell = ({
Expand All @@ -55,8 +58,10 @@ export const PageOperationCell = ({
onRemoveToTrash,
onDuplicate,
onDisablePublicSharing,
onOpenInSplitView,
}: PageOperationCellProps) => {
const t = useAFFiNEI18N();
const { appSettings } = useAppSettingHelper();
const [openDisableShared, setOpenDisableShared] = useState(false);
const OperationMenu = (
<>
Expand Down Expand Up @@ -84,6 +89,20 @@ export const PageOperationCell = ({
? t['com.affine.favoritePageOperation.remove']()
: t['com.affine.favoritePageOperation.add']()}
</MenuItem>

{environment.isDesktop && appSettings.enableMultiView ? (
<MenuItem
onClick={onOpenInSplitView}
preFix={
<MenuIcon>
<SplitViewIcon />
</MenuIcon>
}
>
{t['com.affine.workbench.split-view.page-menu-open']()}
</MenuItem>
) : null}

{!environment.isDesktop && (
<Link
className={styles.clearLinkStyle}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ import {
MenuItem,
type MenuItemProps,
} from '@affine/component';
import { useAppSettingHelper } from '@affine/core/hooks/affine/use-app-setting-helper';
import { Workbench } from '@affine/core/modules/workbench';
import type { Collection, DeleteCollectionInfo } from '@affine/env/filter';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { DeleteIcon, EditIcon, FilterIcon } from '@blocksuite/icons';
import {
DeleteIcon,
EditIcon,
FilterIcon,
SplitViewIcon,
} from '@blocksuite/icons';
import { useService } from '@toeverything/infra/di';
import {
type PropsWithChildren,
Expand Down Expand Up @@ -35,7 +42,9 @@ export const CollectionOperations = ({
config: AllPageListConfig;
openRenameModal?: () => void;
}>) => {
const { appSettings } = useAppSettingHelper();
const service = useService(CollectionService);
const workbench = useService(Workbench);
const { open: openEditCollectionModal, node: editModal } =
useEditCollection(config);
const t = useAFFiNEI18N();
Expand Down Expand Up @@ -71,6 +80,10 @@ export const CollectionOperations = ({
});
}, [openEditCollectionModal, collection, service]);

const openCollectionSplitView = useCallback(() => {
workbench.openCollection(collection.id, { at: 'tail' });
}, [collection.id, workbench]);

const actions = useMemo<
Array<
| {
Expand Down Expand Up @@ -104,6 +117,19 @@ export const CollectionOperations = ({
name: t['com.affine.collection.menu.edit'](),
click: showEdit,
},
...(appSettings.enableMultiView
? [
{
icon: (
<MenuIcon>
<SplitViewIcon />
</MenuIcon>
),
name: t['com.affine.workbench.split-view.page-menu-open'](),
click: openCollectionSplitView,
},
]
: []),
{
element: <div key="divider" className={styles.divider}></div>,
},
Expand All @@ -120,7 +146,16 @@ export const CollectionOperations = ({
type: 'danger',
},
],
[t, showEditName, showEdit, service, info, collection.id]
[
t,
showEditName,
showEdit,
appSettings.enableMultiView,
openCollectionSplitView,
service,
info,
collection.id,
]
);
return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import {
type MenuItemProps,
MenuSeparator,
} from '@affine/component';
import { useAppSettingHelper } from '@affine/core/hooks/affine/use-app-setting-helper';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import {
DeleteIcon,
EditIcon,
FavoriteIcon,
FilterMinusIcon,
LinkedPageIcon,
SplitViewIcon,
} from '@blocksuite/icons';
import { type ReactElement, useMemo } from 'react';

Expand All @@ -24,6 +26,7 @@ type OperationItemsProps = {
onAddLinkedPage: () => void;
onRemoveFromFavourites?: () => void;
onDelete: () => void;
onOpenInSplitView: () => void;
};

export const OperationItems = ({
Expand All @@ -35,7 +38,9 @@ export const OperationItems = ({
onAddLinkedPage,
onRemoveFromFavourites,
onDelete,
onOpenInSplitView,
}: OperationItemsProps) => {
const { appSettings } = useAppSettingHelper();
const t = useAFFiNEI18N();
const actions = useMemo<
Array<
Expand Down Expand Up @@ -81,9 +86,6 @@ export const OperationItems = ({
name: t['Remove from favorites'](),
click: onRemoveFromFavourites,
},
{
element: <MenuSeparator />,
},
]
: []),
...(inAllowList && onRemoveFromAllowList
Expand All @@ -97,18 +99,27 @@ export const OperationItems = ({
name: t['Remove special filter'](),
click: onRemoveFromAllowList,
},
{
element: <MenuSeparator />,
},
]
: []),
...(isReferencePage

...(appSettings.enableMultiView
? [
// open split view
{
element: <MenuSeparator />,
icon: (
<MenuIcon>
<SplitViewIcon />
</MenuIcon>
),
name: t['com.affine.workbench.split-view.page-menu-open'](),
click: onOpenInSplitView,
},
]
: []),

{
element: <MenuSeparator />,
},
{
icon: (
<MenuIcon>
Expand All @@ -121,14 +132,16 @@ export const OperationItems = ({
},
],
[
t,
onRename,
onAddLinkedPage,
inFavorites,
onRemoveFromFavourites,
isReferencePage,
t,
inAllowList,
onRemoveFromAllowList,
appSettings.enableMultiView,
onOpenInSplitView,
onDelete,
]
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { toast } from '@affine/component';
import { IconButton } from '@affine/component/ui/button';
import { Menu } from '@affine/component/ui/menu';
import { Workbench } from '@affine/core/modules/workbench';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { MoreHorizontalIcon } from '@blocksuite/icons';
import type { DocCollection } from '@blocksuite/store';
import { useService } from '@toeverything/infra/di';
import { useCallback } from 'react';

import { useBlockSuiteMetaHelper } from '../../../../hooks/affine/use-block-suite-meta-helper';
Expand Down Expand Up @@ -37,6 +39,7 @@ export const OperationMenuButton = ({ ...props }: OperationMenuButtonProps) => {
const { createLinkedPage } = usePageHelper(docCollection);
const { setTrashModal } = useTrashModalHelper(docCollection);
const { removeFromFavorite } = useBlockSuiteMetaHelper(docCollection);
const workbench = useService(Workbench);

const handleRename = useCallback(() => {
setRenameModalOpen?.();
Expand Down Expand Up @@ -64,6 +67,10 @@ export const OperationMenuButton = ({ ...props }: OperationMenuButtonProps) => {
removeFromAllowList?.(pageId);
}, [pageId, removeFromAllowList]);

const handleOpenInSplitView = useCallback(() => {
workbench.openPage(pageId, { at: 'tail' });
}, [pageId, workbench]);

return (
<Menu
items={
Expand All @@ -73,6 +80,7 @@ export const OperationMenuButton = ({ ...props }: OperationMenuButtonProps) => {
onRemoveFromAllowList={handleRemoveFromAllowList}
onRemoveFromFavourites={handleRemoveFromFavourites}
onRename={handleRename}
onOpenInSplitView={handleOpenInSplitView}
inAllowList={inAllowList}
inFavorites={inFavorites}
isReferencePage={isReferencePage}
Expand Down
Loading

0 comments on commit 01b39ba

Please sign in to comment.