* Icon and IconName * Button and ButtonGroup * UserAvatar * AvatarGroup * Avatar * WizardLayout * Dialogs * EmptyScreen * showToast and TextField * Editor * Skeleton * Skeleton * TopBanner and showToast * Button again * more * perf: Remove app-store reference from @calcom/ui * more * Fixing types * Icon * Fixed casing * dropdown * more * Select * more * Badge * List * more * Divider * more * fix * fix type check * refactor * fix * fix * fix * fix * fix * fix * fix * fix type check * fix * fix * fix * fix * more * more * more * more * add index file to components/command * fix * fix * fix * fix imports * fix * fix * fix * fix * fix * fix * fix * fix build errors * fix build errors * fix --------- Co-authored-by: Keith Williams <keithwillcode@gmail.com>
49 lines
1.7 KiB
TypeScript
49 lines
1.7 KiB
TypeScript
"use client";
|
|
|
|
import { usePathname, useRouter } from "next/navigation";
|
|
import { useEffect, useRef, useState } from "react";
|
|
import { z } from "zod";
|
|
|
|
import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams";
|
|
import { useTypedQuery } from "@calcom/lib/hooks/useTypedQuery";
|
|
import { AppListCard } from "@calcom/ui/components/app-list-card";
|
|
import type { AppListCardProps } from "@calcom/ui/components/app-list-card";
|
|
|
|
const schema = z.object({ hl: z.string().optional() });
|
|
|
|
export default function AppListCardWebWrapper(props: AppListCardProps) {
|
|
const { slug, shouldHighlight } = props;
|
|
const {
|
|
data: { hl },
|
|
} = useTypedQuery(schema);
|
|
const router = useRouter();
|
|
const [highlight, setHighlight] = useState(shouldHighlight && hl === slug);
|
|
const timeoutRef = useRef<NodeJS.Timeout | null>(null);
|
|
const searchParams = useCompatSearchParams();
|
|
const pathname = usePathname();
|
|
|
|
useEffect(() => {
|
|
if (shouldHighlight && highlight && searchParams !== null && pathname !== null) {
|
|
timeoutRef.current = setTimeout(() => {
|
|
const _searchParams = new URLSearchParams(searchParams.toString());
|
|
_searchParams.delete("hl");
|
|
_searchParams.delete("category"); // this comes from params, not from search params
|
|
|
|
setHighlight(false);
|
|
|
|
const stringifiedSearchParams = _searchParams.toString();
|
|
|
|
router.replace(`${pathname}${stringifiedSearchParams !== "" ? `?${stringifiedSearchParams}` : ""}`);
|
|
}, 3000);
|
|
}
|
|
return () => {
|
|
if (timeoutRef.current) {
|
|
clearTimeout(timeoutRef.current);
|
|
timeoutRef.current = null;
|
|
}
|
|
};
|
|
}, [highlight, pathname, router, searchParams, shouldHighlight]);
|
|
|
|
return <AppListCard {...props} />;
|
|
}
|