chore: update create tag dialog (#881)

pull/882/head
boojack 2 years ago committed by GitHub
parent 7670c95360
commit 51eac649c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -22,6 +22,7 @@ const CreateTagDialog: React.FC<Props> = (props: Props) => {
const tagStore = useTagStore(); const tagStore = useTagStore();
const [tagName, setTagName] = useState<string>(""); const [tagName, setTagName] = useState<string>("");
const [suggestTagNameList, setSuggestTagNameList] = useState<string[]>([]); const [suggestTagNameList, setSuggestTagNameList] = useState<string[]>([]);
const [showTagSuggestions, setShowTagSuggestions] = useState<boolean>(false);
const tagNameList = tagStore.state.tags; const tagNameList = tagStore.state.tags;
const shownSuggestTagNameList = suggestTagNameList.filter((tag) => !tagNameList.includes(tag)); const shownSuggestTagNameList = suggestTagNameList.filter((tag) => !tagNameList.includes(tag));
@ -42,10 +43,14 @@ const CreateTagDialog: React.FC<Props> = (props: Props) => {
setTagName(tagName.trim()); setTagName(tagName.trim());
}; };
const handleUpsertSuggestTag = async (tagName: string) => { const handleUpsertTag = async (tagName: string) => {
await tagStore.upsertTag(tagName); await tagStore.upsertTag(tagName);
}; };
const handleToggleShowSuggestionTags = () => {
setShowTagSuggestions((state) => !state);
};
const handleSaveBtnClick = async () => { const handleSaveBtnClick = async () => {
if (!validateTagName(tagName)) { if (!validateTagName(tagName)) {
toastHelper.error("Invalid tag name"); toastHelper.error("Invalid tag name");
@ -111,24 +116,30 @@ const CreateTagDialog: React.FC<Props> = (props: Props) => {
{shownSuggestTagNameList.length > 0 && ( {shownSuggestTagNameList.length > 0 && (
<> <>
<p className="w-full mt-2 mb-1 text-sm text-gray-400">Tag suggestions</p> <div className="mt-4 mb-1 text-sm w-full flex flex-row justify-start items-center">
<div className="w-full flex flex-row justify-start items-start flex-wrap"> <span className="text-gray-400">Tag suggestions</span>
{shownSuggestTagNameList.map((tag) => ( <button className="btn-normal ml-2 px-2 py-0 leading-6 font-mono" onClick={handleToggleShowSuggestionTags}>
<span {showTagSuggestions ? "hide" : "show"}
className="max-w-[120px] text-sm mr-2 mt-1 font-mono cursor-pointer truncate dark:text-gray-300 hover:opacity-60" </button>
key={tag}
onClick={() => handleUpsertSuggestTag(tag)}
>
#{tag}
</span>
))}
</div> </div>
<button {showTagSuggestions && (
className="mt-2 text-sm border px-2 leading-6 rounded cursor-pointer dark:border-gray-400 dark:text-gray-300 hover:opacity-80 hover:shadow" <>
onClick={handleSaveSuggestTagList} <div className="w-full flex flex-row justify-start items-start flex-wrap">
> {shownSuggestTagNameList.map((tag) => (
Save all <span
</button> className="max-w-[120px] text-sm mr-2 mt-1 font-mono cursor-pointer truncate dark:text-gray-300 hover:opacity-60"
key={tag}
onClick={() => handleUpsertTag(tag)}
>
#{tag}
</span>
))}
</div>
<button className="btn-normal mt-2 px-2 py-0 leading-6 font-mono" onClick={handleSaveSuggestTagList}>
Save all
</button>
</>
)}
</> </>
)} )}
</div> </div>

@ -1,4 +1,4 @@
import { useEffect, useState } from "react"; import { useState } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { useGlobalStore } from "../store/module"; import { useGlobalStore } from "../store/module";
import * as api from "../helpers/api"; import * as api from "../helpers/api";
@ -15,11 +15,7 @@ const UpdateCustomizedProfileDialog: React.FC<Props> = ({ destroy }: Props) => {
const globalStore = useGlobalStore(); const globalStore = useGlobalStore();
const [state, setState] = useState<CustomizedProfile>(globalStore.state.systemStatus.customizedProfile); const [state, setState] = useState<CustomizedProfile>(globalStore.state.systemStatus.customizedProfile);
useEffect(() => { const handleCloseButtonClick = () => {
// do nth
}, []);
const handleCloseBtnClick = () => {
destroy(); destroy();
}; };
@ -68,9 +64,20 @@ const UpdateCustomizedProfileDialog: React.FC<Props> = ({ destroy }: Props) => {
}); });
}; };
const handleSaveBtnClick = async () => { const handleRestoreButtonClick = () => {
if (state.name === "" || state.logoUrl === "") { setState({
toastHelper.error(t("message.fill-all")); name: "memos",
logoUrl: "/logo.png",
description: "",
locale: "en",
appearance: "system",
externalUrl: "",
});
};
const handleSaveButtonClick = async () => {
if (state.name === "") {
toastHelper.error("Please fill server name");
return; return;
} }
@ -92,7 +99,7 @@ const UpdateCustomizedProfileDialog: React.FC<Props> = ({ destroy }: Props) => {
<> <>
<div className="dialog-header-container"> <div className="dialog-header-container">
<p className="title-text">{t("setting.system-section.customize-server.title")}</p> <p className="title-text">{t("setting.system-section.customize-server.title")}</p>
<button className="btn close-btn" onClick={handleCloseBtnClick}> <button className="btn close-btn" onClick={handleCloseButtonClick}>
<Icon.X /> <Icon.X />
</button> </button>
</div> </div>
@ -110,13 +117,20 @@ const UpdateCustomizedProfileDialog: React.FC<Props> = ({ destroy }: Props) => {
<LocaleSelect className="w-full" value={state.locale} onChange={handleLocaleSelectChange} /> <LocaleSelect className="w-full" value={state.locale} onChange={handleLocaleSelectChange} />
<p className="text-sm mb-1 mt-2">Server appearance</p> <p className="text-sm mb-1 mt-2">Server appearance</p>
<AppearanceSelect className="w-full" value={state.appearance} onChange={handleAppearanceSelectChange} /> <AppearanceSelect className="w-full" value={state.appearance} onChange={handleAppearanceSelectChange} />
<div className="mt-4 w-full flex flex-row justify-end items-center space-x-2"> <div className="mt-4 w-full flex flex-row justify-between items-center space-x-2">
<span className="btn-text" onClick={handleCloseBtnClick}> <div className="flex flex-row justify-start items-center">
{t("common.cancel")} <button className="btn-normal" onClick={handleRestoreButtonClick}>
</span> {t("common.restore")}
<span className="btn-primary" onClick={handleSaveBtnClick}> </button>
{t("common.save")} </div>
</span> <div className="flex flex-row justify-end items-center">
<button className="btn-text" onClick={handleCloseButtonClick}>
{t("common.cancel")}
</button>
<button className="btn-primary" onClick={handleSaveButtonClick}>
{t("common.save")}
</button>
</div>
</div> </div>
</div> </div>
</> </>

Loading…
Cancel
Save