From 2fb171e069067708a7a1f3bc3720f3c328d3d6b4 Mon Sep 17 00:00:00 2001 From: boojack Date: Thu, 22 Dec 2022 09:29:22 +0800 Subject: [PATCH] chore: update create tag dialog style (#818) * chore: update create tag dialog * chore: update --- web/src/components/CreateTagDialog.tsx | 22 +++++++++++++++------- web/src/components/Sidebar.tsx | 8 ++++++-- web/src/components/TagList.tsx | 5 ++--- web/src/less/tag-list.less | 2 +- web/src/locales/en.json | 2 +- 5 files changed, 25 insertions(+), 14 deletions(-) diff --git a/web/src/components/CreateTagDialog.tsx b/web/src/components/CreateTagDialog.tsx index 460b9ff1..94a070fa 100644 --- a/web/src/components/CreateTagDialog.tsx +++ b/web/src/components/CreateTagDialog.tsx @@ -1,5 +1,5 @@ import { TextField } from "@mui/joy"; -import { useEffect, useState } from "react"; +import React, { useEffect, useState } from "react"; import { useTagStore } from "../store/module"; import { getTagSuggestionList } from "../helpers/api"; import Tag from "../labs/marked/parser/Tag"; @@ -31,8 +31,14 @@ const CreateTagDialog: React.FC = (props: Props) => { }); }, []); - const handleTagNameChanged = (e: React.ChangeEvent) => { - const tagName = e.target.value as string; + const handleTagNameInputKeyDown = (event: React.KeyboardEvent) => { + if (event.key === "Enter") { + handleSaveBtnClick(); + } + }; + + const handleTagNameChanged = (event: React.ChangeEvent) => { + const tagName = event.target.value; setTagName(tagName.trim()); }; @@ -48,6 +54,7 @@ const CreateTagDialog: React.FC = (props: Props) => { try { await tagStore.upsertTag(tagName); + setTagName(""); } catch (error: any) { console.error(error); toastHelper.error(error.response.data.message); @@ -80,9 +87,10 @@ const CreateTagDialog: React.FC = (props: Props) => { placeholder="TAG_NAME" value={tagName} onChange={handleTagNameChanged} + onKeyDown={handleTagNameInputKeyDown} fullWidth startDecorator={} - endDecorator={} + endDecorator={} /> {tagNameList.length > 0 && ( <> @@ -90,7 +98,7 @@ const CreateTagDialog: React.FC = (props: Props) => {
{tagNameList.map((tag) => ( handleDeleteTag(tag)} > @@ -107,7 +115,7 @@ const CreateTagDialog: React.FC = (props: Props) => {
{shownSuggestTagNameList.map((tag) => ( handleUpsertSuggestTag(tag)} > @@ -116,7 +124,7 @@ const CreateTagDialog: React.FC = (props: Props) => { ))}
- {!userStore.isVisitorMode() && } - + {!userStore.isVisitorMode() && ( + <> + + + + )} ); diff --git a/web/src/components/TagList.tsx b/web/src/components/TagList.tsx index 5e19db09..f96bc1d3 100644 --- a/web/src/components/TagList.tsx +++ b/web/src/components/TagList.tsx @@ -1,6 +1,6 @@ import { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; -import { useLocationStore, useTagStore, useUserStore } from "../store/module"; +import { useLocationStore, useTagStore } from "../store/module"; import useToggle from "../hooks/useToggle"; import Icon from "./Icon"; import showCreateTagDialog from "./CreateTagDialog"; @@ -15,7 +15,6 @@ interface Tag { const TagList = () => { const { t } = useTranslation(); const locationStore = useLocationStore(); - const userStore = useUserStore(); const tagStore = useTagStore(); const tagsText = tagStore.state.tags; const query = locationStore.state.query; @@ -84,7 +83,7 @@ const TagList = () => { {tags.map((t, idx) => ( ))} - {!userStore.isVisitorMode() && tags.length === 0 &&

{t("tag-list.tip-text")}

} + {tags.length < 3 &&

{t("tag-list.tip-text")}

} ); diff --git a/web/src/less/tag-list.less b/web/src/less/tag-list.less index dd0f233f..290365df 100644 --- a/web/src/less/tag-list.less +++ b/web/src/less/tag-list.less @@ -54,7 +54,7 @@ } > .tip-text { - @apply w-full bg-gray-50 dark:bg-zinc-700 mt-2 pl-4 leading-8 rounded text-sm text-gray-400 font-mono; + @apply w-full bg-gray-50 dark:bg-zinc-700 mt-2 px-4 py-1 leading-5 rounded text-sm text-gray-400 font-mono; } } } diff --git a/web/src/locales/en.json b/web/src/locales/en.json index 52e85d68..f624709e 100644 --- a/web/src/locales/en.json +++ b/web/src/locales/en.json @@ -141,7 +141,7 @@ "text-placeholder": "Starts with ^ to use regex" }, "tag-list": { - "tip-text": "Enter `#tag ` to create" + "tip-text": "Click the '+' button or input `#tag ` to create a new tag." }, "search": { "quickly-filter": "Quickly filter"