mirror of
https://github.com/usememos/memos.git
synced 2025-04-02 12:00:21 +02:00
fix: tag query filter
This commit is contained in:
parent
308adef98d
commit
6a40be9f8e
@ -19,23 +19,36 @@ const MemoList: React.FC<Props> = () => {
|
|||||||
const wrapperElement = useRef<HTMLDivElement>(null);
|
const wrapperElement = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
const { tag: tagQuery, duration, type: memoType, text: textQuery, filter: queryId } = query;
|
const { tag: tagQuery, duration, type: memoType, text: textQuery, filter: queryId } = query;
|
||||||
const showMemoFilter = Boolean(tagQuery || (duration && duration.from < duration.to) || memoType || textQuery);
|
const queryFilter = queryService.getQueryById(queryId);
|
||||||
|
const showMemoFilter = Boolean(tagQuery || (duration && duration.from < duration.to) || memoType || textQuery || queryFilter);
|
||||||
|
|
||||||
const shownMemos =
|
const shownMemos =
|
||||||
showMemoFilter || queryId
|
showMemoFilter || queryFilter
|
||||||
? memos.filter((memo) => {
|
? memos.filter((memo) => {
|
||||||
let shouldShow = true;
|
let shouldShow = true;
|
||||||
|
|
||||||
const query = queryService.getQueryById(queryId);
|
if (queryFilter) {
|
||||||
if (query) {
|
const filters = JSON.parse(queryFilter.querystring) as Filter[];
|
||||||
const filters = JSON.parse(query.querystring) as Filter[];
|
|
||||||
if (Array.isArray(filters)) {
|
if (Array.isArray(filters)) {
|
||||||
shouldShow = checkShouldShowMemoWithFilters(memo, filters);
|
shouldShow = checkShouldShowMemoWithFilters(memo, filters);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tagQuery && !memo.content.includes(`#${tagQuery} `) && !memo.content.includes(`# ${tagQuery} `)) {
|
if (tagQuery) {
|
||||||
shouldShow = false;
|
const tagsSet = new Set<string>();
|
||||||
|
for (const t of Array.from(memo.content.match(TAG_REG) ?? [])) {
|
||||||
|
const tag = t.replace(TAG_REG, "$1").trim();
|
||||||
|
const items = tag.split("/");
|
||||||
|
let temp = "";
|
||||||
|
for (const i of items) {
|
||||||
|
temp += i;
|
||||||
|
tagsSet.add(temp);
|
||||||
|
temp += "/";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!tagsSet.has(tagQuery)) {
|
||||||
|
shouldShow = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
duration &&
|
duration &&
|
||||||
|
@ -100,7 +100,7 @@ const TagItemContainer: React.FC<TagItemContainerProps> = (props: TagItemContain
|
|||||||
if (isActive) {
|
if (isActive) {
|
||||||
locationService.setTagQuery("");
|
locationService.setTagQuery("");
|
||||||
} else {
|
} else {
|
||||||
utils.copyTextToClipboard(`# ${tag.text} `);
|
utils.copyTextToClipboard(`#${tag.text} `);
|
||||||
if (!["/", "/recycle"].includes(locationService.getState().pathname)) {
|
if (!["/", "/recycle"].includes(locationService.getState().pathname)) {
|
||||||
locationService.setPathname("/");
|
locationService.setPathname("/");
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,21 @@ export const checkShouldShowMemo = (memo: Model.Memo, filter: Filter) => {
|
|||||||
let shouldShow = true;
|
let shouldShow = true;
|
||||||
|
|
||||||
if (type === "TAG") {
|
if (type === "TAG") {
|
||||||
let contained = memo.content.includes(`#${value} `) || memo.content.includes(`# ${value} `);
|
let contained = true;
|
||||||
|
const tagsSet = new Set<string>();
|
||||||
|
for (const t of Array.from(memo.content.match(TAG_REG) ?? [])) {
|
||||||
|
const tag = t.replace(TAG_REG, "$1").trim();
|
||||||
|
const items = tag.split("/");
|
||||||
|
let temp = "";
|
||||||
|
for (const i of items) {
|
||||||
|
temp += i;
|
||||||
|
tagsSet.add(temp);
|
||||||
|
temp += "/";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!tagsSet.has(value)) {
|
||||||
|
contained = false;
|
||||||
|
}
|
||||||
if (operator === "NOT_CONTAIN") {
|
if (operator === "NOT_CONTAIN") {
|
||||||
contained = !contained;
|
contained = !contained;
|
||||||
}
|
}
|
||||||
|
@ -37,8 +37,21 @@ const MemoTrash: React.FC<Props> = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tagQuery && !memo.content.includes(`# ${tagQuery}`)) {
|
if (tagQuery) {
|
||||||
shouldShow = false;
|
const tagsSet = new Set<string>();
|
||||||
|
for (const t of Array.from(memo.content.match(TAG_REG) ?? [])) {
|
||||||
|
const tag = t.replace(TAG_REG, "$1").trim();
|
||||||
|
const items = tag.split("/");
|
||||||
|
let temp = "";
|
||||||
|
for (const i of items) {
|
||||||
|
temp += i;
|
||||||
|
tagsSet.add(temp);
|
||||||
|
temp += "/";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!tagsSet.has(tagQuery)) {
|
||||||
|
shouldShow = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
duration &&
|
duration &&
|
||||||
|
Loading…
x
Reference in New Issue
Block a user