Skip to content

Commit e07cc16

Browse files
committed
destructure
1 parent dd22357 commit e07cc16

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

frontend/app/src/entities/events/api/get-events.query.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import { getCurrentBranchName } from "@/entities/branches/domain/get-current-bra
22
import { store } from "@/shared/stores";
33
import { datetimeAtom } from "@/shared/stores/time.atom";
44
import { queryOptions, useQuery } from "@tanstack/react-query";
5-
import { getEventsFromApi } from "./get-events";
5+
import { EventType } from "../ui/event";
6+
import { INFRAHUB_EVENT } from "../utils/constants";
7+
import { getEventsFromApi } from "./get-events-from-api";
68

79
export function getEventsQueryOptions({
810
ids,
@@ -34,5 +36,17 @@ export const useEvents = ({
3436
limit,
3537
search,
3638
}: { ids?: Array<string | undefined>; offset?: number; limit?: number; search?: string }) => {
37-
return useQuery(getEventsQueryOptions({ ids, offset, limit, search }));
39+
const { data } = useQuery(getEventsQueryOptions({ ids, offset, limit, search }));
40+
41+
const activities: EventType[] = data?.data?.[INFRAHUB_EVENT]?.edges?.map((edge) => {
42+
return edge.node;
43+
});
44+
45+
const count = data?.data?.[INFRAHUB_EVENT]?.count;
46+
47+
return {
48+
...useQuery(getEventsQueryOptions({ ids, offset, limit, search })),
49+
data: activities,
50+
count,
51+
};
3852
};

frontend/app/src/entities/events/ui/global-events.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,17 @@ import { Spinner } from "@/shared/components/ui/spinner";
88
import usePagination from "@/shared/hooks/usePagination";
99
import useSearch from "@/shared/hooks/useSearch";
1010
import { useEvents } from "../api/get-events.query";
11-
import { INFRAHUB_EVENT } from "../utils/constants";
12-
import { EventType } from "./event";
1311
import { Event } from "./global-event";
1412

1513
export const GlobalEvents = () => {
1614
const [pagination] = usePagination();
1715
const [search] = useSearch();
18-
const { isLoading, data, error, refetch } = useEvents({ ...pagination, search });
16+
const { isLoading, data, count, error, refetch } = useEvents({ ...pagination, search });
1917

2018
if (error) {
2119
return <ErrorFallback error={error} />;
2220
}
2321

24-
const activities: EventType[] = data?.data?.[INFRAHUB_EVENT]?.edges?.map((edge) => {
25-
return edge.node;
26-
});
27-
28-
const count = data?.data?.[INFRAHUB_EVENT]?.count;
29-
3022
return (
3123
<Content.Card>
3224
<Content.CardTitle
@@ -43,9 +35,9 @@ export const GlobalEvents = () => {
4335
</div>
4436

4537
<div className="flex flex-col gap-2">
46-
{!isLoading && !activities?.length && <NoDataFound message="No activity found." />}
38+
{!isLoading && !data?.length && <NoDataFound message="No activity found." />}
4739

48-
{activities?.map((activity) => (
40+
{data?.map((activity) => (
4941
<Event key={activity.id} {...activity} />
5042
))}
5143
</div>

0 commit comments

Comments
 (0)