Skip to content

Commit c689da6

Browse files
committed
🚚(frontend) reduce features coupling
Move some components and assets to `doc-management` to reduce coupling between features: - SimpleDocItem from `doc-grid` to `doc-management` - useCreateChildDoc from `doc-tree` to `doc-management` - isOwnerOrAdmin from `doc-tree` to `doc-management`
1 parent f2e5430 commit c689da6

File tree

13 files changed

+31
-26
lines changed

13 files changed

+31
-26
lines changed

src/frontend/apps/impress/src/features/docs/doc-management/api/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export * from './useCreateChildDoc';
12
export * from './useCreateDoc';
23
export * from './useCreateFavoriteDoc';
34
export * from './useDeleteFavoriteDoc';

src/frontend/apps/impress/src/features/docs/doc-tree/api/useCreateChildren.tsx renamed to src/frontend/apps/impress/src/features/docs/doc-management/api/useCreateChildDoc.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ import { useMutation, useQueryClient } from '@tanstack/react-query';
22

33
import { APIError, errorCauses, fetchAPI } from '@/api';
44

5-
import { Doc, KEY_LIST_DOC } from '../../doc-management';
5+
import { Doc, KEY_LIST_DOC } from '..';
66

7-
export type CreateDocParam = Pick<Doc, 'title'> & {
7+
export type CreateChildDocParam = Pick<Doc, 'title'> & {
88
parentId: string;
99
};
1010

11-
export const createDocChildren = async ({
11+
export const createChildDoc = async ({
1212
title,
1313
parentId,
14-
}: CreateDocParam): Promise<Doc> => {
14+
}: CreateChildDocParam): Promise<Doc> => {
1515
const response = await fetchAPI(`documents/${parentId}/children/`, {
1616
method: 'POST',
1717
body: JSON.stringify({
@@ -26,19 +26,19 @@ export const createDocChildren = async ({
2626
return response.json() as Promise<Doc>;
2727
};
2828

29-
interface CreateDocProps {
30-
onSuccess: (data: Doc) => void;
29+
interface UseCreateChildDocProps {
30+
onSuccess: (doc: Doc) => void;
3131
}
3232

33-
export function useCreateChildrenDoc({ onSuccess }: CreateDocProps) {
33+
export function useCreateChildDoc({ onSuccess }: UseCreateChildDocProps) {
3434
const queryClient = useQueryClient();
35-
return useMutation<Doc, APIError, CreateDocParam>({
36-
mutationFn: createDocChildren,
37-
onSuccess: (data) => {
35+
return useMutation<Doc, APIError, CreateChildDocParam>({
36+
mutationFn: createChildDoc,
37+
onSuccess: (doc) => {
3838
void queryClient.resetQueries({
3939
queryKey: [KEY_LIST_DOC],
4040
});
41-
onSuccess(data);
41+
onSuccess(doc);
4242
},
4343
});
4444
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './ModalRemoveDoc';
2+
export * from './SimpleDocItem';

src/frontend/apps/impress/src/features/docs/doc-search/components/DocSearchItem.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Box, Icon } from '@/components';
22
import { QuickSearchItemContent } from '@/components/quick-search/';
3-
import { Doc } from '@/docs/doc-management';
4-
import { SimpleDocItem } from '@/docs/docs-grid/';
3+
import { Doc, SimpleDocItem } from '@/docs/doc-management';
54
import { useResponsiveStore } from '@/stores';
65

76
type DocSearchItemProps = {
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
export * from './useCreateChildren';
21
export * from './useDocChildren';
32
export * from './useDocTree';
43
export * from './useMove';

src/frontend/apps/impress/src/features/docs/doc-tree/components/DocTree.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@ import { css } from 'styled-components';
1010

1111
import { Box, StyledLink } from '@/components';
1212
import { useCunninghamTheme } from '@/cunningham';
13-
import { Doc, KEY_SUB_PAGE, useDoc, useDocStore } from '@/docs/doc-management';
14-
import { SimpleDocItem } from '@/docs/docs-grid';
13+
import {
14+
Doc,
15+
KEY_SUB_PAGE,
16+
SimpleDocItem,
17+
useDoc,
18+
useDocStore,
19+
} from '@/docs/doc-management';
1520

1621
import { useDocTree } from '../api/useDocTree';
1722
import { useMoveDoc } from '../api/useMove';

src/frontend/apps/impress/src/features/docs/doc-tree/components/DocTreeItemActions.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ import { useTranslation } from 'react-i18next';
1010
import { css } from 'styled-components';
1111

1212
import { Box, BoxButton, Icon } from '@/components';
13-
1413
import {
1514
Doc,
1615
ModalRemoveDoc,
1716
Role,
1817
useCopyDocLink,
19-
} from '../../doc-management';
20-
import { useCreateChildrenDoc } from '../api/useCreateChildren';
18+
useCreateChildDoc,
19+
} from '@/docs/doc-management';
20+
2121
import { useDetachDoc } from '../api/useDetach';
2222
import MoveDocIcon from '../assets/doc-extract-bold.svg';
2323
import { useTreeUtils } from '../hooks';
@@ -97,7 +97,7 @@ export const DocTreeItemActions = ({
9797
},
9898
];
9999

100-
const { mutate: createChildrenDoc } = useCreateChildrenDoc({
100+
const { mutate: createChildDoc } = useCreateChildDoc({
101101
onSuccess: (newDoc) => {
102102
onCreateSuccess?.(newDoc);
103103
void router.push(`/docs/${newDoc.id}`);
@@ -147,7 +147,7 @@ export const DocTreeItemActions = ({
147147
e.stopPropagation();
148148
e.preventDefault();
149149

150-
createChildrenDoc({
150+
createChildDoc({
151151
parentId: doc.id,
152152
});
153153
}}

0 commit comments

Comments
 (0)