|
1 | 1 | "use client";
|
2 | 2 |
|
3 |
| -import { usePathname, useRouter } from "next/navigation"; |
4 |
| -import type { ReactNode } from "react"; |
5 |
| -import { useEffect, useRef, useState } from "react"; |
6 |
| -import { z } from "zod"; |
| 3 | +import dynamic from "next/dynamic"; |
| 4 | +import { useMemo } from "react"; |
7 | 5 |
|
8 |
| -import type { CredentialOwner } from "@calcom/app-store/types"; |
9 | 6 | import { useIsPlatform } from "@calcom/atoms/hooks/useIsPlatform";
|
10 |
| -import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams"; |
11 |
| -import { useTypedQuery } from "@calcom/lib/hooks/useTypedQuery"; |
12 |
| -import { AppListCard as AppListCardComponent } from "@calcom/ui"; |
13 |
| - |
14 |
| -type ShouldHighlight = |
15 |
| - | { |
16 |
| - slug: string; |
17 |
| - shouldHighlight: true; |
18 |
| - } |
19 |
| - | { |
20 |
| - shouldHighlight?: never; |
21 |
| - slug?: never; |
22 |
| - }; |
23 |
| - |
24 |
| -export type AppListCardProps = { |
25 |
| - logo?: string; |
26 |
| - title: string; |
27 |
| - description: string; |
28 |
| - actions?: ReactNode; |
29 |
| - isDefault?: boolean; |
30 |
| - isTemplate?: boolean; |
31 |
| - invalidCredential?: boolean; |
32 |
| - children?: ReactNode; |
33 |
| - credentialOwner?: CredentialOwner; |
34 |
| - className?: string; |
35 |
| -} & ShouldHighlight; |
36 |
| - |
37 |
| -const schema = z.object({ hl: z.string().optional() }); |
38 |
| - |
39 |
| -function AppListCardPlatformWrapper(props: AppListCardProps) { |
40 |
| - const logo = `https://app.cal.com${props.logo}`; |
41 |
| - return <AppListCardComponent {...props} logo={logo} />; |
42 |
| -} |
43 |
| -function AppListCardWebWrapper(props: AppListCardProps) { |
44 |
| - const { slug, shouldHighlight } = props; |
45 |
| - const { |
46 |
| - data: { hl }, |
47 |
| - } = useTypedQuery(schema); |
48 |
| - const router = useRouter(); |
49 |
| - const [highlight, setHighlight] = useState(shouldHighlight && hl === slug); |
50 |
| - const timeoutRef = useRef<NodeJS.Timeout | null>(null); |
51 |
| - const searchParams = useCompatSearchParams(); |
52 |
| - const pathname = usePathname(); |
53 |
| - |
54 |
| - useEffect(() => { |
55 |
| - if (shouldHighlight && highlight && searchParams !== null && pathname !== null) { |
56 |
| - timeoutRef.current = setTimeout(() => { |
57 |
| - const _searchParams = new URLSearchParams(searchParams.toString()); |
58 |
| - _searchParams.delete("hl"); |
59 |
| - _searchParams.delete("category"); // this comes from params, not from search params |
60 |
| - |
61 |
| - setHighlight(false); |
62 |
| - |
63 |
| - const stringifiedSearchParams = _searchParams.toString(); |
64 |
| - |
65 |
| - router.replace(`${pathname}${stringifiedSearchParams !== "" ? `?${stringifiedSearchParams}` : ""}`); |
66 |
| - }, 3000); |
67 |
| - } |
68 |
| - return () => { |
69 |
| - if (timeoutRef.current) { |
70 |
| - clearTimeout(timeoutRef.current); |
71 |
| - timeoutRef.current = null; |
72 |
| - } |
73 |
| - }; |
74 |
| - }, [highlight, pathname, router, searchParams, shouldHighlight]); |
75 |
| - |
76 |
| - return <AppListCardComponent {...props} />; |
77 |
| -} |
| 7 | +import type { AppListCardProps } from "@calcom/ui/components/app-list-card/AppListCard"; |
78 | 8 |
|
79 | 9 | export default function AppListCard(props: AppListCardProps) {
|
80 | 10 | const isPlatform = useIsPlatform();
|
81 |
| - return isPlatform ? <AppListCardPlatformWrapper {...props} /> : <AppListCardWebWrapper {...props} />; |
| 11 | + |
| 12 | + // Dynamically import the correct wrapper |
| 13 | + const AppListCardWrapper = useMemo( |
| 14 | + () => |
| 15 | + dynamic( |
| 16 | + () => (isPlatform ? import("./AppListCardPlatformWrapper") : import("./AppListCardWebWrapper")), |
| 17 | + { |
| 18 | + ssr: false, // Prevents SSR issues if needed |
| 19 | + } |
| 20 | + ), |
| 21 | + [isPlatform] |
| 22 | + ); |
| 23 | + |
| 24 | + return <AppListCardWrapper {...props} />; |
82 | 25 | }
|
0 commit comments