diff --git a/client/src/page/feeds.tsx b/client/src/page/feeds.tsx
index 32101d95..729bc02b 100644
--- a/client/src/page/feeds.tsx
+++ b/client/src/page/feeds.tsx
@@ -32,11 +32,7 @@ type FeedsMap = {
export function FeedsPage() {
const query = new URLSearchParams(useSearch());
const profile = useContext(ProfileContext);
- const [listState, _setListState] = useState('normal')
- function setListState(type: FeedType) {
- if (feeds[type].size === 0) fetchFeeds(type)
- _setListState(type)
- }
+ const [listState, _setListState] = useState(query.get("type") as FeedType || 'normal')
const [feeds, setFeeds] = useState({
draft: { size: 0, data: [], hasNext: false },
unlisted: { size: 0, data: [], hasNext: false },
@@ -44,7 +40,7 @@ export function FeedsPage() {
})
const page = tryInt(1, query.get("page"))
const limit = tryInt(10, query.get("limit"), process.env.PAGE_SIZE)
- const ref = useRef(false)
+ const ref = useRef("")
function fetchFeeds(type: FeedType) {
client.feed.index.get({
query: {
@@ -63,16 +59,16 @@ export function FeedsPage() {
})
}
useEffect(() => {
- if (ref.current) return
- fetchFeeds(listState)
- ref.current = true
- }, [])
-
- useEffect(() => {
- if (feeds) {
- fetchFeeds(listState)
+ const key = `${query.get("page")} ${query.get("type")}`
+ console.log(key)
+ if (ref.current == key) return
+ const type = query.get("type") as FeedType || 'normal'
+ if (type !== listState) {
+ _setListState(type)
}
- }, [query.get("page")])
+ fetchFeeds(type)
+ ref.current = key
+ }, [query.get("page"), query.get("type")])
return (
<>
@@ -87,12 +83,12 @@ export function FeedsPage() {
{profile?.permission &&
-
-
+
}
@@ -101,11 +97,11 @@ export function FeedsPage() {
))}
- 1 ? '' : 'invisible'}`}>
上一页
-
下一页