chore: add useNavigateTo hook

This commit is contained in:
steven
2023-09-24 21:21:34 +08:00
parent f78b072bb8
commit 159dfc9446
9 changed files with 47 additions and 45 deletions

View File

@ -1,6 +1,6 @@
import { useState } from "react";
import { useTranslation } from "react-i18next";
import { useNavigate } from "react-router-dom";
import useNavigateTo from "@/hooks/useNavigateTo";
import { shortcutService } from "../services";
import useUserStore from "../stores/v1/user";
import { showCommonDialog } from "./Alert";
@ -16,7 +16,7 @@ interface Props {
const ShortcutActionsDropdown = (props: Props) => {
const { shortcut } = props;
const { t } = useTranslation();
const navigate = useNavigate();
const navigateTo = useNavigateTo();
const currentUser = useUserStore().getCurrentUser();
const [showEditDialog, setShowEditDialog] = useState<boolean>(false);
const [showQRCodeDialog, setShowQRCodeDialog] = useState<boolean>(false);
@ -34,7 +34,7 @@ const ShortcutActionsDropdown = (props: Props) => {
};
const gotoAnalytics = () => {
navigate(`/shortcut/${shortcut.id}#analytics`);
navigateTo(`/shortcut/${shortcut.id}#analytics`);
};
return (

View File

@ -1,5 +1,4 @@
import { ReactNode, useEffect, useRef } from "react";
import useToggle from "../../hooks/useToggle";
import { ReactNode, useEffect, useRef, useState } from "react";
import Icon from "../Icon";
interface Props {
@ -11,14 +10,14 @@ interface Props {
const Dropdown: React.FC<Props> = (props: Props) => {
const { trigger, actions, className, actionsClassName } = props;
const [dropdownStatus, toggleDropdownStatus] = useToggle(false);
const [dropdownStatus, setDropdownStatus] = useState(false);
const dropdownWrapperRef = useRef<HTMLDivElement>(null);
useEffect(() => {
if (dropdownStatus) {
const handleClickOutside = (event: MouseEvent) => {
if (!dropdownWrapperRef.current?.contains(event.target as Node)) {
toggleDropdownStatus(false);
setDropdownStatus(false);
}
};
@ -35,7 +34,7 @@ const Dropdown: React.FC<Props> = (props: Props) => {
const handleToggleDropdownStatus = (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
e.stopPropagation();
toggleDropdownStatus();
setDropdownStatus(!dropdownStatus);
};
return (