chore: remove mark memo (#476)

This commit is contained in:
boojack 2022-11-15 21:22:08 +08:00 committed by GitHub
parent de2eff474c
commit 66f9bc48bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 4 additions and 69 deletions

View File

@ -5,7 +5,6 @@ import { memo, useEffect, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import { useNavigate } from "react-router-dom";
import "dayjs/locale/zh";
import { UNKNOWN_ID } from "../helpers/consts";
import { editorStateService, locationService, memoService, userService } from "../services";
import Icon from "./Icon";
import toastHelper from "./Toast";
@ -71,10 +70,6 @@ const Memo: React.FC<Props> = (props: Props) => {
}
};
const handleMarkMemoClick = () => {
editorStateService.setMarkMemoWithId(memo.id);
};
const handleEditMemoClick = () => {
editorStateService.setEditMemoWithId(memo.id);
};
@ -102,17 +97,7 @@ const Memo: React.FC<Props> = (props: Props) => {
const handleMemoContentClick = async (e: React.MouseEvent) => {
const targetEl = e.target as HTMLElement;
if (targetEl.className === "memo-link-text") {
const memoId = targetEl.dataset?.value;
const memoTemp = await memoService.getMemoById(Number(memoId) ?? UNKNOWN_ID);
if (memoTemp) {
navigate(`/m/${memoTemp.id}`);
} else {
toastHelper.error(t("message.memo-not-found"));
targetEl.classList.remove("memo-link-text");
}
} else if (targetEl.className === "tag-span") {
if (targetEl.className === "tag-span") {
const tagName = targetEl.innerText.slice(1);
const currTagQuery = locationService.getState().query?.tag;
if (currTagQuery === tagName) {
@ -231,9 +216,6 @@ const Memo: React.FC<Props> = (props: Props) => {
<span className="tip-text">{t("common.share")}</span>
</div>
</div>
<span className="btn" onClick={handleMarkMemoClick}>
{t("common.mark")}
</span>
<span className="btn" onClick={handleCopyContent}>
{t("memo.copy")}
</span>

View File

@ -73,15 +73,6 @@ const MemoEditor = () => {
}
}, []);
useEffect(() => {
if (editorState.markMemoId && editorState.markMemoId !== UNKNOWN_ID) {
const editorCurrentValue = editorRef.current?.getContent();
const memoLinkText = `${editorCurrentValue ? "\n" : ""}Mark: @[MEMO](${editorState.markMemoId})`;
editorRef.current?.insertText(memoLinkText);
editorStateService.clearMarkMemo();
}
}, [editorState.markMemoId]);
useEffect(() => {
if (editorState.editMemoId) {
memoService.getMemoById(editorState.editMemoId ?? UNKNOWN_ID).then((memo) => {

View File

@ -1,18 +0,0 @@
import { escape } from "lodash-es";
export const MARK_REG = /@\[(.+?)\]\((\S+?)\)/;
const renderer = (rawStr: string): string => {
const matchResult = rawStr.match(MARK_REG);
if (!matchResult) {
return rawStr;
}
return `<span class='memo-link-text' data-value='${escape(matchResult[2])}'>${escape(matchResult[1])}</span>`;
};
export default {
name: "mark",
regex: MARK_REG,
renderer,
};

View File

@ -7,7 +7,6 @@ import Paragraph from "./Paragraph";
import Tag from "./Tag";
import Image from "./Image";
import Link from "./Link";
import Mark from "./Mark";
import Bold from "./Bold";
import Emphasis from "./Emphasis";
import PlainLink from "./PlainLink";
@ -23,10 +22,9 @@ export { DONE_LIST_REG } from "./DoneList";
export { TAG_REG } from "./Tag";
export { IMAGE_REG } from "./Image";
export { LINK_REG } from "./Link";
export { MARK_REG } from "./Mark";
export { TABLE_REG } from "./Table";
// The order determines the order of execution.
export const blockElementParserList = [Table, CodeBlock, Blockquote, TodoList, DoneList, OrderedList, UnorderedList, Paragraph];
export const inlineElementParserList = [Image, Mark, BoldEmphasis, Bold, Emphasis, Link, InlineCode, PlainLink, Tag, PlainText];
export const inlineElementParserList = [Image, BoldEmphasis, Bold, Emphasis, Link, InlineCode, PlainLink, Tag, PlainText];
export const parserList = [...blockElementParserList, ...inlineElementParserList];

View File

@ -22,7 +22,6 @@
"delete": "Delete",
"null": "Null",
"share": "Share",
"mark": "Mark",
"archive": "Archive",
"basic": "Basic",
"admin": "Admin",

View File

@ -22,7 +22,6 @@
"delete": "Xóa",
"null": "Null",
"share": "Chia sẻ",
"mark": "Đánh dấu",
"archive": "Lưu trữ",
"basic": "Cơ bản",
"admin": "Admin",

View File

@ -22,7 +22,6 @@
"delete": "删除",
"null": "空",
"share": "分享",
"mark": "标注",
"archive": "归档",
"basic": "基础",
"admin": "管理员",

View File

@ -1,5 +1,5 @@
import store from "../store";
import { setEditMemoId, setMarkMemoId, setMemoVisibility } from "../store/modules/editor";
import { setEditMemoId, setMemoVisibility } from "../store/modules/editor";
const editorStateService = {
getState: () => {
@ -14,14 +14,6 @@ const editorStateService = {
store.dispatch(setEditMemoId());
},
setMarkMemoWithId: (markMemoId: MemoId) => {
store.dispatch(setMarkMemoId(markMemoId));
},
clearMarkMemo: () => {
store.dispatch(setMarkMemoId());
},
setMemoVisibility: (memoVisibility: Visibility) => {
store.dispatch(setMemoVisibility(memoVisibility));
},

View File

@ -1,7 +1,6 @@
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
interface State {
markMemoId?: MemoId;
editMemoId?: MemoId;
memoVisibility: Visibility;
}
@ -10,12 +9,6 @@ const editorSlice = createSlice({
name: "editor",
initialState: {} as State,
reducers: {
setMarkMemoId: (state, action: PayloadAction<Option<MemoId>>) => {
return {
...state,
markMemoId: action.payload,
};
},
setEditMemoId: (state, action: PayloadAction<Option<MemoId>>) => {
return {
...state,
@ -31,6 +24,6 @@ const editorSlice = createSlice({
},
});
export const { setEditMemoId, setMarkMemoId, setMemoVisibility } = editorSlice.actions;
export const { setEditMemoId, setMemoVisibility } = editorSlice.actions;
export default editorSlice.reducer;