Skip to content

Commit

Permalink
Better loading in the conference schedule builder (#4377)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoacierno authored Feb 23, 2025
1 parent ae7154e commit b5be418
Showing 1 changed file with 35 additions and 16 deletions.
51 changes: 35 additions & 16 deletions backend/custom_admin/src/components/schedule-builder/root.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { Flex, Spinner } from "@radix-ui/themes";
import { Suspense } from "react";
import { Base } from "../shared/base";
import { DjangoAdminLayout } from "../shared/django-admin-layout";
import { useCurrentConference } from "../utils/conference";
import { AddItemModalProvider } from "./add-item-modal/context";
import { Calendar } from "./calendar";
import { PendingItemsBasket } from "./pending-items-basket";
import { useConferenceScheduleQuery } from "./schedule.generated";
import {
useConferenceScheduleQuery,
useConferenceScheduleSuspenseQuery,
} from "./schedule.generated";

export const ScheduleBuilderRoot = ({
conferenceId,
Expand All @@ -21,7 +26,23 @@ export const ScheduleBuilderRoot = ({
>
<AddItemModalProvider>
<DjangoAdminLayout>
<ScheduleBuilder />
<Suspense
fallback={
<Flex
align="center"
justify="center"
width="100%"
height="100%"
position="absolute"
top="0"
left="0"
>
<Spinner size="3" />
</Flex>
}
>
<ScheduleBuilder />
</Suspense>
</DjangoAdminLayout>
</AddItemModalProvider>
</Base>
Expand All @@ -30,30 +51,28 @@ export const ScheduleBuilderRoot = ({

const ScheduleBuilder = () => {
const { conferenceCode } = useCurrentConference();
const { error, loading, data } = useConferenceScheduleQuery({
const { error, data } = useConferenceScheduleSuspenseQuery({
variables: {
conferenceCode,
},
});

const {
conference: { days },
} = data ?? { conference: {} };
} = data;

if (error) {
return (
<h2>Something went wrong. Make sure you have the right permissions.</h2>
);
}

return (
<>
{loading && <h2>Please wait</h2>}
{!loading && error && (
<h2>Something went wrong. Make sure you have the right permissions.</h2>
)}
{!loading && (
<>
{days.map((day) => (
<Calendar key={day.id} day={day} />
))}
<PendingItemsBasket />
</>
)}
{days.map((day) => (
<Calendar key={day.id} day={day} />
))}
<PendingItemsBasket />
</>
);
};

0 comments on commit b5be418

Please sign in to comment.