mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-13 21:01:21 +08:00
Don't fetch users table twice
This commit is contained in:
parent
9f73738d12
commit
4e251311b6
@ -1,6 +1,7 @@
|
||||
'use client';
|
||||
import { useAdminApp } from '@/app/(main)/(protected)/projects/[projectId]/use-admin-app';
|
||||
import { ServerUser } from '@stackframe/stack';
|
||||
import { deepPlainEquals } from '@stackframe/stack-shared/dist/utils/objects';
|
||||
import { deindent } from '@stackframe/stack-shared/dist/utils/strings';
|
||||
import { ActionCell, ActionDialog, AvatarCell, BadgeCell, CopyField, DataTableColumnHeader, DataTableManualPagination, DateCell, SearchToolbarItem, SimpleTooltip, TextCell, Typography } from "@stackframe/stack-ui";
|
||||
import { ColumnDef, ColumnFiltersState, Row, SortingState, Table } from "@tanstack/react-table";
|
||||
@ -170,8 +171,8 @@ const columns: ColumnDef<ExtendedServerUser>[] = [
|
||||
},
|
||||
];
|
||||
|
||||
export function extendUsers(users: ServerUser[]): ExtendedServerUser[] {
|
||||
return users.map((user) => ({
|
||||
export function extendUsers(users: ServerUser[] & { nextCursor: string | null }): ExtendedServerUser[] & { nextCursor: string | null } {
|
||||
const extended = users.map((user) => ({
|
||||
...user,
|
||||
authTypes: [
|
||||
...user.otpAuthEnabled ? ["otp"] : [],
|
||||
@ -180,6 +181,7 @@ export function extendUsers(users: ServerUser[]): ExtendedServerUser[] {
|
||||
],
|
||||
emailVerified: user.primaryEmailVerified ? "verified" : "unverified",
|
||||
} satisfies ExtendedServerUser)).sort((a, b) => a.signedUpAt > b.signedUpAt ? -1 : 1);
|
||||
return Object.assign(extended, { nextCursor: users.nextCursor });
|
||||
}
|
||||
|
||||
export function UserTable() {
|
||||
@ -194,7 +196,7 @@ export function UserTable() {
|
||||
columnFilters: ColumnFiltersState,
|
||||
globalFilters: any,
|
||||
}) => {
|
||||
let filters: Parameters<typeof stackAdminApp.listUsers>[0] = {
|
||||
let newFilters: Parameters<typeof stackAdminApp.listUsers>[0] = {
|
||||
cursor: options.cursor,
|
||||
limit: options.limit,
|
||||
query: options.globalFilters,
|
||||
@ -204,13 +206,19 @@ export function UserTable() {
|
||||
signedUpAt: "signedUpAt",
|
||||
} as const;
|
||||
if (options.sorting.length > 0 && options.sorting[0].id in orderMap) {
|
||||
filters.orderBy = orderMap[options.sorting[0].id as keyof typeof orderMap];
|
||||
filters.desc = options.sorting[0].desc;
|
||||
newFilters.orderBy = orderMap[options.sorting[0].id as keyof typeof orderMap];
|
||||
newFilters.desc = options.sorting[0].desc;
|
||||
}
|
||||
|
||||
setFilters(filters);
|
||||
const users = await stackAdminApp.listUsers(filters);
|
||||
return { nextCursor: users.nextCursor };
|
||||
console.log("AAAAAAAAA", newFilters, filters, deepPlainEquals(newFilters, filters, { ignoreUndefinedValues: true }));
|
||||
if (deepPlainEquals(newFilters, filters, { ignoreUndefinedValues: true })) {
|
||||
// save ourselves a request if the filters didn't change
|
||||
return { nextCursor: users.nextCursor };
|
||||
} else {
|
||||
setFilters(newFilters);
|
||||
const users = await stackAdminApp.listUsers(newFilters);
|
||||
return { nextCursor: users.nextCursor };
|
||||
}
|
||||
};
|
||||
|
||||
return <DataTableManualPagination
|
||||
|
||||
@ -194,6 +194,7 @@ class AsyncValueCache<T> {
|
||||
});
|
||||
this._unsubscribers.push(unsubscribe);
|
||||
}
|
||||
console.log("add", this._subscriptionsCount, new Date().toISOString());
|
||||
|
||||
let hasUnsubscribed = false;
|
||||
return {
|
||||
@ -201,6 +202,7 @@ class AsyncValueCache<T> {
|
||||
if (hasUnsubscribed) return;
|
||||
hasUnsubscribed = true;
|
||||
storeObj.unsubscribe();
|
||||
console.log("remove", this._subscriptionsCount - 1, new Date().toISOString());
|
||||
if (--this._subscriptionsCount === 0) {
|
||||
for (const unsubscribe of this._unsubscribers) {
|
||||
unsubscribe();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user