mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 04:46:40 +07:00
moved tags to sidebar (#135)
This commit is contained in:
parent
a8ac233140
commit
b36dcca0df
13 changed files with 99 additions and 71 deletions
|
@ -1,14 +1,14 @@
|
|||
import { useCallback } from 'react';
|
||||
|
||||
import { apiDeleteNodeTag, apiPostNodeTags } from '~/api/node';
|
||||
import { Dialog } from '~/constants/modal';
|
||||
import { useShowModal } from '~/hooks/modal/useShowModal';
|
||||
import { useGetNodeRelated } from '~/hooks/node/useGetNodeRelated';
|
||||
import { useLoadNode } from '~/hooks/node/useLoadNode';
|
||||
import { ITag } from '~/types';
|
||||
|
||||
import { useTagSidebar } from '../sidebar/useTagSidebar';
|
||||
|
||||
export const useNodeTags = (id: number) => {
|
||||
const showModal = useShowModal(Dialog.TagSidebar);
|
||||
const openTagSidebar = useTagSidebar();
|
||||
const { refresh: refreshRelated } = useGetNodeRelated(id);
|
||||
const { update } = useLoadNode(id);
|
||||
|
||||
|
@ -22,7 +22,7 @@ export const useNodeTags = (id: number) => {
|
|||
console.warn(error);
|
||||
}
|
||||
},
|
||||
[id, update, refreshRelated]
|
||||
[id, update, refreshRelated],
|
||||
);
|
||||
|
||||
const onClick = useCallback(
|
||||
|
@ -31,9 +31,9 @@ export const useNodeTags = (id: number) => {
|
|||
return;
|
||||
}
|
||||
|
||||
showModal({ tag: tag.title });
|
||||
openTagSidebar(tag.title);
|
||||
},
|
||||
[showModal, id]
|
||||
[openTagSidebar, id],
|
||||
);
|
||||
|
||||
const onDelete = useCallback(
|
||||
|
@ -46,7 +46,7 @@ export const useNodeTags = (id: number) => {
|
|||
console.warn(e);
|
||||
}
|
||||
},
|
||||
[id, update, refreshRelated]
|
||||
[id, update, refreshRelated],
|
||||
);
|
||||
|
||||
return { onDelete, onChange, onClick };
|
||||
|
|
20
src/hooks/sidebar/useTagSidebar.ts
Normal file
20
src/hooks/sidebar/useTagSidebar.ts
Normal file
|
@ -0,0 +1,20 @@
|
|||
import { useCallback } from 'react';
|
||||
|
||||
import { SidebarName } from '~/constants/sidebar';
|
||||
import { ITag } from '~/types';
|
||||
import { useSidebar } from '~/utils/providers/SidebarProvider';
|
||||
|
||||
export const useTagSidebar = () => {
|
||||
const { open } = useSidebar();
|
||||
|
||||
return useCallback(
|
||||
(tag: string) => {
|
||||
if (!tag) {
|
||||
return;
|
||||
}
|
||||
|
||||
open(SidebarName.Tag, { tag });
|
||||
},
|
||||
[open],
|
||||
);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue