From b3640699e041b7dd15d85f3509abf2bb6389bbd2 Mon Sep 17 00:00:00 2001 From: Steven Date: Fri, 23 Jun 2023 12:34:02 +0800 Subject: [PATCH] feat: add shortcut tags in UI --- web/src/components/CreateShortcutDialog.tsx | 18 +++++++++++++++++- web/src/components/ShortcutListView.tsx | 19 +++++++++++++++---- web/src/helpers/api.ts | 7 +++---- web/src/types/modules/shortcut.d.ts | 4 ++++ 4 files changed, 39 insertions(+), 9 deletions(-) diff --git a/web/src/components/CreateShortcutDialog.tsx b/web/src/components/CreateShortcutDialog.tsx index 512265a..dcfdffd 100644 --- a/web/src/components/CreateShortcutDialog.tsx +++ b/web/src/components/CreateShortcutDialog.tsx @@ -23,8 +23,10 @@ const CreateShortcutDialog: React.FC = (props: Props) => { link: "", description: "", visibility: "PRIVATE", + tags: [], }, }); + const [tag, setTag] = useState(""); const requestState = useLoading(false); useEffect(() => { @@ -40,6 +42,7 @@ const CreateShortcutDialog: React.FC = (props: Props) => { visibility: shortcutTemp.visibility, }), }); + setTag(shortcutTemp.tags.join(" ")); } } }, [shortcutId]); @@ -67,6 +70,11 @@ const CreateShortcutDialog: React.FC = (props: Props) => { handleInputChange(e, "description"); }; + const handleTagsInputChange = (e: React.ChangeEvent) => { + const text = e.target.value as string; + setTag(text); + }; + const handleVisibilityInputChange = (e: React.ChangeEvent) => { handleInputChange(e, "visibility"); }; @@ -85,9 +93,13 @@ const CreateShortcutDialog: React.FC = (props: Props) => { link: state.shortcutCreate.link, description: state.shortcutCreate.description, visibility: state.shortcutCreate.visibility, + tags: tag.split(" "), }); } else { - await shortcutService.createShortcut(state.shortcutCreate); + await shortcutService.createShortcut({ + ...state.shortcutCreate, + tags: tag.split(" "), + }); } if (onConfirm) { @@ -145,6 +157,10 @@ const CreateShortcutDialog: React.FC = (props: Props) => { onChange={handleDescriptionInputChange} /> +
+ Tags + +
Visibility * diff --git a/web/src/components/ShortcutListView.tsx b/web/src/components/ShortcutListView.tsx index d27a555..b68024e 100644 --- a/web/src/components/ShortcutListView.tsx +++ b/web/src/components/ShortcutListView.tsx @@ -58,10 +58,21 @@ const ShortcutListView: React.FC = (props: Props) => {
{shortcutList.map((shortcut) => { return ( -
-
- {shortcut.name} - ({shortcut.description}) +
+
+

+ {shortcut.name} + {shortcut.description && ({shortcut.description})} +

+
+ {shortcut.tags.map((tag) => { + return ( + + #{tag} + + ); + })} +
{shortcut.creator.nickname} diff --git a/web/src/helpers/api.ts b/web/src/helpers/api.ts index 0d720c8..8fcd0d0 100644 --- a/web/src/helpers/api.ts +++ b/web/src/helpers/api.ts @@ -47,13 +47,12 @@ export function getShortcutList(shortcutFind?: ShortcutFind) { if (shortcutFind?.creatorId) { queryList.push(`creatorId=${shortcutFind.creatorId}`); } + if (shortcutFind?.tag) { + queryList.push(`tag=${shortcutFind.tag}`); + } return axios.get(`/api/v1/shortcut?${queryList.join("&")}`); } -export function getShortcutWithNameAndWorkspaceName(workspaceName: string, shortcutName: string) { - return axios.get(`/api/v1/workspace/${workspaceName}/shortcut/${shortcutName}`); -} - export function createShortcut(shortcutCreate: ShortcutCreate) { return axios.post("/api/v1/shortcut", shortcutCreate); } diff --git a/web/src/types/modules/shortcut.d.ts b/web/src/types/modules/shortcut.d.ts index 9a3bc07..6cf782e 100644 --- a/web/src/types/modules/shortcut.d.ts +++ b/web/src/types/modules/shortcut.d.ts @@ -15,6 +15,7 @@ interface Shortcut { link: string; description: string; visibility: Visibility; + tags: string[]; } interface ShortcutCreate { @@ -22,6 +23,7 @@ interface ShortcutCreate { link: string; description: string; visibility: Visibility; + tags: string[]; } interface ShortcutPatch { @@ -31,8 +33,10 @@ interface ShortcutPatch { link?: string; description?: string; visibility?: Visibility; + tags?: string[]; } interface ShortcutFind { creatorId?: UserId; + tag?: string; }