chore: update timeline filters

This commit is contained in:
Steven 2024-05-31 09:06:03 +08:00
parent 98f2cf6397
commit 08a9291964

View file

@ -29,7 +29,7 @@ const Timeline = () => {
const memoStore = useMemoStore();
const memoList = useMemoList();
const [, setLastVisited] = useLocalStorage<string>("lastVisited", Routes.TIMELINE);
const { tag: tagQuery, text: textQuery } = useFilterWithUrlParams();
const filter = useFilterWithUrlParams();
const [activityStats, setActivityStats] = useState<Record<string, number>>({});
const [selectedDateString, setSelectedDateString] = useState<string>(new Date().toDateString());
const [isRequesting, setIsRequesting] = useState(true);
@ -44,21 +44,11 @@ const Timeline = () => {
useEffect(() => {
memoList.reset();
fetchMemos("");
}, [selectedDateString, tagQuery, textQuery]);
}, [selectedDateString, filter.text, filter.tag, filter.memoPropertyFilter]);
useEffect(() => {
(async () => {
const filters = [`row_status == "NORMAL"`];
const contentSearch: string[] = [];
if (textQuery) {
contentSearch.push(JSON.stringify(textQuery));
}
if (contentSearch.length > 0) {
filters.push(`content_search == [${contentSearch.join(", ")}]`);
}
if (tagQuery) {
filters.push(`tag == "${tagQuery}"`);
}
const { stats } = await memoServiceClient.getUserMemosStats({
name: user.name,
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
@ -79,14 +69,25 @@ const Timeline = () => {
setIsRequesting(true);
const filters = [`creator == "${user.name}"`, `row_status == "NORMAL"`];
const contentSearch: string[] = [];
if (textQuery) {
contentSearch.push(JSON.stringify(textQuery));
if (filter.text) {
contentSearch.push(JSON.stringify(filter.text));
}
if (contentSearch.length > 0) {
filters.push(`content_search == [${contentSearch.join(", ")}]`);
}
if (tagQuery) {
filters.push(`tag == "${tagQuery}"`);
if (filter.tag) {
filters.push(`tag == "${filter.tag}"`);
}
if (filter.memoPropertyFilter) {
if (filter.memoPropertyFilter.hasLink) {
filters.push(`has_link == true`);
}
if (filter.memoPropertyFilter.hasTaskList) {
filters.push(`has_task_list == true`);
}
if (filter.memoPropertyFilter.hasCode) {
filters.push(`has_code == true`);
}
}
if (selectedDateString) {
const selectedDateStamp = getTimeStampByDate(selectedDateString);