Skip to content

Commit

Permalink
chore: remove explorerTreesType
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmFly committed Aug 1, 2024
1 parent 2f7cd81 commit c2b687e
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,8 @@ const ExplorerCollectionNodeChildren = ({
(id: string) => {
collectionService.deletePageFromCollection(collection.id, id);
mixpanel.track('PageOptionClick', {
page: 'doc library',
segment: 'collections',
module: 'collections',
segment: 'sidebar',
module: 'doc',
control: 'remove special filter',
});
toast(t['com.affine.collection.removePage.success']());
Expand Down Expand Up @@ -308,7 +307,6 @@ const ExplorerCollectionNodeChildren = ({
<ExplorerDocNode
key={doc.id}
docId={doc.id}
explorerTreesType="collections"
reorderable={false}
location={{
at: 'explorer:collection:filtered-docs',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
import { useCallback, useLayoutEffect, useMemo, useState } from 'react';

import { ExplorerTreeNode, type ExplorerTreeNodeDropEffect } from '../../tree';
import type { ExplorerTreesType, GenericExplorerNode } from '../types';
import type { GenericExplorerNode } from '../types';
import { Empty } from './empty';
import { useExplorerDocNodeOperations } from './operations';
import * as styles from './styles.css';
Expand All @@ -41,11 +41,9 @@ export const ExplorerDocNode = ({
canDrop,
operations: additionalOperations,
dropEffect,
explorerTreesType,
}: {
docId: string;
isLinked?: boolean;
explorerTreesType?: ExplorerTreesType;
} & GenericExplorerNode) => {
const t = useI18n();
const { docsSearchService, docsService, globalContextService } = useServices({
Expand Down Expand Up @@ -123,16 +121,13 @@ export const ExplorerDocNode = ({
module: 'doc',
control: 'doc rename',
});
if (explorerTreesType) {
mixpanel.track('PageOptionClick', {
page: 'doc library',
segment: explorerTreesType,
module: explorerTreesType,
control: 'rename',
});
}
mixpanel.track('PageOptionClick', {
segment: 'sidebar',
module: 'doc',
control: 'rename',
});
},
[docId, docsService, explorerTreesType]
[docId, docsService]
);

const handleDropOnDoc = useAsyncCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@ import { DocsService, useLiveData, useServices } from '@toeverything/infra';
import { useCallback, useMemo } from 'react';

import type { NodeOperation } from '../../tree/types';
import type { ExplorerTreesType } from '../types';

export const useExplorerDocNodeOperations = (
docId: string,
options: {
openInfoModal: () => void;
openNodeCollapsed: () => void;
},
explorerTreesType?: ExplorerTreesType
}
): NodeOperation[] => {
const t = useI18n();
const { appSettings } = useAppSettingHelper();
Expand All @@ -52,29 +50,23 @@ export const useExplorerDocNodeOperations = (
);

const handleOpenInfoModal = useCallback(() => {
if (explorerTreesType) {
mixpanel.track('PageOptionClick', {
page: 'doc library',
segment: explorerTreesType,
module: explorerTreesType,
control: 'view info',
});
}
mixpanel.track('PageOptionClick', {
segment: 'sidebar',
module: 'doc',
control: 'view info',
});
options.openInfoModal();
}, [explorerTreesType, options]);
}, [options]);

const handleMoveToTrash = useCallback(() => {
if (!docRecord) {
return;
}
if (explorerTreesType) {
mixpanel.track('PageOptionClick', {
page: 'doc library',
segment: explorerTreesType,
module: explorerTreesType,
control: 'move to trash',
});
}
mixpanel.track('PageOptionClick', {
segment: 'sidebar',
module: 'doc',
control: 'move to trash',
});
openConfirmModal({
title: t['com.affine.moveToTrash.title'](),
description: t['com.affine.moveToTrash.confirmModal.description']({
Expand All @@ -95,7 +87,7 @@ export const useExplorerDocNodeOperations = (
toast(t['com.affine.toastMessage.movedTrash']());
},
});
}, [docRecord, explorerTreesType, openConfirmModal, t]);
}, [docRecord, openConfirmModal, t]);

const handleOpenInSplitView = useCallback(() => {
workbenchService.workbench.openDoc(docId, {
Expand All @@ -106,15 +98,12 @@ export const useExplorerDocNodeOperations = (
module: 'doc',
control: 'open in split view button',
});
if (explorerTreesType) {
mixpanel.track('PageOptionClick', {
page: 'doc library',
segment: explorerTreesType,
module: explorerTreesType,
control: 'open in split view',
});
}
}, [docId, explorerTreesType, workbenchService.workbench]);
mixpanel.track('PageOptionClick', {
segment: 'sidebar',
module: 'doc',
control: 'open in split view',
});
}, [docId, workbenchService.workbench]);

const handleAddLinkedPage = useAsyncCallback(async () => {
const newDoc = docsService.createDoc();
Expand All @@ -130,23 +119,14 @@ export const useExplorerDocNodeOperations = (
module: 'doc',
control: 'add linked doc button',
});
if (explorerTreesType) {
mixpanel.track('PageOptionClick', {
page: 'doc library',
segment: explorerTreesType,
module: explorerTreesType,
control: 'add linked doc',
});
}
mixpanel.track('PageOptionClick', {
segment: 'sidebar',
module: 'doc',
control: 'add linked doc',
});
workbenchService.workbench.openDoc(newDoc.id);
options.openNodeCollapsed();
}, [
docsService,
docId,
explorerTreesType,
workbenchService.workbench,
options,
]);
}, [docsService, docId, workbenchService.workbench, options]);

const handleToggleFavoriteDoc = useCallback(() => {
compatibleFavoriteItemsAdapter.toggle(docId, 'doc');
Expand All @@ -157,15 +137,12 @@ export const useExplorerDocNodeOperations = (
type: 'doc',
id: docId,
});
if (explorerTreesType) {
mixpanel.track('PageOptionClick', {
page: 'doc library',
segment: explorerTreesType,
module: explorerTreesType,
control: favorite ? 'remove from favourites' : 'add to favourites',
});
}
}, [compatibleFavoriteItemsAdapter, docId, explorerTreesType, favorite]);
mixpanel.track('PageOptionClick', {
segment: 'sidebar',
module: 'doc',
control: favorite ? 'remove from favourites' : 'add to favourites',
});
}, [compatibleFavoriteItemsAdapter, docId, favorite]);

return useMemo(
() => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ export const ExplorerFolderNode = ({
canDrop={canDrop}
dropEffect={dropEffect}
operations={additionalOperations}
explorerTreesType="organize"
/>
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ export const ExplorerTagNodeDocs = ({ tag }: { tag: Tag }) => {
location={{
at: 'explorer:tags:docs',
}}
explorerTreesType="tags"
/>
));
};
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,3 @@ export interface GenericExplorerNode {
*/
dropEffect?: ExplorerTreeNodeDropEffect;
}

export type ExplorerTreesType =
| 'favourites'
| 'organize'
| 'migration-favourites'
| 'old-favourites'
| 'collections'
| 'tags';
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ const ExplorerFavoriteNode = ({
onDrop={handleOnChildrenDrop}
dropEffect={dropEffect}
canDrop={canDrop}
explorerTreesType="favourites"
/>
) : favorite.type === 'tag' ? (
<ExplorerTagNode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ const ExplorerMigrationFavoriteNode = ({
location={childLocation}
reorderable={false}
canDrop={false}
explorerTreesType="migration-favourites"
/>
) : (
<ExplorerCollectionNode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ const ExplorerFavoriteNode = ({
onDrop={handleOnChildrenDrop}
dropEffect={dropEffect}
canDrop={canDrop}
explorerTreesType="old-favourites"
/>
) : (
<ExplorerCollectionNode
Expand Down

0 comments on commit c2b687e

Please sign in to comment.