From bc2d2d0cde1cc449cb99f0926902720f5188f231 Mon Sep 17 00:00:00 2001 From: Steven Date: Fri, 26 Jan 2024 22:51:57 +0800 Subject: [PATCH] feat: support set embedded content in UI --- .../components/CreateMemoRelationDialog.tsx | 21 +-- .../EmbeddedContent/EmbeddedMemo.tsx | 24 ++- .../ActionButton/AddMemoRelationButton.tsx | 68 +++++++++ web/src/components/MemoEditor/index.tsx | 138 +++++++++--------- .../components/MemoEditor/types/context.ts | 14 ++ web/src/components/MemoEditor/types/index.ts | 1 + 6 files changed, 182 insertions(+), 84 deletions(-) create mode 100644 web/src/components/MemoEditor/ActionButton/AddMemoRelationButton.tsx create mode 100644 web/src/components/MemoEditor/types/context.ts create mode 100644 web/src/components/MemoEditor/types/index.ts diff --git a/web/src/components/CreateMemoRelationDialog.tsx b/web/src/components/CreateMemoRelationDialog.tsx index ecea9ba9..137065f1 100644 --- a/web/src/components/CreateMemoRelationDialog.tsx +++ b/web/src/components/CreateMemoRelationDialog.tsx @@ -1,4 +1,4 @@ -import { Autocomplete, AutocompleteOption, Button, Chip, IconButton } from "@mui/joy"; +import { Autocomplete, AutocompleteOption, Button, Checkbox, Chip, IconButton } from "@mui/joy"; import React, { useState } from "react"; import { toast } from "react-hot-toast"; import useDebounce from "react-use/lib/useDebounce"; @@ -11,18 +11,18 @@ import { generateDialog } from "./Dialog"; import Icon from "./Icon"; interface Props extends DialogProps { - onCancel?: () => void; - onConfirm?: (memoIdList: number[]) => void; + onConfirm: (memoIdList: number[], embedded?: boolean) => void; } const CreateMemoRelationDialog: React.FC = (props: Props) => { - const { destroy, onCancel, onConfirm } = props; + const { destroy, onConfirm } = props; const t = useTranslate(); const user = useCurrentUser(); const [searchText, setSearchText] = useState(""); const [isFetching, setIsFetching] = useState(true); const [fetchedMemos, setFetchedMemos] = useState([]); const [selectedMemos, setSelectedMemos] = useState([]); + const [embedded, setEmbedded] = useState(false); const filteredMemos = fetchedMemos.filter((memo) => !selectedMemos.includes(memo)); useDebounce( @@ -73,16 +73,14 @@ const CreateMemoRelationDialog: React.FC = (props: Props) => { }; const handleCloseDialog = () => { - if (onCancel) { - onCancel(); - } destroy(); }; const handleConfirmBtnClick = async () => { - if (onConfirm) { - onConfirm(selectedMemos.map((memo) => memo.id)); - } + onConfirm( + selectedMemos.map((memo) => memo.id), + embedded + ); destroy(); }; @@ -133,6 +131,9 @@ const CreateMemoRelationDialog: React.FC = (props: Props) => { } onChange={(_, value) => setSelectedMemos(value)} /> +
+ setEmbedded(e.target.checked)} /> +
+
- -
-
e.stopPropagation()}> - -
-
- -
-
- + ); }; diff --git a/web/src/components/MemoEditor/types/context.ts b/web/src/components/MemoEditor/types/context.ts new file mode 100644 index 00000000..7bd2fa0e --- /dev/null +++ b/web/src/components/MemoEditor/types/context.ts @@ -0,0 +1,14 @@ +import { createContext } from "react"; +import { MemoRelation } from "@/types/proto/api/v2/memo_relation_service"; + +interface Context { + relationList: MemoRelation[]; + setRelationList: (relationList: MemoRelation[]) => void; + // memoId is the id of the memo that is being edited. + memoId?: number; +} + +export const MemoEditorContext = createContext({ + relationList: [], + setRelationList: () => {}, +}); diff --git a/web/src/components/MemoEditor/types/index.ts b/web/src/components/MemoEditor/types/index.ts new file mode 100644 index 00000000..2edd280c --- /dev/null +++ b/web/src/components/MemoEditor/types/index.ts @@ -0,0 +1 @@ +export * from "./context";