feat: upsert tag based content (#816)

* feat: upsert tag based content

* chore: update
This commit is contained in:
boojack
2022-12-22 00:35:47 +08:00
committed by GitHub
parent 68a77b6e1f
commit b6f19ca093
3 changed files with 82 additions and 2 deletions

View File

@ -1,6 +1,7 @@
import { isNumber, last, toLower } from "lodash";
import { isNumber, last, toLower, uniq } from "lodash";
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import { getMatchedNodes } from "../labs/marked";
import { deleteMemoResource, upsertMemoResource } from "../helpers/api";
import { TAB_SPACE_WIDTH, UNKNOWN_ID, VISIBILITY_SELECTOR_ITEMS } from "../helpers/consts";
import { useEditorStore, useLocationStore, useMemoStore, useResourceStore, useTagStore, useUserStore } from "../store/module";
@ -326,6 +327,13 @@ const MemoEditor = () => {
toastHelper.error(error.response.data.message);
}
// Upsert tag based with content.
const matchedNodes = getMatchedNodes(content);
const tagNameList = uniq(matchedNodes.filter((node) => node.parserName === "tag").map((node) => node.matchedContent.slice(1)));
for (const tagName of tagNameList) {
await tagStore.upsertTag(tagName);
}
setState((state) => {
return {
...state,