2026-08-01 09:19:39 +07:00
|
|
|
import useSWR from "swr";
|
2026-07-26 16:14:32 +07:00
|
|
|
|
|
|
|
|
import { dashboardApi } from "@/lib/api";
|
|
|
|
|
import type {
|
|
|
|
|
DashboardChannelDetail,
|
|
|
|
|
DashboardStats,
|
|
|
|
|
DashboardUserDetail,
|
|
|
|
|
} from "@/lib/types";
|
|
|
|
|
|
2026-07-26 16:55:20 +07:00
|
|
|
export function useStats() {
|
2026-08-01 09:19:39 +07:00
|
|
|
return useSWR<DashboardStats>(["dashboard-stats"], () =>
|
|
|
|
|
dashboardApi.getStats(),
|
|
|
|
|
);
|
2026-07-26 16:14:32 +07:00
|
|
|
}
|
|
|
|
|
|
2026-07-26 16:55:20 +07:00
|
|
|
export function useUsers(search?: string) {
|
2026-08-01 09:19:39 +07:00
|
|
|
return useSWR(
|
|
|
|
|
["dashboard-users", search ?? ""],
|
|
|
|
|
async () => {
|
|
|
|
|
const res = await dashboardApi.listUsers(20, undefined, search);
|
|
|
|
|
return res.data;
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
keepPreviousData: true,
|
|
|
|
|
},
|
|
|
|
|
);
|
2026-07-26 16:14:32 +07:00
|
|
|
}
|
|
|
|
|
|
2026-07-31 16:54:41 +07:00
|
|
|
export function useChannels(guildId?: string, search?: string) {
|
2026-08-01 09:19:39 +07:00
|
|
|
return useSWR(
|
|
|
|
|
["dashboard-channels", guildId ?? "__all__", search ?? ""],
|
|
|
|
|
async () => {
|
|
|
|
|
const res = await dashboardApi.listChannels(
|
|
|
|
|
20,
|
|
|
|
|
search,
|
|
|
|
|
guildId || undefined,
|
|
|
|
|
);
|
|
|
|
|
return res.data;
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
keepPreviousData: true,
|
|
|
|
|
},
|
|
|
|
|
);
|
2026-07-26 16:14:32 +07:00
|
|
|
}
|
|
|
|
|
|
2026-07-26 16:55:20 +07:00
|
|
|
export function useUserDetail(userId: string | null) {
|
2026-08-01 09:19:39 +07:00
|
|
|
return useSWR<DashboardUserDetail>(
|
|
|
|
|
userId ? ["dashboard-user", userId] : null,
|
|
|
|
|
() => dashboardApi.getUserDetail(userId!),
|
|
|
|
|
);
|
2026-07-26 16:14:32 +07:00
|
|
|
}
|
|
|
|
|
|
2026-07-26 16:55:20 +07:00
|
|
|
export function useChannelDetail(channelId: string | null) {
|
2026-08-01 09:19:39 +07:00
|
|
|
return useSWR<DashboardChannelDetail>(
|
|
|
|
|
channelId ? ["dashboard-channel", channelId] : null,
|
|
|
|
|
() => dashboardApi.getChannelDetail(channelId!),
|
|
|
|
|
);
|
2026-07-26 16:14:32 +07:00
|
|
|
}
|