diff --git a/web/src/components/MemoEditor/index.tsx b/web/src/components/MemoEditor/index.tsx index f3d572ab..dbc7ed16 100644 --- a/web/src/components/MemoEditor/index.tsx +++ b/web/src/components/MemoEditor/index.tsx @@ -37,6 +37,7 @@ interface Props { relationList?: MemoRelation[]; autoFocus?: boolean; onConfirm?: (memoId: number) => void; + onEditPrevious?: () => void; } interface State { @@ -144,7 +145,7 @@ const MemoEditor = (props: Props) => { const isMetaKey = event.ctrlKey || event.metaKey; if (isMetaKey) { if (event.key === "Enter") { - handleSaveBtnClick(); + void handleSaveBtnClick(); return; } @@ -161,6 +162,12 @@ const MemoEditor = (props: Props) => { } return; } + + if (!!props.onEditPrevious && event.key === "ArrowDown" && !state.isComposing && editorRef.current.getContent() === "") { + event.preventDefault(); + props.onEditPrevious(); + return; + } }; const handleMemoVisibilityChange = (visibility: Visibility) => { diff --git a/web/src/pages/Home.tsx b/web/src/pages/Home.tsx index c7ad5983..74bb50e7 100644 --- a/web/src/pages/Home.tsx +++ b/web/src/pages/Home.tsx @@ -1,11 +1,12 @@ import { Button } from "@mui/joy"; import classNames from "classnames"; -import { useEffect, useRef, useState } from "react"; +import { useCallback, useEffect, useRef, useState } from "react"; import Empty from "@/components/Empty"; import HomeSidebar from "@/components/HomeSidebar"; import HomeSidebarDrawer from "@/components/HomeSidebarDrawer"; import Icon from "@/components/Icon"; import MemoEditor from "@/components/MemoEditor"; +import showMemoEditorDialog from "@/components/MemoEditor/MemoEditorDialog"; import MemoFilter from "@/components/MemoFilter"; import MemoView from "@/components/MemoView"; import MobileHeader from "@/components/MobileHeader"; @@ -14,7 +15,7 @@ import { getTimeStampByDate } from "@/helpers/datetime"; import useCurrentUser from "@/hooks/useCurrentUser"; import useFilterWithUrlParams from "@/hooks/useFilterWithUrlParams"; import useResponsiveWidth from "@/hooks/useResponsiveWidth"; -import { useMemoList, useMemoStore } from "@/store/v1"; +import { extractMemoIdFromName, useMemoList, useMemoStore } from "@/store/v1"; import { RowStatus } from "@/types/proto/api/v2/common"; import { useTranslate } from "@/utils/i18n"; @@ -60,6 +61,14 @@ const Home = () => { nextPageTokenRef.current = data.nextPageToken; }; + const handleEditPrevious = useCallback(() => { + const lastMemo = memoList.value[memoList.value.length - 1]; + showMemoEditorDialog({ + memoId: extractMemoIdFromName(lastMemo.name), + cacheKey: `${lastMemo.name}-${lastMemo.updateTime}`, + }); + }, [memoList]); + return (
{!md && ( @@ -69,7 +78,7 @@ const Home = () => { )}
- +
{sortedMemos.map((memo) => (