|
1 | 1 | 'use client'
|
2 | 2 |
|
3 | 3 | import { useQuery } from '@tanstack/react-query'
|
| 4 | +import { sleep } from 'openai/core' |
4 | 5 |
|
5 | 6 | import { useOnlineCount } from '~/atoms'
|
6 | 7 | import { useSocketIsConnect } from '~/atoms/hooks'
|
@@ -115,51 +116,46 @@ const RoomsInfo = () => {
|
115 | 116 | const { data } = useQuery({
|
116 | 117 | queryKey: ['rooms'],
|
117 | 118 | refetchOnMount: true,
|
118 |
| - queryFn: () => { |
119 |
| - return apiClient.activity |
120 |
| - .getRoomsInfo() |
121 |
| - .then((res) => res.$serialized) |
122 |
| - .then((data) => { |
123 |
| - const result = [] as { |
124 |
| - path: string |
125 |
| - title: string |
126 |
| - count: number |
127 |
| - }[] |
128 |
| - |
129 |
| - const morphArticleIdToRoomName = (id: string) => `article_${id}` |
130 |
| - data.objects.notes.forEach((note) => { |
131 |
| - result.push({ |
132 |
| - path: routeBuilder(Routes.Note, { |
133 |
| - id: note.nid, |
134 |
| - }), |
135 |
| - title: note.title, |
136 |
| - count: data.roomCount[morphArticleIdToRoomName(note.id)], |
137 |
| - }) |
138 |
| - }) |
139 |
| - |
140 |
| - data.objects.posts.forEach((post) => { |
141 |
| - result.push({ |
142 |
| - path: routeBuilder(Routes.Post, { |
143 |
| - category: post.category.slug, |
144 |
| - slug: post.slug, |
145 |
| - }), |
146 |
| - title: post.title, |
147 |
| - count: data.roomCount[morphArticleIdToRoomName(post.id)], |
148 |
| - }) |
149 |
| - }) |
150 |
| - |
151 |
| - data.objects.pages.forEach((page) => { |
152 |
| - result.push({ |
153 |
| - path: routeBuilder(Routes.Page, { |
154 |
| - slug: page.slug, |
155 |
| - }), |
156 |
| - title: page.title, |
157 |
| - count: data.roomCount[morphArticleIdToRoomName(page.id)], |
158 |
| - }) |
159 |
| - }) |
160 |
| - |
161 |
| - return result.sort((a, b) => b.count - a.count) |
| 119 | + staleTime: 1000 * 10, |
| 120 | + queryFn: async () => { |
| 121 | + await sleep(1000) |
| 122 | + const res = await apiClient.activity.getRoomsInfo() |
| 123 | + const data = res.$serialized |
| 124 | + const result = [] as { |
| 125 | + path: string |
| 126 | + title: string |
| 127 | + count: number |
| 128 | + }[] |
| 129 | + const morphArticleIdToRoomName = (id: string) => `article_${id}` |
| 130 | + data.objects.notes.forEach((note) => { |
| 131 | + result.push({ |
| 132 | + path: routeBuilder(Routes.Note, { |
| 133 | + id: note.nid, |
| 134 | + }), |
| 135 | + title: note.title, |
| 136 | + count: data.roomCount[morphArticleIdToRoomName(note.id)], |
| 137 | + }) |
| 138 | + }) |
| 139 | + data.objects.posts.forEach((post) => { |
| 140 | + result.push({ |
| 141 | + path: routeBuilder(Routes.Post, { |
| 142 | + category: post.category.slug, |
| 143 | + slug: post.slug, |
| 144 | + }), |
| 145 | + title: post.title, |
| 146 | + count: data.roomCount[morphArticleIdToRoomName(post.id)], |
| 147 | + }) |
| 148 | + }) |
| 149 | + data.objects.pages.forEach((page) => { |
| 150 | + result.push({ |
| 151 | + path: routeBuilder(Routes.Page, { |
| 152 | + slug: page.slug, |
| 153 | + }), |
| 154 | + title: page.title, |
| 155 | + count: data.roomCount[morphArticleIdToRoomName(page.id)], |
162 | 156 | })
|
| 157 | + }) |
| 158 | + return result.sort((a, b) => b.count - a.count) |
163 | 159 | },
|
164 | 160 | })
|
165 | 161 |
|
|
0 commit comments