Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

🐛 Show a skeleton while the polls list loads after a filter change (#3496)

Luke Vella4f4101a53c5d
diff --git a/apps/web/src/app/[locale]/(space)/(dashboard)/polls/page.tsx b/apps/web/src/app/[locale]/(space)/(dashboard)/polls/page.tsx
index 765da8670..38f17eab9 100644
--- a/apps/web/src/app/[locale]/(space)/(dashboard)/polls/page.tsx
+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/polls/page.tsx
@@ -4,24 +4,15 @@ import { loadPollStatusCounts } from "@/features/poll/loaders";
import { getTranslation } from "@/i18n/server";
import { createPrivateSSRHelper } from "@/trpc/server/create-ssr-helper";
import { PollsPage } from "./polls-page";
-import { searchParamsSchema } from "./schema";
-
-export default async function Page(props: {
- searchParams?: Promise<{ [key: string]: string | string[] | undefined }>;
-}) {
- const searchParams = await props.searchParams;
- const { status, q, member } = searchParamsSchema.parse(searchParams);
+export default async function Page() {
const helpers = await createPrivateSSRHelper();
+ // The polls list itself is fetched on the client so switching filters shows
+ // a skeleton instead of holding the previous list until the server responds.
const [counts] = await Promise.all([
loadPollStatusCounts(),
helpers.spaces.listMembers.prefetch(),
- helpers.polls.infiniteChronological.prefetchInfinite({
- status,
- search: q,
- member,
- }),
]);
return (
diff --git a/apps/web/src/features/poll/components/polls-infinite-list.tsx b/apps/web/src/features/poll/components/polls-infinite-list.tsx
index f94f9d536..ab1cc132c 100644
--- a/apps/web/src/features/poll/components/polls-infinite-list.tsx
+++ b/apps/web/src/features/poll/components/polls-infinite-list.tsx
@@ -19,6 +19,7 @@ import {
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@rallly/ui/dropdown-menu";
+import { Skeleton } from "@rallly/ui/skeleton";
import { toast } from "@rallly/ui/sonner";
import { Tooltip, TooltipContent, TooltipTrigger } from "@rallly/ui/tooltip";
import { absoluteUrl, shortUrl } from "@rallly/utils/absolute-url";
@@ -411,6 +412,23 @@ const columns = [
}),
];
+function PollsListSkeleton() {
+ return (
+ <div aria-hidden className="py-2">
+ {Array.from({ length: 6 }).map((_, i) => (
+ <div
+ // biome-ignore lint/suspicious/noArrayIndexKey: static placeholders
+ key={i}
+ className="flex h-12 items-center gap-3 px-8"
+ >
+ <Skeleton className="size-4 rounded-full" />
+ <Skeleton className="h-4 w-48" />
+ </div>
+ ))}
+ </div>
+ );
+}
+
export function PollsInfiniteList({
status,
search,
@@ -422,20 +440,26 @@ export function PollsInfiniteList({
member?: string;
emptyState: React.ReactNode;
}) {
- const [data, { fetchNextPage, hasNextPage, isFetchingNextPage }] =
- trpc.polls.infiniteChronological.useSuspenseInfiniteQuery(
- {
- status,
- search,
- member,
- },
- {
- getNextPageParam: (lastPage) => lastPage.nextCursor,
- },
- );
+ const {
+ data,
+ error,
+ fetchNextPage,
+ hasNextPage,
+ isFetchingNextPage,
+ status: queryStatus,
+ } = trpc.polls.infiniteChronological.useInfiniteQuery(
+ {
+ status,
+ search,
+ member,
+ },
+ {
+ getNextPageParam: (lastPage) => lastPage.nextCursor,
+ },
+ );
const polls = React.useMemo(
- () => data.pages.flatMap((page) => page.polls),
+ () => data?.pages.flatMap((page) => page.polls) ?? [],
[data],
);
@@ -477,6 +501,24 @@ export function PollsInfiniteList({
};
}, [handleLoadMore]);
+ if (queryStatus === "pending") {
+ return (
+ <ListViewContent>
+ <PollsListSkeleton />
+ </ListViewContent>
+ );
+ }
+
+ if (queryStatus === "error") {
+ return (
+ <ListViewContent>
+ <div className="py-8 text-center text-red-600">
+ Error loading polls: {error?.message}
+ </div>
+ </ListViewContent>
+ );
+ }
+
if (polls.length === 0) {
return <ListViewContent>{emptyState}</ListViewContent>;
}