From 407d1cdcaa4a635233dd242826cb6e7768086f7a Mon Sep 17 00:00:00 2001 From: Zeng1998 <1129142694@qq.com> Date: Sun, 13 Nov 2022 19:34:22 +0800 Subject: [PATCH] feat: add visibility filter (#461) * feat: add visibility filter * update --- web/src/components/CreateShortcutDialog.tsx | 2 ++ web/src/helpers/filter.ts | 34 +++++++++++++++++++++ web/src/types/filter.d.ts | 12 ++++++-- 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/web/src/components/CreateShortcutDialog.tsx b/web/src/components/CreateShortcutDialog.tsx index 641e8f11..18fc699c 100644 --- a/web/src/components/CreateShortcutDialog.tsx +++ b/web/src/components/CreateShortcutDialog.tsx @@ -173,6 +173,8 @@ const MemoFilterInputer: React.FC = (props: MemoFilterIn const valueDataSource = type === "TYPE" ? filterConsts["TYPE"].values.map(({ text, value }) => ({ text: t(text), value })) + : type === "VISIBILITY" + ? filterConsts["VISIBILITY"].values.map(({ text, value }) => ({ text: t(text), value })) : tags.sort().map((t) => { return { text: t, value: t }; }); diff --git a/web/src/helpers/filter.ts b/web/src/helpers/filter.ts index 6068c7ba..4d82aad6 100644 --- a/web/src/helpers/filter.ts +++ b/web/src/helpers/filter.ts @@ -73,6 +73,34 @@ export const filterConsts = { }, ], }, + VISIBILITY: { + text: "Visibility", + value: "VISIBILITY", + operators: [ + { + text: "filter.operator.is", + value: "IS", + }, + { + text: "filter.operator.is-not", + value: "IS_NOT", + }, + ], + values: [ + { + text: "memo.visibility.public", + value: "PUBLIC", + }, + { + text: "memo.visibility.protected", + value: "PROTECTED", + }, + { + text: "memo.visibility.private", + value: "PRIVATE", + }, + ], + }, }; export const memoSpecialTypes = filterConsts["TYPE"].values; @@ -173,6 +201,12 @@ export const checkShouldShowMemo = (memo: Memo, filter: Filter) => { } else { return memo.displayTs > dayjs(value).valueOf(); } + } else if (type === "VISIBILITY") { + let matched = memo.visibility === value; + if (operator === "IS_NOT") { + matched = !matched; + } + shouldShow = matched; } return shouldShow; diff --git a/web/src/types/filter.d.ts b/web/src/types/filter.d.ts index a2783a3c..43511af6 100644 --- a/web/src/types/filter.d.ts +++ b/web/src/types/filter.d.ts @@ -41,6 +41,14 @@ interface DisplayTimeFilter extends BaseFilter { }; } -type FilterType = "TEXT" | "TYPE" | "TAG" | "DISPLAY_TIME"; +interface VisibilityFilter extends BaseFilter { + type: "VISIBILITY"; + value: { + operator: "IS" | "IS_NOT"; + value: string; + }; +} -type Filter = BaseFilter | TagFilter | TypeFilter | TextFilter | DisplayTimeFilter; +type FilterType = "TEXT" | "TYPE" | "TAG" | "DISPLAY_TIME" | "VISIBILITY"; + +type Filter = BaseFilter | TagFilter | TypeFilter | TextFilter | DisplayTimeFilter | VisibilityFilter;