mirror of
https://github.com/aykhans/slash-e.git
synced 2025-07-03 12:17:55 +00:00
fix: update shortcut
This commit is contained in:
@ -6,18 +6,18 @@ import { GetShortcutAnalyticsResponse } from "@/types/proto/api/v2/shortcut_serv
|
||||
import Icon from "./Icon";
|
||||
|
||||
interface Props {
|
||||
shortcutName: string;
|
||||
shortcutId: number;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
const AnalyticsView: React.FC<Props> = (props: Props) => {
|
||||
const { shortcutName, className } = props;
|
||||
const { shortcutId, className } = props;
|
||||
const { t } = useTranslation();
|
||||
const [analytics, setAnalytics] = useState<GetShortcutAnalyticsResponse | null>(null);
|
||||
const [selectedDeviceTab, setSelectedDeviceTab] = useState<"os" | "browser">("browser");
|
||||
|
||||
useEffect(() => {
|
||||
shortcutServiceClient.getShortcutAnalytics({ name: shortcutName }).then((response) => {
|
||||
shortcutServiceClient.getShortcutAnalytics({ id: shortcutId }).then((response) => {
|
||||
setAnalytics(response);
|
||||
});
|
||||
}, []);
|
||||
|
@ -62,7 +62,7 @@ const CollectionView = (props: Props) => {
|
||||
<div className="bg-gray-100 dark:bg-zinc-800 px-3 py-2 w-full flex flex-row justify-between items-center rounded-t-lg">
|
||||
<div className="w-auto flex flex-col justify-start items-start mr-2">
|
||||
<div className="w-full truncate">
|
||||
<Link className="leading-6 font-medium dark:text-gray-400" to={`/c/${collection.name}`}>
|
||||
<Link className="leading-6 font-medium dark:text-gray-400" to={`/c/${collection.name}`} unstable_viewTransition>
|
||||
{collection.title}
|
||||
</Link>
|
||||
<span className="ml-1 leading-6 text-gray-500 dark:text-gray-400" onClick={handleCopyCollectionLink}>
|
||||
|
@ -25,7 +25,7 @@ import Icon from "./Icon";
|
||||
import ResourceNameInput from "./ResourceNameInput";
|
||||
|
||||
interface Props {
|
||||
shortcutName?: string;
|
||||
shortcutId?: number;
|
||||
initialShortcut?: Partial<Shortcut>;
|
||||
onClose: () => void;
|
||||
onConfirm?: () => void;
|
||||
@ -36,7 +36,7 @@ interface State {
|
||||
}
|
||||
|
||||
const CreateShortcutDrawer: React.FC<Props> = (props: Props) => {
|
||||
const { onClose, onConfirm, shortcutName, initialShortcut } = props;
|
||||
const { onClose, onConfirm, shortcutId, initialShortcut } = props;
|
||||
const { t } = useTranslation();
|
||||
const [state, setState] = useState<State>({
|
||||
shortcutCreate: Shortcut.fromPartial({
|
||||
@ -54,13 +54,13 @@ const CreateShortcutDrawer: React.FC<Props> = (props: Props) => {
|
||||
const shortcutList = shortcutStore.getShortcutList();
|
||||
const [tag, setTag] = useState<string>("");
|
||||
const tagSuggestions = uniq(shortcutList.map((shortcut) => shortcut.tags).flat());
|
||||
const isCreating = isUndefined(shortcutName);
|
||||
const isCreating = isUndefined(shortcutId);
|
||||
const loadingState = useLoading(!isCreating);
|
||||
const requestState = useLoading(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (shortcutName) {
|
||||
const shortcut = shortcutStore.getShortcutByName(shortcutName);
|
||||
if (shortcutId) {
|
||||
const shortcut = shortcutStore.getShortcutById(shortcutId);
|
||||
if (shortcut) {
|
||||
setState({
|
||||
...state,
|
||||
@ -77,7 +77,7 @@ const CreateShortcutDrawer: React.FC<Props> = (props: Props) => {
|
||||
loadingState.setFinish();
|
||||
}
|
||||
}
|
||||
}, [shortcutName]);
|
||||
}, [shortcutId]);
|
||||
|
||||
if (loadingState.isLoading) {
|
||||
return null;
|
||||
@ -183,16 +183,14 @@ const CreateShortcutDrawer: React.FC<Props> = (props: Props) => {
|
||||
}
|
||||
|
||||
try {
|
||||
if (shortcutName) {
|
||||
if (shortcutId) {
|
||||
const originShortcut = shortcutStore.getShortcutById(shortcutId);
|
||||
const updatingShortcut = {
|
||||
...state.shortcutCreate,
|
||||
name: shortcutName,
|
||||
id: shortcutId,
|
||||
tags: tag.split(" ").filter(Boolean),
|
||||
};
|
||||
await shortcutStore.updateShortcut(
|
||||
updatingShortcut,
|
||||
getShortcutUpdateMask(shortcutStore.getShortcutByName(updatingShortcut.name), updatingShortcut)
|
||||
);
|
||||
await shortcutStore.updateShortcut(updatingShortcut, getShortcutUpdateMask(originShortcut, updatingShortcut));
|
||||
} else {
|
||||
await shortcutStore.createShortcut({
|
||||
...state.shortcutCreate,
|
||||
|
@ -19,7 +19,8 @@ const Header: React.FC = () => {
|
||||
const [showAboutDialog, setShowAboutDialog] = useState<boolean>(false);
|
||||
const profile = workspaceStore.profile;
|
||||
const isAdmin = currentUser.role === Role.ADMIN;
|
||||
const shouldShowRouterSwitch = location.pathname === "/" || location.pathname === "/collections";
|
||||
const shouldShowRouterSwitch = location.pathname === "/" || location.pathname === "/collections" || location.pathname === "/memos";
|
||||
const selectedSection = location.pathname === "/" ? "Shortcuts" : location.pathname === "/collections" ? "Collections" : "Memos";
|
||||
|
||||
const handleSignOutButtonClick = async () => {
|
||||
await authServiceClient.signOut({});
|
||||
@ -31,7 +32,7 @@ const Header: React.FC = () => {
|
||||
<div className="w-full bg-gray-50 dark:bg-zinc-800 border-b border-b-gray-200 dark:border-b-zinc-800">
|
||||
<div className="w-full max-w-8xl mx-auto px-3 md:px-12 py-3 flex flex-row justify-between items-center">
|
||||
<div className="flex flex-row justify-start items-center shrink mr-2">
|
||||
<Link to="/" className="cursor-pointer flex flex-row justify-start items-center dark:text-gray-400">
|
||||
<Link to="/" className="cursor-pointer flex flex-row justify-start items-center dark:text-gray-400" unstable_viewTransition>
|
||||
<img id="logo-img" src="/logo.png" className="w-7 h-auto mr-2 -mt-0.5 dark:opacity-80 rounded-full shadow" alt="" />
|
||||
Slash
|
||||
</Link>
|
||||
@ -46,7 +47,7 @@ const Header: React.FC = () => {
|
||||
<Dropdown
|
||||
trigger={
|
||||
<button className="flex flex-row justify-end items-center cursor-pointer">
|
||||
<span className="dark:text-gray-400">{location.pathname === "/" ? "Shortcuts" : "Collections"}</span>
|
||||
<span className="dark:text-gray-400">{selectedSection}</span>
|
||||
<Icon.ChevronsUpDown className="ml-1 w-4 h-auto text-gray-600 dark:text-gray-400" />
|
||||
</button>
|
||||
}
|
||||
@ -54,14 +55,16 @@ const Header: React.FC = () => {
|
||||
actions={
|
||||
<>
|
||||
<Link
|
||||
to="/"
|
||||
className="w-full px-2 flex flex-row justify-start items-center text-left dark:text-gray-400 leading-8 cursor-pointer rounded hover:bg-gray-100 dark:hover:bg-zinc-800 disabled:cursor-not-allowed disabled:bg-gray-100 disabled:opacity-60"
|
||||
to="/"
|
||||
unstable_viewTransition
|
||||
>
|
||||
<Icon.SquareSlash className="w-4 h-auto mr-2 opacity-70" /> Shortcuts
|
||||
</Link>
|
||||
<Link
|
||||
to="/collections"
|
||||
className="w-full px-2 flex flex-row justify-start items-center text-left dark:text-gray-400 leading-8 cursor-pointer rounded hover:bg-gray-100 dark:hover:bg-zinc-800 disabled:cursor-not-allowed disabled:bg-gray-100 disabled:opacity-60"
|
||||
to="/collections"
|
||||
unstable_viewTransition
|
||||
>
|
||||
<Icon.LibrarySquare className="w-4 h-auto mr-2 opacity-70" /> Collections
|
||||
</Link>
|
||||
@ -84,15 +87,17 @@ const Header: React.FC = () => {
|
||||
actions={
|
||||
<>
|
||||
<Link
|
||||
to="/setting/general"
|
||||
className="w-full px-2 flex flex-row justify-start items-center text-left dark:text-gray-400 leading-8 cursor-pointer rounded hover:bg-gray-100 dark:hover:bg-zinc-800 disabled:cursor-not-allowed disabled:bg-gray-100 disabled:opacity-60"
|
||||
to="/setting/general"
|
||||
unstable_viewTransition
|
||||
>
|
||||
<Icon.User className="w-4 h-auto mr-2 opacity-70" /> {t("user.profile")}
|
||||
</Link>
|
||||
{isAdmin && (
|
||||
<Link
|
||||
to="/setting/workspace"
|
||||
className="w-full px-2 flex flex-row justify-start items-center text-left dark:text-gray-400 leading-8 cursor-pointer rounded hover:bg-gray-100 dark:hover:bg-zinc-800 disabled:cursor-not-allowed disabled:bg-gray-100 disabled:opacity-60"
|
||||
to="/setting/workspace"
|
||||
unstable_viewTransition
|
||||
>
|
||||
<Icon.Settings className="w-4 h-auto mr-2 opacity-70" /> {t("settings.self")}
|
||||
</Link>
|
||||
|
@ -31,7 +31,7 @@ const ShortcutActionsDropdown = (props: Props) => {
|
||||
content: `Are you sure to delete shortcut \`${shortcut.name}\`? You cannot undo this action.`,
|
||||
style: "danger",
|
||||
onConfirm: async () => {
|
||||
await shortcutStore.deleteShortcut(shortcut.name);
|
||||
await shortcutStore.deleteShortcut(shortcut.id);
|
||||
},
|
||||
});
|
||||
};
|
||||
@ -82,7 +82,7 @@ const ShortcutActionsDropdown = (props: Props) => {
|
||||
|
||||
{showEditDrawer && (
|
||||
<CreateShortcutDrawer
|
||||
shortcutName={shortcut.name}
|
||||
shortcutId={shortcut.id}
|
||||
onClose={() => setShowEditDrawer(false)}
|
||||
onConfirm={() => setShowEditDrawer(false)}
|
||||
/>
|
||||
|
@ -38,8 +38,9 @@ const ShortcutCard = (props: Props) => {
|
||||
<div className="w-full flex flex-row justify-between items-center">
|
||||
<div className="w-[calc(100%-16px)] flex flex-row justify-start items-center mr-1 shrink-0">
|
||||
<Link
|
||||
to={`/shortcut/${shortcut.name}`}
|
||||
className={classNames("w-8 h-8 flex justify-center items-center overflow-clip shrink-0")}
|
||||
to={`/shortcut/${shortcut.id}`}
|
||||
unstable_viewTransition
|
||||
>
|
||||
{favicon ? (
|
||||
<img className="w-full h-auto rounded" src={favicon} decoding="async" loading="lazy" />
|
||||
@ -123,8 +124,9 @@ const ShortcutCard = (props: Props) => {
|
||||
</Tooltip>
|
||||
<Tooltip title="View count" variant="solid" placement="top" arrow>
|
||||
<Link
|
||||
to={`/shortcut/${shortcut.name}#analytics`}
|
||||
className="w-auto leading-5 flex flex-row justify-start items-center flex-nowrap whitespace-nowrap cursor-pointer text-gray-400 text-sm"
|
||||
to={`/shortcut/${shortcut.id}#analytics`}
|
||||
unstable_viewTransition
|
||||
>
|
||||
<Icon.BarChart2 className="w-4 h-auto mr-1 opacity-70" />
|
||||
{t("shortcut.visits", { count: shortcut.viewCount })}
|
||||
|
Reference in New Issue
Block a user