@@ -155,54 +155,43 @@ onMounted(() => {
155155})
156156
157157const fetchSubscribers = async (afterId = null ) => {
158- const filters = {}
158+ const url = new URL (' /subscribers' , window .location .origin )
159+ if (afterId !== null ) {
160+ url .searchParams .set (' after_id' , afterId)
161+ }
159162
160163 if (currentFilter .value && currentFilter .value !== ' all' ) {
161- filters[ currentFilter .value ] = true
164+ url . searchParams . set ( currentFilter .value , ' true' )
162165 }
163166
164167 if (searchQuery .value ) {
165- filters . findColumn = searchColumn .value
166- filters . findValue = searchQuery .value
168+ url . searchParams . set ( ' findColumn' , searchColumn .value )
169+ url . searchParams . set ( ' findValue' , searchQuery .value )
167170 }
168171
169172 try {
170- const collection = await subscribersClient .getSubscribers (filters, afterId, 10 )
171-
172- subscribers .value = collection .items .map (subscriber => ({
173- id: subscriber .id ,
174- email: subscriber .email ,
175- confirmed: subscriber .confirmed ,
176- blacklisted: subscriber .blacklisted ,
177- createdAt: new Date (subscriber .createdAt ).toISOString ().replace (' T' , ' ' ).substring (0 , 19 ),
178- uniqueId: subscriber .uniqueId ,
179- listCount: subscriber .subscribedLists ? .length || 0 ,
180- }))
181-
182- const history = pagination .value .history || [0 ]
183- if (! history .includes (afterId)) {
184- history .push (afterId)
173+ const response = await fetch (url, {
174+ headers: { Accept: ' application/json' , ' X-Requested-With' : ' XMLHttpRequest' }
175+ })
176+
177+ if (response .status === 401 ) {
178+ const data = await response .json ()
179+ window .location .href = data .redirect
180+ return
185181 }
186182
187- const index = history .indexOf (afterId)
188- const prevId = index > 0 ? history[index - 1 ] : 0
189-
190- pagination .value = {
191- limit: collection .pagination .limit ,
192- afterId: collection .pagination .nextCursor ,
193- hasMore: collection .pagination .hasMore ,
194- total: collection .pagination .total ,
195- isFirstPage: afterId === 0 || afterId === null ,
196- prevId,
197- history,
198- }
183+ const data = await response .json ()
184+
185+ subscribers .value = data .items
186+ pagination .value = data .pagination
199187
200188 updateUrl (afterId)
201189 } catch (error) {
202190 console .error (' Failed to fetch subscribers:' , error)
203191 }
204192}
205193
194+
206195const handleSearch = () => {
207196 if (searchTimeout) {
208197 clearTimeout (searchTimeout)
0 commit comments