From 87f8f5ff646680075cbada3a96faf9f0eea694e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E4=B8=80=E4=BA=8C?= Date: Fri, 25 Jun 2021 22:16:05 +0800 Subject: [PATCH] fix: userName in workspace is not editable --- localization/locales/en/translation.json | 4 +++- localization/locales/zh_CN/translation.json | 6 +++++- src/pages/AddWorkspace/useForm.ts | 12 ------------ src/pages/EditWorkspace/index.tsx | 13 +++++++++++-- src/services/auth/index.ts | 2 +- src/services/wikiGitWorkspace/error.ts | 11 +++++++++++ src/services/wikiGitWorkspace/index.ts | 6 ++---- 7 files changed, 33 insertions(+), 21 deletions(-) diff --git a/localization/locales/en/translation.json b/localization/locales/en/translation.json index 2e02615a..d77070ae 100644 --- a/localization/locales/en/translation.json +++ b/localization/locales/en/translation.json @@ -105,7 +105,9 @@ "GitEmailDescription": "Email used for Git commit, and is used to count daily activities on Github and other online git services", "GitUserNameDescription": "The account name used to log in to Git. Not the nickname", "LogoutToGetStorageServiceToken": "Log in to the online storage service to obtain latest credentials", - "AddWorkspace": "Add Workspace" + "AddWorkspace": "Add Workspace", + "WorkspaceUserName": "Workspace User Name", + "WorkspaceUserNameDetail": "The editor name used in the Wiki will be fill in the creator field when the Tiddler is created or edited. The editor name set in the workspace will override the global default editor name assigned in the preferences. This allows you to create Tiddlers with different identities in the same Wiki, with multiple workspace configed with different user name." }, "EditWorkspace": { "Path": "Wiki Path", diff --git a/localization/locales/zh_CN/translation.json b/localization/locales/zh_CN/translation.json index 593526ef..e1b46504 100644 --- a/localization/locales/zh_CN/translation.json +++ b/localization/locales/zh_CN/translation.json @@ -131,6 +131,8 @@ "WorkspaceUpdated": "工作区更新完毕,正在启动Wiki", "StartLinkingSubWikiToMainWiki": "开始链接子Wiki到父Wiki", "AddFileSystemPath": "正在为子Wiki添加FileSystemPaths", + "WorkspaceUserName": "工作区编辑者名", + "WorkspaceUserNameDetail": "在 Wiki 中使用的编辑者名,将在创建或编辑 Tiddler 时填入 creator 字段。工作区内设置的编辑者名,将覆盖设置里配的全局的默认编辑者名。这方便你通过创建多个配了不同编辑者名的工作区,在同一个 Wiki 里用不同的身份创建 Tiddler。", "TagName": "标签名", "TagNameHelp": "加上此标签的笔记将会自动被放入这个子知识库内(可先不填,之后右键点击这个工作区的图标选择编辑工作区修改)", "NoGitInfoAlert": "你未选择在线Git仓库地址,或未成功登录在线Git存储服务账号(可能被墙)。点击创建按钮将创建一个不会自动同步到Github的本地仓库,请注意。" @@ -305,7 +307,9 @@ "DoubleWikiInstanceError": "重复启动维基错误", "DoubleWikiInstanceErrorDescription": "E-4 你启动了同一个Wiki两次,这可能是程序bug导致的。", "InsertMenuAfterSubMenuIndexError": "插入目录模板到现有目录后错误", - "InsertMenuAfterSubMenuIndexErrorDescription": "E-5 你尝试插入目录,且 afterSubMenu \"{afterSubMenu}\" 在目录 menuID \"{menuID}\" 内,但我们无法在目录 \"{menu}\" 里找到它,请用正确的 menuID 指定一个目录。" + "InsertMenuAfterSubMenuIndexErrorDescription": "E-5 你尝试插入目录,且 afterSubMenu \"{afterSubMenu}\" 在目录 menuID \"{menuID}\" 内,但我们无法在目录 \"{menu}\" 里找到它,请用正确的 menuID 指定一个目录。", + "InitWikiGitSyncedWikiNoGitUserInfoError": "笔记仓库初始化失败因为没有提供Git信息错误", + "InitWikiGitSyncedWikiNoGitUserInfoErrorDescription": "E-3 初始化同步到云端的笔记仓库需要你选择一个云端的 git 仓库地址,还有提供相应云服务的认证凭证,然而目前没有获得这些信息。" }, "Loading": "加载中", "Yes": "是的", diff --git a/src/pages/AddWorkspace/useForm.ts b/src/pages/AddWorkspace/useForm.ts index 2e01da70..b2e03382 100644 --- a/src/pages/AddWorkspace/useForm.ts +++ b/src/pages/AddWorkspace/useForm.ts @@ -45,16 +45,6 @@ export function useWikiWorkspaceForm(options?: { fromExisted: boolean }) { const [storageProvider, storageProviderSetter] = useState(SupportedStorageServices.local); const gitUserInfo = useStorageServiceUserInfoObservable(storageProvider); - /** - * Update tiddlywiki's editor user name when first time creating new workspace - */ - const [userName, userNameSetter] = usePromiseValueAndSetter( - async () => await window.service.auth.get('userName'), - async (newUserName) => { - if (newUserName !== undefined) await window.service.auth.set('userName', newUserName); - }, - ); - /** * For sub-wiki, we need to link it to a main wiki's folder, so all wiki contents can be loaded together. */ @@ -123,8 +113,6 @@ export function useWikiWorkspaceForm(options?: { fromExisted: boolean }) { storageProviderSetter, wikiPort, wikiPortSetter, - userName, - userNameSetter, mainWikiToLink, mainWikiToLinkSetter, tagName, diff --git a/src/pages/EditWorkspace/index.tsx b/src/pages/EditWorkspace/index.tsx index 3d192455..3c3788e1 100644 --- a/src/pages/EditWorkspace/index.tsx +++ b/src/pages/EditWorkspace/index.tsx @@ -139,6 +139,8 @@ export default function EditWorkspace(): JSX.Element { isSubWiki, name, port, + order, + userName, tagName, transparentBackground, picturePath, @@ -146,7 +148,7 @@ export default function EditWorkspace(): JSX.Element { disableAudio, disableNotifications, homeUrl, - } = ((workspace ?? {}) as unknown) as IWorkspace; + } = (workspace ?? {}) as unknown as IWorkspace; const fileSystemPaths = usePromiseValue( async () => (mainWikiToLink ? await window.service.wiki.getSubWikiPluginContent(mainWikiToLink) : []), [], @@ -163,7 +165,7 @@ export default function EditWorkspace(): JSX.Element {
- {t('WorkspaceSelector.EditWorkspace')} {String(workspace.order ?? 1)} {workspace.name} + {t('WorkspaceSelector.EditWorkspace')} {String(order ?? 1)} {name} @@ -175,6 +177,13 @@ export default function EditWorkspace(): JSX.Element { value={name} onChange={(event) => workspaceSetter({ ...workspace, name: event.target.value })} /> + workspaceSetter({ ...workspace, userName: event.target.value })} + label={t('AddWorkspace.WorkspaceUserName')} + value={userName} + /> {!isSubWiki && (