mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
fix: embed memos callback
This commit is contained in:
@ -12,7 +12,7 @@ import { generateDialog } from "./Dialog";
|
|||||||
import Icon from "./Icon";
|
import Icon from "./Icon";
|
||||||
|
|
||||||
interface Props extends DialogProps {
|
interface Props extends DialogProps {
|
||||||
onConfirm: (memoIdList: number[], embedded?: boolean) => void;
|
onConfirm: (memos: Memo[], embedded?: boolean) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CreateMemoRelationDialog: React.FC<Props> = (props: Props) => {
|
const CreateMemoRelationDialog: React.FC<Props> = (props: Props) => {
|
||||||
@ -78,10 +78,7 @@ const CreateMemoRelationDialog: React.FC<Props> = (props: Props) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleConfirmBtnClick = async () => {
|
const handleConfirmBtnClick = async () => {
|
||||||
onConfirm(
|
onConfirm(selectedMemos, embedded);
|
||||||
selectedMemos.map((memo) => memo.id),
|
|
||||||
embedded,
|
|
||||||
);
|
|
||||||
destroy();
|
destroy();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@ import toast from "react-hot-toast";
|
|||||||
import showCreateMemoRelationDialog from "@/components/CreateMemoRelationDialog";
|
import showCreateMemoRelationDialog from "@/components/CreateMemoRelationDialog";
|
||||||
import Icon from "@/components/Icon";
|
import Icon from "@/components/Icon";
|
||||||
import { UNKNOWN_ID } from "@/helpers/consts";
|
import { UNKNOWN_ID } from "@/helpers/consts";
|
||||||
import { useMemoStore } from "@/store/v1";
|
|
||||||
import { MemoRelation_Type } from "@/types/proto/api/v2/memo_relation_service";
|
import { MemoRelation_Type } from "@/types/proto/api/v2/memo_relation_service";
|
||||||
import { EditorRefActions } from "../Editor";
|
import { EditorRefActions } from "../Editor";
|
||||||
import { MemoEditorContext } from "../types";
|
import { MemoEditorContext } from "../types";
|
||||||
@ -16,12 +15,11 @@ interface Props {
|
|||||||
|
|
||||||
const AddMemoRelationButton = (props: Props) => {
|
const AddMemoRelationButton = (props: Props) => {
|
||||||
const { editorRef } = props;
|
const { editorRef } = props;
|
||||||
const memoStore = useMemoStore();
|
|
||||||
const context = useContext(MemoEditorContext);
|
const context = useContext(MemoEditorContext);
|
||||||
|
|
||||||
const handleAddMemoRelationBtnClick = () => {
|
const handleAddMemoRelationBtnClick = () => {
|
||||||
showCreateMemoRelationDialog({
|
showCreateMemoRelationDialog({
|
||||||
onConfirm: (memoIdList, embedded) => {
|
onConfirm: (memos, embedded) => {
|
||||||
// If embedded mode is enabled, embed the memo instead of creating a relation.
|
// If embedded mode is enabled, embed the memo instead of creating a relation.
|
||||||
if (embedded) {
|
if (embedded) {
|
||||||
if (!editorRef.current) {
|
if (!editorRef.current) {
|
||||||
@ -34,8 +32,7 @@ const AddMemoRelationButton = (props: Props) => {
|
|||||||
if (prevValue !== "" && !prevValue.endsWith("\n")) {
|
if (prevValue !== "" && !prevValue.endsWith("\n")) {
|
||||||
editorRef.current.insertText("\n");
|
editorRef.current.insertText("\n");
|
||||||
}
|
}
|
||||||
for (const memoId of memoIdList) {
|
for (const memo of memos) {
|
||||||
const memo = memoStore.getMemoById(memoId);
|
|
||||||
editorRef.current.insertText(`![[memos/${memo.name}]]\n`);
|
editorRef.current.insertText(`![[memos/${memo.name}]]\n`);
|
||||||
}
|
}
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@ -48,7 +45,7 @@ const AddMemoRelationButton = (props: Props) => {
|
|||||||
context.setRelationList(
|
context.setRelationList(
|
||||||
uniqBy(
|
uniqBy(
|
||||||
[
|
[
|
||||||
...memoIdList.map((id) => ({ memoId: context.memoId || UNKNOWN_ID, relatedMemoId: id, type: MemoRelation_Type.REFERENCE })),
|
...memos.map((memo) => ({ memoId: context.memoId || UNKNOWN_ID, relatedMemoId: memo.id, type: MemoRelation_Type.REFERENCE })),
|
||||||
...context.relationList,
|
...context.relationList,
|
||||||
].filter((relation) => relation.relatedMemoId !== (context.memoId || UNKNOWN_ID)),
|
].filter((relation) => relation.relatedMemoId !== (context.memoId || UNKNOWN_ID)),
|
||||||
"relatedMemoId",
|
"relatedMemoId",
|
||||||
|
Reference in New Issue
Block a user