feat: add visibility filter (#461)

* feat: add visibility filter

* update
This commit is contained in:
Zeng1998 2022-11-13 19:34:22 +08:00 committed by GitHub
parent cb50bbc3cb
commit 407d1cdcaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 2 deletions

View File

@ -173,6 +173,8 @@ const MemoFilterInputer: React.FC<MemoFilterInputerProps> = (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 };
});

View File

@ -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;

View File

@ -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;