From 8c48ec06791742e0c35819d26f207c850748a742 Mon Sep 17 00:00:00 2001 From: Steven Date: Sat, 24 Jun 2023 23:20:25 +0800 Subject: [PATCH] chore: update shortcut view --- web/src/components/ShortcutListView.tsx | 101 +-------------- web/src/components/ShortcutView.tsx | 116 ++++++++++++++++++ web/src/components/setting/AccountSection.tsx | 13 +- 3 files changed, 125 insertions(+), 105 deletions(-) create mode 100644 web/src/components/ShortcutView.tsx diff --git a/web/src/components/ShortcutListView.tsx b/web/src/components/ShortcutListView.tsx index 12f3190..1537612 100644 --- a/web/src/components/ShortcutListView.tsx +++ b/web/src/components/ShortcutListView.tsx @@ -1,14 +1,6 @@ -import { Tooltip } from "@mui/joy"; -import copy from "copy-to-clipboard"; import { useState } from "react"; -import { toast } from "react-hot-toast"; -import { shortcutService } from "../services"; -import { useAppSelector } from "../stores"; -import { absolutifyLink } from "../helpers/utils"; -import { showCommonDialog } from "./Alert"; -import Icon from "./Icon"; -import Dropdown from "./common/Dropdown"; import CreateShortcutDialog from "./CreateShortcutDialog"; +import ShortcutView from "./ShortcutView"; interface Props { shortcutList: Shortcut[]; @@ -16,102 +8,13 @@ interface Props { const ShortcutListView: React.FC = (props: Props) => { const { shortcutList } = props; - const user = useAppSelector((state) => state.user.user as User); const [editingShortcutId, setEditingShortcutId] = useState(); - const havePermission = (shortcut: Shortcut) => { - return user.role === "ADMIN" || shortcut.creatorId === user.id; - }; - - const handleCopyButtonClick = (shortcut: Shortcut) => { - copy(absolutifyLink(`/s/${shortcut.name}`)); - toast.success("Shortcut link copied to clipboard."); - }; - - const handleDeleteShortcutButtonClick = (shortcut: Shortcut) => { - showCommonDialog({ - title: "Delete Shortcut", - content: `Are you sure to delete shortcut \`${shortcut.name}\` in this workspace?`, - style: "danger", - onConfirm: async () => { - await shortcutService.deleteShortcutById(shortcut.id); - }, - }); - }; - return ( <>
{shortcutList.map((shortcut) => { - return ( -
-
-

- handleCopyButtonClick(shortcut)}> - o/ - {shortcut.name} - -

-
- - - - - - - - - - - - - } - > -
-
- {shortcut.description &&

{shortcut.description}

} - {/* TODO(steven): display shortcut's tags later */} - {shortcut.tags.length > 0 && false && ( -
- - {shortcut.tags.map((tag) => { - return ( - - #{tag} - - ); - })} -
- )} -
- -
- - {shortcut.view} -
-
-
-
- ); + return setEditingShortcutId(shortcut.id)} />; })}
diff --git a/web/src/components/ShortcutView.tsx b/web/src/components/ShortcutView.tsx new file mode 100644 index 0000000..4502ede --- /dev/null +++ b/web/src/components/ShortcutView.tsx @@ -0,0 +1,116 @@ +import copy from "copy-to-clipboard"; +import { absolutifyLink } from "../helpers/utils"; +import toast from "react-hot-toast"; +import { showCommonDialog } from "./Alert"; +import { shortcutService } from "../services"; +import { Tooltip } from "@mui/joy"; +import Icon from "./Icon"; +import Dropdown from "./common/Dropdown"; +import { useAppSelector } from "../stores"; + +interface Props { + shortcut: Shortcut; + handleEdit: () => void; +} + +const ShortcutView = (props: Props) => { + const { shortcut, handleEdit } = props; + const user = useAppSelector((state) => state.user.user as User); + + const havePermission = (shortcut: Shortcut) => { + return user.role === "ADMIN" || shortcut.creatorId === user.id; + }; + + const handleCopyButtonClick = (shortcut: Shortcut) => { + copy(absolutifyLink(`/s/${shortcut.name}`)); + toast.success("Shortcut link copied to clipboard."); + }; + + const handleDeleteShortcutButtonClick = (shortcut: Shortcut) => { + showCommonDialog({ + title: "Delete Shortcut", + content: `Are you sure to delete shortcut \`${shortcut.name}\` in this workspace?`, + style: "danger", + onConfirm: async () => { + await shortcutService.deleteShortcutById(shortcut.id); + }, + }); + }; + + return ( +
+
+

+ handleCopyButtonClick(shortcut)}> + o/ + {shortcut.name} + +

+
+ + + + + + + + + + + + + } + > +
+
+ {shortcut.description &&

{shortcut.description}

} + {shortcut.tags.length > 0 && false && ( +
+ + {shortcut.tags.map((tag) => { + return ( + + #{tag} + + ); + })} +
+ )} +
+ +
+ + {shortcut.creator.nickname} +
+
+ +
+ + {shortcut.view} +
+
+
+
+ ); +}; + +export default ShortcutView; diff --git a/web/src/components/setting/AccountSection.tsx b/web/src/components/setting/AccountSection.tsx index b3242a7..24bc56d 100644 --- a/web/src/components/setting/AccountSection.tsx +++ b/web/src/components/setting/AccountSection.tsx @@ -8,20 +8,21 @@ const AccountSection: React.FC = () => { const user = useAppSelector((state) => state.user).user as User; const [showEditUserinfoDialog, setShowEditUserinfoDialog] = useState(false); const [showChangePasswordDialog, setShowChangePasswordDialog] = useState(false); + const isAdmin = user.role === "ADMIN"; return ( <> -
-

Account

-

- Nickname: - {user.nickname} +

+

Account

+

+ {user.nickname} + {isAdmin && Admin}

Email: {user.email}

-
+