From e1affbf5408d27dc4ceacdbfd6b7362e9ac3e6d5 Mon Sep 17 00:00:00 2001 From: Lukin Date: Fri, 21 Feb 2025 15:26:33 +0800 Subject: [PATCH 1/2] feat(ui): improve mobile navigation and tag-based question creation --- .vscode/settings.json | 13 +++++++----- .../Header/components/NavItems/index.tsx | 20 ++++++++++++++++--- ui/src/components/Header/index.tsx | 7 ------- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index b7d39e6e5..01d235e6d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,9 +1,12 @@ { - "eslint.workingDirectories": [ - "ui" - ], + "eslint.workingDirectories": ["ui"], "explorer.autoReveal": "focusNoScroll", - "cSpell.words": [ - "grecaptcha" + "cSpell.words": ["grecaptcha"], + "i18n-ally.localesPaths": [ + "i18n", + "ui/src/i18n", + "ui/src/plugins/builtin/SearchInfo/i18n", + "ui/src/plugins/builtin/ThirdPartyConnector/i18n", + "ui/src/plugins/builtin/HostingConnector/i18n" ] } diff --git a/ui/src/components/Header/components/NavItems/index.tsx b/ui/src/components/Header/components/NavItems/index.tsx index badd1b795..0b5c56504 100644 --- a/ui/src/components/Header/components/NavItems/index.tsx +++ b/ui/src/components/Header/components/NavItems/index.tsx @@ -20,7 +20,7 @@ import { FC, memo } from 'react'; import { Nav, Dropdown } from 'react-bootstrap'; import { useTranslation } from 'react-i18next'; -import { NavLink, useNavigate } from 'react-router-dom'; +import { NavLink, useMatch, useNavigate } from 'react-router-dom'; import type * as Type from '@/common/interface'; import { Avatar, Icon } from '@/components'; @@ -48,13 +48,27 @@ const Index: FC = ({ redDot, userInfo, logOut }) => { }); } }; + /** + * Automatically append `tag` information when creating a question + */ + const tagMatch = useMatch('/tags/:slugName'); + let askUrl = '/questions/ask'; + if (tagMatch && tagMatch.params.slugName) { + askUrl = `${askUrl}?tags=${encodeURIComponent(tagMatch.params.slugName)}`; + } return ( <>