From 027ecf294c367f6dce84928cee7fccafa560c372 Mon Sep 17 00:00:00 2001 From: haitaoo Date: Wed, 15 Feb 2023 11:55:27 +0800 Subject: [PATCH 1/5] feat(Question): Automatically attach tag parameters to question links when rendering tag detail pages --- ui/src/components/Header/index.tsx | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/ui/src/components/Header/index.tsx b/ui/src/components/Header/index.tsx index 15a6bae9..eda36a03 100644 --- a/ui/src/components/Header/index.tsx +++ b/ui/src/components/Header/index.tsx @@ -15,6 +15,7 @@ import { Link, useNavigate, useLocation, + useMatch, } from 'react-router-dom'; import classnames from 'classnames'; @@ -35,16 +36,22 @@ import './index.scss'; const Header: FC = () => { const navigate = useNavigate(); - const { user, clear: clearUserStore } = loggedUserInfoStore(); - const { t } = useTranslation(); + const location = useLocation(); const [urlSearch] = useSearchParams(); const q = urlSearch.get('q'); + const { user, clear: clearUserStore } = loggedUserInfoStore(); + const { t } = useTranslation(); const [searchStr, setSearch] = useState(''); const siteInfo = siteInfoStore((state) => state.siteInfo); const brandingInfo = brandingStore((state) => state.branding); const loginSetting = loginSettingStore((state) => state.login); const { data: redDot } = useQueryNotificationStatus(); - const location = useLocation(); + const tagMatch = useMatch('/tags/:slugName'); + let askUrl = '/questions/ask'; + if (tagMatch && tagMatch.params.slugName) { + askUrl = `${askUrl}?tags=${tagMatch.params.slugName}`; + } + const handleInput = (val) => { setSearch(val); }; @@ -189,7 +196,7 @@ const Header: FC = () => { {t('btns.add_question')} @@ -202,7 +209,7 @@ const Header: FC = () => {