🚚(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`
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
export * from './useCreateChildDoc';
|
||||
export * from './useCreateDoc';
|
||||
export * from './useCreateFavoriteDoc';
|
||||
export * from './useDeleteFavoriteDoc';
|
||||
|
||||
@@ -2,16 +2,16 @@ import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
|
||||
import { APIError, errorCauses, fetchAPI } from '@/api';
|
||||
|
||||
import { Doc, KEY_LIST_DOC } from '../../doc-management';
|
||||
import { Doc, KEY_LIST_DOC } from '..';
|
||||
|
||||
export type CreateDocParam = Pick<Doc, 'title'> & {
|
||||
export type CreateChildDocParam = Pick<Doc, 'title'> & {
|
||||
parentId: string;
|
||||
};
|
||||
|
||||
export const createDocChildren = async ({
|
||||
export const createChildDoc = async ({
|
||||
title,
|
||||
parentId,
|
||||
}: CreateDocParam): Promise<Doc> => {
|
||||
}: CreateChildDocParam): Promise<Doc> => {
|
||||
const response = await fetchAPI(`documents/${parentId}/children/`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
@@ -26,19 +26,19 @@ export const createDocChildren = async ({
|
||||
return response.json() as Promise<Doc>;
|
||||
};
|
||||
|
||||
interface CreateDocProps {
|
||||
onSuccess: (data: Doc) => void;
|
||||
interface UseCreateChildDocProps {
|
||||
onSuccess: (doc: Doc) => void;
|
||||
}
|
||||
|
||||
export function useCreateChildrenDoc({ onSuccess }: CreateDocProps) {
|
||||
export function useCreateChildDoc({ onSuccess }: UseCreateChildDocProps) {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<Doc, APIError, CreateDocParam>({
|
||||
mutationFn: createDocChildren,
|
||||
onSuccess: (data) => {
|
||||
return useMutation<Doc, APIError, CreateChildDocParam>({
|
||||
mutationFn: createChildDoc,
|
||||
onSuccess: (doc) => {
|
||||
void queryClient.resetQueries({
|
||||
queryKey: [KEY_LIST_DOC],
|
||||
});
|
||||
onSuccess(data);
|
||||
onSuccess(doc);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 6.7 KiB |
|
Before Width: | Height: | Size: 6.2 KiB After Width: | Height: | Size: 6.2 KiB |
@@ -1 +1,2 @@
|
||||
export * from './ModalRemoveDoc';
|
||||
export * from './SimpleDocItem';
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { Box, Icon } from '@/components';
|
||||
import { QuickSearchItemContent } from '@/components/quick-search/';
|
||||
import { Doc } from '@/docs/doc-management';
|
||||
import { SimpleDocItem } from '@/docs/docs-grid/';
|
||||
import { Doc, SimpleDocItem } from '@/docs/doc-management';
|
||||
import { useResponsiveStore } from '@/stores';
|
||||
|
||||
type DocSearchItemProps = {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
export * from './useCreateChildren';
|
||||
export * from './useDocChildren';
|
||||
export * from './useDocTree';
|
||||
export * from './useMove';
|
||||
|
||||
@@ -11,8 +11,7 @@ import { css } from 'styled-components';
|
||||
|
||||
import { Box, StyledLink } from '@/components';
|
||||
import { useCunninghamTheme } from '@/cunningham';
|
||||
import { Doc } from '@/docs/doc-management';
|
||||
import { SimpleDocItem } from '@/docs/docs-grid';
|
||||
import { Doc, SimpleDocItem } from '@/docs/doc-management';
|
||||
|
||||
import { KEY_DOC_TREE, useDocTree } from '../api/useDocTree';
|
||||
import { useMoveDoc } from '../api/useMove';
|
||||
|
||||
@@ -14,10 +14,10 @@ import {
|
||||
ModalRemoveDoc,
|
||||
Role,
|
||||
useCopyDocLink,
|
||||
useCreateChildDoc,
|
||||
useDuplicateDoc,
|
||||
} from '@/docs/doc-management';
|
||||
|
||||
import { useCreateChildrenDoc } from '../api/useCreateChildren';
|
||||
import { useDetachDoc } from '../api/useDetach';
|
||||
import MoveDocIcon from '../assets/doc-extract-bold.svg';
|
||||
|
||||
@@ -118,7 +118,7 @@ export const DocTreeItemActions = ({
|
||||
},
|
||||
];
|
||||
|
||||
const { mutate: createChildrenDoc } = useCreateChildrenDoc({
|
||||
const { mutate: createChildDoc } = useCreateChildDoc({
|
||||
onSuccess: (newDoc) => {
|
||||
onCreateSuccess?.(newDoc);
|
||||
void router.push(`/docs/${newDoc.id}`);
|
||||
@@ -174,7 +174,7 @@ export const DocTreeItemActions = ({
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
|
||||
createChildrenDoc({
|
||||
createChildDoc({
|
||||
parentId: doc.id,
|
||||
});
|
||||
}}
|
||||
|
||||
@@ -5,7 +5,7 @@ import { css } from 'styled-components';
|
||||
|
||||
import { Box, Icon, StyledLink, Text } from '@/components';
|
||||
import { useCunninghamTheme } from '@/cunningham';
|
||||
import { Doc, LinkReach } from '@/docs/doc-management';
|
||||
import { Doc, LinkReach, SimpleDocItem } from '@/docs/doc-management';
|
||||
import { DocShareModal } from '@/docs/doc-share';
|
||||
import { useResponsiveStore } from '@/stores';
|
||||
|
||||
@@ -13,11 +13,12 @@ import { useResponsiveDocGrid } from '../hooks/useResponsiveDocGrid';
|
||||
|
||||
import { DocsGridActions } from './DocsGridActions';
|
||||
import { DocsGridItemSharedButton } from './DocsGridItemSharedButton';
|
||||
import { SimpleDocItem } from './SimpleDocItem';
|
||||
|
||||
type DocsGridItemProps = {
|
||||
doc: Doc;
|
||||
dragMode?: boolean;
|
||||
};
|
||||
|
||||
export const DocsGridItem = ({ doc, dragMode = false }: DocsGridItemProps) => {
|
||||
const { t } = useTranslation();
|
||||
const { isDesktop } = useResponsiveStore();
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
export * from './DocsGrid';
|
||||
export * from './DocsGridActions';
|
||||
export * from './SimpleDocItem';
|
||||
export * from './DocsGridLoader';
|
||||
|
||||
@@ -3,9 +3,9 @@ import { css } from 'styled-components';
|
||||
|
||||
import { Box, StyledLink } from '@/components';
|
||||
import { useCunninghamTheme } from '@/cunningham';
|
||||
import { Doc } from '@/docs/doc-management';
|
||||
import { Doc, SimpleDocItem } from '@/docs/doc-management';
|
||||
import { DocShareModal } from '@/docs/doc-share';
|
||||
import { DocsGridActions, SimpleDocItem } from '@/docs/docs-grid';
|
||||
import { DocsGridActions } from '@/docs/docs-grid';
|
||||
import { useResponsiveStore } from '@/stores';
|
||||
|
||||
type LeftPanelFavoriteItemProps = {
|
||||
|
||||
Reference in New Issue
Block a user