diff --git a/web/src/components/CreateShortcutDialog.tsx b/web/src/components/CreateShortcutDialog.tsx index c6d3d3f7..641e8f11 100644 --- a/web/src/components/CreateShortcutDialog.tsx +++ b/web/src/components/CreateShortcutDialog.tsx @@ -8,6 +8,7 @@ import { generateDialog } from "./Dialog"; import toastHelper from "./Toast"; import Selector from "./common/Selector"; import "../less/create-shortcut-dialog.less"; +import dayjs from "dayjs"; interface Props extends DialogProps { shortcutId?: ShortcutId; @@ -176,8 +177,15 @@ const MemoFilterInputer: React.FC = (props: MemoFilterIn return { text: t, value: t }; }); + const maxDatetimeValue = dayjs().format("9999-12-31T23:59"); + useEffect(() => { - setValue(filter.value.value); + if (type === "DISPLAY_TIME") { + const nowDatetimeValue = dayjs().format("YYYY-MM-DDTHH:mm"); + handleValueChange(nowDatetimeValue); + } else { + setValue(filter.value.value); + } }, [type]); const handleRelationChange = (value: string) => { @@ -260,6 +268,16 @@ const MemoFilterInputer: React.FC = (props: MemoFilterIn }} placeholder={t("filter.text-placeholder")} /> + ) : type === "DISPLAY_TIME" ? ( + { + handleValueChange(event.target.value); + }} + /> ) : ( )} diff --git a/web/src/helpers/filter.ts b/web/src/helpers/filter.ts index 57dd1880..6068c7ba 100644 --- a/web/src/helpers/filter.ts +++ b/web/src/helpers/filter.ts @@ -1,4 +1,5 @@ import { TAG_REG, LINK_REG } from "../labs/marked/parser"; +import dayjs from "dayjs"; export const relationConsts = [ { text: "And", value: "AND" }, @@ -58,6 +59,20 @@ export const filterConsts = { }, ], }, + DISPLAY_TIME: { + text: "Display Time", + value: "DISPLAY_TIME", + operators: [ + { + text: "filter.operator.before", + value: "BEFORE", + }, + { + text: "filter.operator.after", + value: "AFTER", + }, + ], + }, }; export const memoSpecialTypes = filterConsts["TYPE"].values; @@ -152,6 +167,12 @@ export const checkShouldShowMemo = (memo: Memo, filter: Filter) => { } shouldShow = contained; } + } else if (type === "DISPLAY_TIME") { + if (operator === "BEFORE") { + return memo.displayTs < dayjs(value).valueOf(); + } else { + return memo.displayTs > dayjs(value).valueOf(); + } } return shouldShow; diff --git a/web/src/less/create-shortcut-dialog.less b/web/src/less/create-shortcut-dialog.less index 1e3737a2..ce4b4b33 100644 --- a/web/src/less/create-shortcut-dialog.less +++ b/web/src/less/create-shortcut-dialog.less @@ -73,15 +73,15 @@ } &.type-selector { - @apply w-20; - } - - &.operator-selector { @apply w-24; } + &.operator-selector { + @apply w-20; + } + &.value-selector { - flex-grow: 1; + @apply grow; } } @@ -90,6 +90,11 @@ @apply h-9 px-2 shrink-0 grow mr-1 text-sm rounded border bg-transparent hover:bg-gray-50; } + > input.datetime-selector{ + max-width: calc(100% - 152px); + @apply h-9 px-2 shrink-0 grow mr-1 text-sm rounded border bg-transparent hover:bg-gray-50; + } + > .remove-btn { @apply w-4 h-auto ml-1 cursor-pointer opacity-60 hover:opacity-80; } diff --git a/web/src/locales/en.json b/web/src/locales/en.json index 9982eba3..d9ea2a45 100644 --- a/web/src/locales/en.json +++ b/web/src/locales/en.json @@ -112,7 +112,9 @@ "contains": "Contains", "not-contains": "Does not contain", "is": "Is", - "is-not": "Is Not" + "is-not": "Is Not", + "before": "Before", + "after": "After" }, "value": { "not-tagged": "No tags", diff --git a/web/src/locales/vi.json b/web/src/locales/vi.json index c1ab08e2..ccb64d83 100644 --- a/web/src/locales/vi.json +++ b/web/src/locales/vi.json @@ -109,10 +109,12 @@ "filter": { "new-filter": "Bộ lọc mới", "operator": { - "contains": "Contains", - "not-contains": "Does not contain", - "is": "Is", - "is-not": "Is Not" + "contains": "Chứa", + "not-contains": "Không chứa", + "is": "Là", + "is-not": "không phải", + "before": "Trước", + "after": "sau" }, "value": { "not-tagged": "Không có thẻ", diff --git a/web/src/locales/zh.json b/web/src/locales/zh.json index 4836f116..7357f67d 100644 --- a/web/src/locales/zh.json +++ b/web/src/locales/zh.json @@ -112,7 +112,9 @@ "contains": "包含", "not-contains": "不包含", "is": "是", - "is-not": "不是" + "is-not": "不是", + "before": "早于", + "after": "晚于" }, "value": { "not-tagged": "无标签", diff --git a/web/src/types/filter.d.ts b/web/src/types/filter.d.ts index 9c71f14c..a2783a3c 100644 --- a/web/src/types/filter.d.ts +++ b/web/src/types/filter.d.ts @@ -33,6 +33,14 @@ interface TextFilter extends BaseFilter { }; } -type FilterType = "TEXT" | "TYPE" | "TAG"; +interface DisplayTimeFilter extends BaseFilter { + type: "DISPLAY_TIME"; + value: { + operator: "BEFORE" | "AFTER"; + value: string; + }; +} -type Filter = BaseFilter | TagFilter | TypeFilter | TextFilter; +type FilterType = "TEXT" | "TYPE" | "TAG" | "DISPLAY_TIME"; + +type Filter = BaseFilter | TagFilter | TypeFilter | TextFilter | DisplayTimeFilter;