|
|
@ -30,13 +30,12 @@ import { MemoEditorContext } from "./types";
|
|
|
|
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
interface Props {
|
|
|
|
className?: string;
|
|
|
|
className?: string;
|
|
|
|
editorClassName?: string;
|
|
|
|
|
|
|
|
cacheKey?: string;
|
|
|
|
cacheKey?: string;
|
|
|
|
memoId?: number;
|
|
|
|
memoName?: string;
|
|
|
|
parentMemoId?: number;
|
|
|
|
parentMemoName?: string;
|
|
|
|
relationList?: MemoRelation[];
|
|
|
|
relationList?: MemoRelation[];
|
|
|
|
autoFocus?: boolean;
|
|
|
|
autoFocus?: boolean;
|
|
|
|
onConfirm?: (memoId: number) => void;
|
|
|
|
onConfirm?: (memoName: string) => void;
|
|
|
|
onEditPrevious?: () => void;
|
|
|
|
onEditPrevious?: () => void;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -50,7 +49,7 @@ interface State {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const MemoEditor = (props: Props) => {
|
|
|
|
const MemoEditor = (props: Props) => {
|
|
|
|
const { className, editorClassName, cacheKey, memoId, parentMemoId, autoFocus, onConfirm } = props;
|
|
|
|
const { className, cacheKey, memoName, parentMemoName, autoFocus, onConfirm } = props;
|
|
|
|
const { i18n } = useTranslation();
|
|
|
|
const { i18n } = useTranslation();
|
|
|
|
const t = useTranslate();
|
|
|
|
const t = useTranslate();
|
|
|
|
const {
|
|
|
|
const {
|
|
|
@ -74,12 +73,9 @@ const MemoEditor = (props: Props) => {
|
|
|
|
const userSetting = userStore.userSetting as UserSetting;
|
|
|
|
const userSetting = userStore.userSetting as UserSetting;
|
|
|
|
const contentCacheKey = `${currentUser.name}-${cacheKey || ""}`;
|
|
|
|
const contentCacheKey = `${currentUser.name}-${cacheKey || ""}`;
|
|
|
|
const [contentCache, setContentCache] = useLocalStorage<string>(contentCacheKey, "");
|
|
|
|
const [contentCache, setContentCache] = useLocalStorage<string>(contentCacheKey, "");
|
|
|
|
const referenceRelations = memoId
|
|
|
|
const referenceRelations = memoName
|
|
|
|
? state.relationList.filter(
|
|
|
|
? state.relationList.filter(
|
|
|
|
(relation) =>
|
|
|
|
(relation) => relation.memo === memoName && relation.relatedMemo !== memoName && relation.type === MemoRelation_Type.REFERENCE,
|
|
|
|
extractMemoIdFromName(relation.memo) === memoId &&
|
|
|
|
|
|
|
|
extractMemoIdFromName(relation.relatedMemo) !== memoId &&
|
|
|
|
|
|
|
|
relation.type === MemoRelation_Type.REFERENCE,
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
: state.relationList.filter((relation) => relation.type === MemoRelation_Type.REFERENCE);
|
|
|
|
: state.relationList.filter((relation) => relation.type === MemoRelation_Type.REFERENCE);
|
|
|
|
|
|
|
|
|
|
|
@ -105,8 +101,8 @@ const MemoEditor = (props: Props) => {
|
|
|
|
}, [userSetting.memoVisibility, systemStatus.disablePublicMemos]);
|
|
|
|
}, [userSetting.memoVisibility, systemStatus.disablePublicMemos]);
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
useEffect(() => {
|
|
|
|
if (memoId) {
|
|
|
|
if (memoName) {
|
|
|
|
memoStore.getOrFetchMemoByName(`${MemoNamePrefix}${memoId}`).then((memo) => {
|
|
|
|
memoStore.getOrFetchMemoByName(memoName).then((memo) => {
|
|
|
|
if (memo) {
|
|
|
|
if (memo) {
|
|
|
|
handleEditorFocus();
|
|
|
|
handleEditorFocus();
|
|
|
|
setState((prevState) => ({
|
|
|
|
setState((prevState) => ({
|
|
|
@ -121,7 +117,7 @@ const MemoEditor = (props: Props) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, [memoId]);
|
|
|
|
}, [memoName]);
|
|
|
|
|
|
|
|
|
|
|
|
const handleCompositionStart = () => {
|
|
|
|
const handleCompositionStart = () => {
|
|
|
|
setState((prevState) => ({
|
|
|
|
setState((prevState) => ({
|
|
|
@ -233,11 +229,11 @@ const MemoEditor = (props: Props) => {
|
|
|
|
const resource = await handleUploadResource(file);
|
|
|
|
const resource = await handleUploadResource(file);
|
|
|
|
if (resource) {
|
|
|
|
if (resource) {
|
|
|
|
uploadedResourceList.push(resource);
|
|
|
|
uploadedResourceList.push(resource);
|
|
|
|
if (memoId) {
|
|
|
|
if (memoName) {
|
|
|
|
await resourceStore.updateResource({
|
|
|
|
await resourceStore.updateResource({
|
|
|
|
resource: Resource.fromPartial({
|
|
|
|
resource: Resource.fromPartial({
|
|
|
|
name: resource.name,
|
|
|
|
name: resource.name,
|
|
|
|
memoId,
|
|
|
|
memoId: extractMemoIdFromName(memoName),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
updateMask: ["memo_id"],
|
|
|
|
updateMask: ["memo_id"],
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -296,8 +292,8 @@ const MemoEditor = (props: Props) => {
|
|
|
|
const content = editorRef.current?.getContent() ?? "";
|
|
|
|
const content = editorRef.current?.getContent() ?? "";
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// Update memo.
|
|
|
|
// Update memo.
|
|
|
|
if (memoId && memoId !== UNKNOWN_ID) {
|
|
|
|
if (memoName) {
|
|
|
|
const prevMemo = await memoStore.getOrFetchMemoByName(`${MemoNamePrefix}${memoId}`);
|
|
|
|
const prevMemo = await memoStore.getOrFetchMemoByName(memoName);
|
|
|
|
if (prevMemo) {
|
|
|
|
if (prevMemo) {
|
|
|
|
const memo = await memoStore.updateMemo(
|
|
|
|
const memo = await memoStore.updateMemo(
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -315,22 +311,21 @@ const MemoEditor = (props: Props) => {
|
|
|
|
name: memo.name,
|
|
|
|
name: memo.name,
|
|
|
|
relations: state.relationList,
|
|
|
|
relations: state.relationList,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
const memoId = extractMemoIdFromName(memo.name);
|
|
|
|
await memoStore.getOrFetchMemoByName(memo.name, { skipCache: true });
|
|
|
|
await memoStore.getOrFetchMemoByName(`${MemoNamePrefix}${memoId}`, { skipCache: true });
|
|
|
|
|
|
|
|
if (onConfirm) {
|
|
|
|
if (onConfirm) {
|
|
|
|
onConfirm(memoId);
|
|
|
|
onConfirm(memo.name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// Create memo or memo comment.
|
|
|
|
// Create memo or memo comment.
|
|
|
|
const request = !parentMemoId
|
|
|
|
const request = !parentMemoName
|
|
|
|
? memoStore.createMemo({
|
|
|
|
? memoStore.createMemo({
|
|
|
|
content,
|
|
|
|
content,
|
|
|
|
visibility: state.memoVisibility,
|
|
|
|
visibility: state.memoVisibility,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
: memoServiceClient
|
|
|
|
: memoServiceClient
|
|
|
|
.createMemoComment({
|
|
|
|
.createMemoComment({
|
|
|
|
name: `${MemoNamePrefix}${parentMemoId}`,
|
|
|
|
name: parentMemoName,
|
|
|
|
comment: {
|
|
|
|
comment: {
|
|
|
|
content,
|
|
|
|
content,
|
|
|
|
visibility: state.memoVisibility,
|
|
|
|
visibility: state.memoVisibility,
|
|
|
@ -346,10 +341,9 @@ const MemoEditor = (props: Props) => {
|
|
|
|
name: memo.name,
|
|
|
|
name: memo.name,
|
|
|
|
relations: state.relationList,
|
|
|
|
relations: state.relationList,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
const memoId = extractMemoIdFromName(memo.name);
|
|
|
|
await memoStore.getOrFetchMemoByName(memo.name, { skipCache: true });
|
|
|
|
await memoStore.getOrFetchMemoByName(`${MemoNamePrefix}${memoId}`, { skipCache: true });
|
|
|
|
|
|
|
|
if (onConfirm) {
|
|
|
|
if (onConfirm) {
|
|
|
|
onConfirm(memoId);
|
|
|
|
onConfirm(memo.name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
editorRef.current?.setContent("");
|
|
|
|
editorRef.current?.setContent("");
|
|
|
@ -378,7 +372,7 @@ const MemoEditor = (props: Props) => {
|
|
|
|
|
|
|
|
|
|
|
|
const editorConfig = useMemo(
|
|
|
|
const editorConfig = useMemo(
|
|
|
|
() => ({
|
|
|
|
() => ({
|
|
|
|
className: editorClassName ?? "",
|
|
|
|
className: "",
|
|
|
|
initialContent: "",
|
|
|
|
initialContent: "",
|
|
|
|
placeholder: t("editor.placeholder"),
|
|
|
|
placeholder: t("editor.placeholder"),
|
|
|
|
onContentChange: handleContentChange,
|
|
|
|
onContentChange: handleContentChange,
|
|
|
@ -399,7 +393,7 @@ const MemoEditor = (props: Props) => {
|
|
|
|
relationList,
|
|
|
|
relationList,
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
},
|
|
|
|
memoId,
|
|
|
|
memoName,
|
|
|
|
}}
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
<div
|
|
|
|