From 66f9bc48bb765fb51361a329a97f6158998d9c59 Mon Sep 17 00:00:00 2001 From: boojack Date: Tue, 15 Nov 2022 21:22:08 +0800 Subject: [PATCH] chore: remove mark memo (#476) --- web/src/components/Memo.tsx | 20 +------------------- web/src/components/MemoEditor.tsx | 9 --------- web/src/labs/marked/parser/Mark.ts | 18 ------------------ web/src/labs/marked/parser/index.ts | 4 +--- web/src/locales/en.json | 1 - web/src/locales/vi.json | 1 - web/src/locales/zh.json | 1 - web/src/services/editorStateService.ts | 10 +--------- web/src/store/modules/editor.ts | 9 +-------- 9 files changed, 4 insertions(+), 69 deletions(-) delete mode 100644 web/src/labs/marked/parser/Mark.ts diff --git a/web/src/components/Memo.tsx b/web/src/components/Memo.tsx index 969142d6..25f05bc1 100644 --- a/web/src/components/Memo.tsx +++ b/web/src/components/Memo.tsx @@ -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) => { } }; - const handleMarkMemoClick = () => { - editorStateService.setMarkMemoWithId(memo.id); - }; - const handleEditMemoClick = () => { editorStateService.setEditMemoWithId(memo.id); }; @@ -102,17 +97,7 @@ const Memo: React.FC = (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) => { {t("common.share")} - - {t("common.mark")} - {t("memo.copy")} diff --git a/web/src/components/MemoEditor.tsx b/web/src/components/MemoEditor.tsx index 93c19ad5..6c547c91 100644 --- a/web/src/components/MemoEditor.tsx +++ b/web/src/components/MemoEditor.tsx @@ -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) => { diff --git a/web/src/labs/marked/parser/Mark.ts b/web/src/labs/marked/parser/Mark.ts deleted file mode 100644 index 3b30ce23..00000000 --- a/web/src/labs/marked/parser/Mark.ts +++ /dev/null @@ -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 `${escape(matchResult[1])}`; -}; - -export default { - name: "mark", - regex: MARK_REG, - renderer, -}; diff --git a/web/src/labs/marked/parser/index.ts b/web/src/labs/marked/parser/index.ts index 9d5eb97d..04e2684b 100644 --- a/web/src/labs/marked/parser/index.ts +++ b/web/src/labs/marked/parser/index.ts @@ -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]; diff --git a/web/src/locales/en.json b/web/src/locales/en.json index bf4a0b46..255353d0 100644 --- a/web/src/locales/en.json +++ b/web/src/locales/en.json @@ -22,7 +22,6 @@ "delete": "Delete", "null": "Null", "share": "Share", - "mark": "Mark", "archive": "Archive", "basic": "Basic", "admin": "Admin", diff --git a/web/src/locales/vi.json b/web/src/locales/vi.json index 17e75f77..1b2ce25a 100644 --- a/web/src/locales/vi.json +++ b/web/src/locales/vi.json @@ -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", diff --git a/web/src/locales/zh.json b/web/src/locales/zh.json index a70e864a..6bdc2688 100644 --- a/web/src/locales/zh.json +++ b/web/src/locales/zh.json @@ -22,7 +22,6 @@ "delete": "删除", "null": "空", "share": "分享", - "mark": "标注", "archive": "归档", "basic": "基础", "admin": "管理员", diff --git a/web/src/services/editorStateService.ts b/web/src/services/editorStateService.ts index 110010fd..fe11a812 100644 --- a/web/src/services/editorStateService.ts +++ b/web/src/services/editorStateService.ts @@ -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)); }, diff --git a/web/src/store/modules/editor.ts b/web/src/store/modules/editor.ts index 15f8654b..e88f823a 100644 --- a/web/src/store/modules/editor.ts +++ b/web/src/store/modules/editor.ts @@ -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>) => { - return { - ...state, - markMemoId: action.payload, - }; - }, setEditMemoId: (state, action: PayloadAction>) => { 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;