|
|
|
@ -1,64 +1,35 @@
|
|
|
|
|
import dayjs from "dayjs";
|
|
|
|
|
import { observer } from "mobx-react-lite";
|
|
|
|
|
import { useMemo } from "react";
|
|
|
|
|
import MemoView from "@/components/MemoView";
|
|
|
|
|
import MobileHeader from "@/components/MobileHeader";
|
|
|
|
|
import PagedMemoList from "@/components/PagedMemoList";
|
|
|
|
|
import useCurrentUser from "@/hooks/useCurrentUser";
|
|
|
|
|
import useResponsiveWidth from "@/hooks/useResponsiveWidth";
|
|
|
|
|
import { viewStore } from "@/store/v2";
|
|
|
|
|
import memoFilterStore from "@/store/v2/memoFilter";
|
|
|
|
|
import { Direction, State } from "@/types/proto/api/v1/common";
|
|
|
|
|
import { Memo } from "@/types/proto/api/v1/memo_service";
|
|
|
|
|
|
|
|
|
|
const Explore = observer(() => {
|
|
|
|
|
const user = useCurrentUser();
|
|
|
|
|
|
|
|
|
|
const memoListFilter = useMemo(() => {
|
|
|
|
|
const conditions = [];
|
|
|
|
|
const contentSearch: string[] = [];
|
|
|
|
|
const tagSearch: string[] = [];
|
|
|
|
|
for (const filter of memoFilterStore.filters) {
|
|
|
|
|
if (filter.factor === "contentSearch") {
|
|
|
|
|
contentSearch.push(`"${filter.value}"`);
|
|
|
|
|
} else if (filter.factor === "tagSearch") {
|
|
|
|
|
tagSearch.push(`"${filter.value}"`);
|
|
|
|
|
} else if (filter.factor === "property.hasLink") {
|
|
|
|
|
conditions.push(`has_link == true`);
|
|
|
|
|
} else if (filter.factor === "property.hasTaskList") {
|
|
|
|
|
conditions.push(`has_task_list == true`);
|
|
|
|
|
} else if (filter.factor === "property.hasCode") {
|
|
|
|
|
conditions.push(`has_code == true`);
|
|
|
|
|
} else if (filter.factor === "displayTime") {
|
|
|
|
|
const filterDate = new Date(filter.value);
|
|
|
|
|
const filterUtcTimestamp = filterDate.getTime() + filterDate.getTimezoneOffset() * 60 * 1000;
|
|
|
|
|
const timestampAfter = filterUtcTimestamp / 1000;
|
|
|
|
|
conditions.push(`display_time_after == ${timestampAfter}`);
|
|
|
|
|
conditions.push(`display_time_before == ${timestampAfter + 60 * 60 * 24}`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (contentSearch.length > 0) {
|
|
|
|
|
conditions.push(`content_search == [${contentSearch.join(", ")}]`);
|
|
|
|
|
}
|
|
|
|
|
if (tagSearch.length > 0) {
|
|
|
|
|
conditions.push(`tag_search == [${tagSearch.join(", ")}]`);
|
|
|
|
|
}
|
|
|
|
|
return conditions.join(" && ");
|
|
|
|
|
}, [user, memoFilterStore.filters, viewStore.state.orderByTimeAsc]);
|
|
|
|
|
const { md } = useResponsiveWidth();
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<PagedMemoList
|
|
|
|
|
renderer={(memo: Memo) => <MemoView key={`${memo.name}-${memo.updateTime}`} memo={memo} showCreator showVisibility compact />}
|
|
|
|
|
listSort={(memos: Memo[]) =>
|
|
|
|
|
memos
|
|
|
|
|
.filter((memo) => memo.state === State.NORMAL)
|
|
|
|
|
.sort((a, b) =>
|
|
|
|
|
viewStore.state.orderByTimeAsc
|
|
|
|
|
? dayjs(a.displayTime).unix() - dayjs(b.displayTime).unix()
|
|
|
|
|
: dayjs(b.displayTime).unix() - dayjs(a.displayTime).unix(),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
direction={viewStore.state.orderByTimeAsc ? Direction.ASC : Direction.DESC}
|
|
|
|
|
oldFilter={memoListFilter}
|
|
|
|
|
/>
|
|
|
|
|
<section className="@container w-full max-w-5xl min-h-full flex flex-col justify-start items-center sm:pt-3 md:pt-6 pb-8">
|
|
|
|
|
{!md && <MobileHeader />}
|
|
|
|
|
<div className="w-full px-4 sm:px-6">
|
|
|
|
|
<PagedMemoList
|
|
|
|
|
renderer={(memo: Memo) => <MemoView key={`${memo.name}-${memo.updateTime}`} memo={memo} showCreator showVisibility compact />}
|
|
|
|
|
listSort={(memos: Memo[]) =>
|
|
|
|
|
memos
|
|
|
|
|
.filter((memo) => memo.state === State.NORMAL)
|
|
|
|
|
.sort((a, b) =>
|
|
|
|
|
viewStore.state.orderByTimeAsc
|
|
|
|
|
? dayjs(a.displayTime).unix() - dayjs(b.displayTime).unix()
|
|
|
|
|
: dayjs(b.displayTime).unix() - dayjs(a.displayTime).unix(),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
direction={viewStore.state.orderByTimeAsc ? Direction.ASC : Direction.DESC}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|