diff --git a/web/src/App.tsx b/web/src/App.tsx index e67a278a..6129102c 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -7,6 +7,7 @@ import * as storage from "./helpers/storage"; function App() { const { setLocale } = useI18n(); + const user = useAppSelector((state) => state.user.user); const global = useAppSelector((state) => state.global); const pathname = useAppSelector((state) => state.location.pathname); const [isLoading, setLoading] = useState(true); @@ -21,12 +22,18 @@ function App() { }); }, []); + useEffect(() => { + if (user?.setting.locale) { + globalService.setLocale(user.setting.locale); + } + }, [user?.setting.locale]); + useEffect(() => { setLocale(global.locale); storage.set({ locale: global.locale, }); - }, [global]); + }, [global.locale]); return <>{isLoading ? null : appRouterSwitch(pathname)}; } diff --git a/web/src/components/Memo.tsx b/web/src/components/Memo.tsx index 8e1d6d99..92c4f9f3 100644 --- a/web/src/components/Memo.tsx +++ b/web/src/components/Memo.tsx @@ -45,15 +45,16 @@ const Memo: React.FC = (props: Props) => { }); const [createdAtStr, setCreatedAtStr] = useState(getFormatedMemoCreatedAtStr(memo.createdTs, locale)); const memoContainerRef = useRef(null); + const memoContentContainerRef = useRef(null); const imageUrls = Array.from(memo.content.match(IMAGE_URL_REG) ?? []).map((s) => s.replace(IMAGE_URL_REG, "$1")); const isVisitorMode = userService.isVisitorMode(); useEffect(() => { - if (!memoContainerRef) { + if (!memoContentContainerRef) { return; } - if (Number(memoContainerRef.current?.clientHeight) > MAX_MEMO_CONTAINER_HEIGHT) { + if (Number(memoContentContainerRef.current?.clientHeight) > MAX_MEMO_CONTAINER_HEIGHT) { setState({ ...state, expandButtonStatus: 0, @@ -143,7 +144,7 @@ const Memo: React.FC = (props: Props) => { } const status = targetEl.dataset?.value; - const todoElementList = [...(memoContainerRef.current?.querySelectorAll(`span.todo-block[data-value=${status}]`) ?? [])]; + const todoElementList = [...(memoContentContainerRef.current?.querySelectorAll(`span.todo-block[data-value=${status}]`) ?? [])]; for (const element of todoElementList) { if (element === targetEl) { const index = indexOf(todoElementList, element); @@ -172,13 +173,18 @@ const Memo: React.FC = (props: Props) => { }; const handleExpandBtnClick = () => { + const expandButtonStatus = Boolean(!state.expandButtonStatus); + if (!expandButtonStatus) { + memoContainerRef.current?.scrollIntoView(); + } + setState({ - expandButtonStatus: Number(Boolean(!state.expandButtonStatus)) as ExpandButtonStatus, + expandButtonStatus: Number(expandButtonStatus) as ExpandButtonStatus, }); }; return ( -
+
{createdAtStr} @@ -220,7 +226,7 @@ const Memo: React.FC = (props: Props) => {
= () => { + const { t } = useI18n(); const query = useAppSelector((state) => state.location.query); - const memos = useAppSelector((state) => state.memo.memos); - const [isFetching, setFetchStatus] = useState(true); + const { memos, isFetching } = useAppSelector((state) => state.memo); const wrapperElement = useRef(null); const { tag: tagQuery, duration, type: memoType, text: textQuery, shortcutId } = query ?? {}; @@ -82,7 +84,7 @@ const MemoList: React.FC = () => { memoService .fetchAllMemos() .then(() => { - setFetchStatus(false); + // do nth }) .catch((error) => { console.error(error); @@ -91,19 +93,26 @@ const MemoList: React.FC = () => { }, []); useEffect(() => { - wrapperElement.current?.scrollTo({ top: 0 }); + wrapperElement.current?.scrollTo({ + top: 0, + }); }, [query]); return (
+ +
+

{t("memo-list.fetching-data")}

+
+
{sortedMemos.map((memo) => ( ))} -
-

- {isFetching ? "Fetching data..." : sortedMemos.length === 0 ? "No memos 🌃" : showMemoFilter ? "" : "All memos are ready 🎉"} -

-
+ +
+

{sortedMemos.length === 0 ? "no memos 🌃" : showMemoFilter ? "" : "all memos are ready 🎉"}

+
+
); }; diff --git a/web/src/components/MemosHeader.tsx b/web/src/components/MemosHeader.tsx index 62f3c512..9198f7f4 100644 --- a/web/src/components/MemosHeader.tsx +++ b/web/src/components/MemosHeader.tsx @@ -29,7 +29,7 @@ const MemosHeader: React.FC = () => { const handleTitleTextClick = useCallback(() => { const now = Date.now(); - if (now - prevRequestTimestamp > 10 * 1000) { + if (now - prevRequestTimestamp > 1 * 1000) { prevRequestTimestamp = now; memoService.fetchAllMemos().catch(() => { // do nth diff --git a/web/src/components/Settings/PreferencesSection.tsx b/web/src/components/Settings/PreferencesSection.tsx index d4ed00ab..c747098c 100644 --- a/web/src/components/Settings/PreferencesSection.tsx +++ b/web/src/components/Settings/PreferencesSection.tsx @@ -35,8 +35,8 @@ const PreferencesSection: React.FC = () => { const { setting } = useAppSelector((state) => state.user.user as User); const handleLocaleChanged = async (value: string) => { - globalService.setLocale(value as Locale); await userService.upsertUserSetting("locale", value); + globalService.setLocale(value as Locale); }; const handleDefaultMemoVisibilityChanged = async (value: string) => { @@ -49,16 +49,17 @@ const PreferencesSection: React.FC = () => { return (
-

{t("common.language")}

+

{t("common.basic")}

{t("setting.preference")}