From ae1d9adf657e6276563579c1f33004c4cdcd6481 Mon Sep 17 00:00:00 2001 From: boojack Date: Sat, 20 May 2023 09:39:20 +0800 Subject: [PATCH] fix: initial system locale (#1684) --- server/auth.go | 18 ---------------- web/src/components/Memo.tsx | 5 +---- .../MemoEditor/RelationListView.tsx | 2 +- .../MemoEditor/ResourceListView.tsx | 2 +- web/src/components/Settings/SystemSection.tsx | 4 ++-- web/src/components/UsageHeatMap.tsx | 21 +++++++++---------- web/src/store/module/global.ts | 5 +++-- 7 files changed, 18 insertions(+), 39 deletions(-) diff --git a/server/auth.go b/server/auth.go index 51dab321..f874b7e9 100644 --- a/server/auth.go +++ b/server/auth.go @@ -101,24 +101,6 @@ func (s *Server) registerAuthRoutes(g *echo.Group, secret string) { return echo.NewHTTPError(http.StatusInternalServerError, "Incorrect login credentials, please try again") } if user == nil { - allowSignUpSetting, err := s.Store.FindSystemSetting(ctx, &api.SystemSettingFind{ - Name: api.SystemSettingAllowSignUpName, - }) - if err != nil && common.ErrorCode(err) != common.NotFound { - return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find system setting").SetInternal(err) - } - - allowSignUpSettingValue := false - if allowSignUpSetting != nil { - err = json.Unmarshal([]byte(allowSignUpSetting.Value), &allowSignUpSettingValue) - if err != nil { - return echo.NewHTTPError(http.StatusInternalServerError, "Failed to unmarshal system setting allow signup").SetInternal(err) - } - } - if !allowSignUpSettingValue { - return echo.NewHTTPError(http.StatusUnauthorized, "signup is disabled").SetInternal(err) - } - userCreate := &api.UserCreate{ Username: userInfo.Identifier, // The new signup user should be normal user by default. diff --git a/web/src/components/Memo.tsx b/web/src/components/Memo.tsx index a6d7f7f6..ce0da25b 100644 --- a/web/src/components/Memo.tsx +++ b/web/src/components/Memo.tsx @@ -210,10 +210,7 @@ const Memo: React.FC = (props: Props) => { return ( <> -
0 && "pinned"} ${memo.pinned ? "pinned" : ""}`} - ref={memoContainerRef} - > +
diff --git a/web/src/components/MemoEditor/RelationListView.tsx b/web/src/components/MemoEditor/RelationListView.tsx index 03ec5948..37b8be0c 100644 --- a/web/src/components/MemoEditor/RelationListView.tsx +++ b/web/src/components/MemoEditor/RelationListView.tsx @@ -41,7 +41,7 @@ const RelationListView = () => { return (
diff --git a/web/src/components/MemoEditor/ResourceListView.tsx b/web/src/components/MemoEditor/ResourceListView.tsx index 6bc9afa9..af79e839 100644 --- a/web/src/components/MemoEditor/ResourceListView.tsx +++ b/web/src/components/MemoEditor/ResourceListView.tsx @@ -18,7 +18,7 @@ const ResourceListView = () => { return (
{resource.filename} diff --git a/web/src/components/Settings/SystemSection.tsx b/web/src/components/Settings/SystemSection.tsx index afb2a4ab..e1200aa6 100644 --- a/web/src/components/Settings/SystemSection.tsx +++ b/web/src/components/Settings/SystemSection.tsx @@ -232,7 +232,7 @@ const SystemSection = () => {
- {t("setting.system-section.max-upload-size")} + {t("setting.system-section.max-upload-size")}
{
- {t("setting.system-section.openai-api-key")} + {t("setting.system-section.openai-api-key")}
diff --git a/web/src/components/UsageHeatMap.tsx b/web/src/components/UsageHeatMap.tsx index 947065e8..7ad9164e 100644 --- a/web/src/components/UsageHeatMap.tsx +++ b/web/src/components/UsageHeatMap.tsx @@ -44,16 +44,19 @@ const UsageHeatMap = () => { const [allStat, setAllStat] = useState(getInitialUsageStat(usedDaysAmount, beginDayTimestamp)); const [currentStat, setCurrentStat] = useState(null); const containerElRef = useRef(null); + const currentUserId = userStore.getCurrentUserId(); useEffect(() => { - if (!userStore.state.user) { - return; - } - setCreatedDays(Math.ceil((Date.now() - getTimeStampByDate(userStore.state.user.createdTs)) / 1000 / 3600 / 24)); - }, [userStore.state.user]); + userStore.getUserById(currentUserId).then((user) => { + if (!user) { + return; + } + setCreatedDays(Math.ceil((Date.now() - getTimeStampByDate(user.createdTs)) / 1000 / 3600 / 24)); + }); + }, [currentUserId]); useEffect(() => { - getMemoStats(userStore.getCurrentUserId()) + getMemoStats(currentUserId) .then(({ data: { data } }) => { setMemoAmount(data.length); const newStat: DailyUsageStat[] = getInitialUsageStat(usedDaysAmount, beginDayTimestamp); @@ -72,11 +75,7 @@ const UsageHeatMap = () => { .catch((error) => { console.error(error); }); - - return () => { - handleUsageStatItemMouseLeave(); - }; - }, [memos.length]); + }, [memos.length, currentUserId]); const handleUsageStatItemMouseEnter = useCallback((event: React.MouseEvent, item: DailyUsageStat) => { const tempDiv = document.createElement("div"); diff --git a/web/src/store/module/global.ts b/web/src/store/module/global.ts index 50b62ca2..38c4866f 100644 --- a/web/src/store/module/global.ts +++ b/web/src/store/module/global.ts @@ -49,8 +49,9 @@ export const initialGlobalState = async () => { externalUrl: "", }, }; - defaultGlobalState.locale = storageLocale || findNearestLanguageMatch(i18n.language); - defaultGlobalState.appearance = customizedProfile.appearance; + defaultGlobalState.locale = + storageLocale || defaultGlobalState.systemStatus.customizedProfile.locale || findNearestLanguageMatch(i18n.language); + defaultGlobalState.appearance = defaultGlobalState.systemStatus.customizedProfile.appearance; } store.dispatch(setGlobalState(defaultGlobalState)); };