App Store Search (#5704)

Co-authored-by: Alex van Andel <[email protected]>
Co-authored-by: Peer Richelsen <[email protected]>
Co-authored-by: Peer Richelsen <[email protected]>
This commit is contained in:
authored and GitHub committed 2022-11-30 20:51:44 +00:00
1 parent ef3ad36c2c
commit f1b92c49fc
13 files changed
+312 -58

No files matched your search

+33 -12
View File
@@ -6,7 +6,7 @@ import classNames from "@calcom/lib/classNames";
import { getErrorFromUnknown } from "@calcom/lib/errors";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { Alert, showToast, Skeleton, Tooltip, UnstyledSelect } from "../../..";
import { Alert, showToast, Icon, Skeleton, Tooltip, UnstyledSelect } from "../../..";
import { HintsOrErrors } from "./HintOrErrors";
import { Label } from "./Label";
@@ -44,9 +44,8 @@ type InputFieldProps = {
addOnLeading?: ReactNode;
addOnSuffix?: ReactNode;
inputIsFullWidth?: boolean;
/**@Default paddingX 12px */
addOnPadding?: number;
addOnFilled?: boolean;
addOnClassname?: string;
error?: string;
labelSrOnly?: boolean;
containerClassName?: string;
@@ -61,13 +60,15 @@ type AddonProps = {
isFilled?: boolean;
className?: string;
error?: boolean;
paddingX?: number;
};
const Addon = ({ isFilled, children, className, error, paddingX = 12 }: AddonProps) => (
const Addon = ({ isFilled, children, className, error }: AddonProps) => (
<div
style={{ padding: `0 ${paddingX}px` }}
className={classNames("addon-wrapper h-9 border border-gray-300", isFilled && "bg-gray-100", className)}>
className={classNames(
"addon-wrapper h-9 border border-gray-300 px-3",
isFilled && "bg-gray-100",
className
)}>
<div className={classNames("flex h-full flex-col justify-center text-sm", error && "text-red-900")}>
<span className="whitespace-nowrap py-2.5">{children}</span>
</div>
@@ -88,9 +89,10 @@ export const InputField = forwardRef<HTMLInputElement, InputFieldProps>(function
addOnLeading,
addOnSuffix,
addOnFilled = true,
addOnPadding,
addOnClassname,
inputIsFullWidth,
hint,
type,
hintErrors,
labelSrOnly,
containerClassName,
@@ -99,6 +101,8 @@ export const InputField = forwardRef<HTMLInputElement, InputFieldProps>(function
...passThrough
} = props;
const [inputValue, setInputValue] = useState<string>("");
return (
<div className={classNames(containerClassName)}>
{!!name && (
@@ -114,28 +118,45 @@ export const InputField = forwardRef<HTMLInputElement, InputFieldProps>(function
{addOnLeading || addOnSuffix ? (
<div className="relative mb-1 flex items-center rounded-md focus-within:outline-none focus-within:ring-2 focus-within:ring-neutral-800 focus-within:ring-offset-1">
{addOnLeading && (
<Addon isFilled={addOnFilled} className="rounded-l-md border-r-0" paddingX={addOnPadding}>
<Addon isFilled={addOnFilled} className={classNames("rounded-l-md border-r-0", addOnClassname)}>
{addOnLeading}
</Addon>
)}
<Input
id={id}
placeholder={placeholder}
{...passThrough}
{...(type == "search" && {
onChange: (e) => {
setInputValue(e.target.value);
props.onChange && props.onChange(e);
},
value: inputValue,
})}
isFullWidth={inputIsFullWidth}
className={classNames(
className,
addOnLeading && "rounded-l-none",
addOnSuffix && "rounded-r-none",
type === "search" && "pr-8",
"!my-0 !ring-0"
)}
{...passThrough}
ref={ref}
/>
{addOnSuffix && (
<Addon isFilled={addOnFilled} className="rounded-r-md border-l-0" paddingX={addOnPadding}>
<Addon isFilled={addOnFilled} className={classNames("rounded-r-md border-l-0", addOnClassname)}>
{addOnSuffix}
</Addon>
)}
{type === "search" && inputValue?.toString().length > 0 && (
<Icon.FiX
className="absolute right-2 top-2.5 h-4 w-4 cursor-pointer text-gray-500"
onClick={(e) => {
setInputValue("");
props.onChange && props.onChange(e as unknown as React.ChangeEvent<HTMLInputElement>);
}}
/>
)}
</div>
) : (
<Input
@@ -344,7 +365,7 @@ export const InputFieldWithSelect = forwardRef<
ref={ref}
{...props}
inputIsFullWidth={false}
addOnPadding={0}
addOnClassname="!px-0"
addOnSuffix={<UnstyledSelect {...props.selectProps} />}
/>
);
+1 -1
View File
@@ -15,7 +15,7 @@
"dependencies": {
"@calcom/lib": "*",
"@calcom/trpc": "*",
"@formkit/auto-animate": "^1.0.0-beta.1",
"@formkit/auto-animate": "^1.0.0-beta.5",
"@radix-ui/react-dialog": "^1.0.0",
"@radix-ui/react-portal": "^1.0.0",
"@radix-ui/react-select": "^0.1.1",
+3
View File
@@ -183,6 +183,8 @@ type LayoutProps = {
withoutMain?: boolean;
// Gives you the option to skip HeadSEO and render your own.
withoutSeo?: boolean;
// Gives the ability to include actions to the right of the heading
actions?: JSX.Element;
};
const CustomBrandingContainer = () => {
@@ -840,6 +842,7 @@ export function ShellMain(props: LayoutProps) {
{props.CTA}
</div>
)}
{props.actions && props.actions}
</header>
)}
</div>
+34 -23
View File
@@ -36,14 +36,15 @@ export function useShouldShowArrows() {
return { ref, calculateScroll, leftVisible: showArrowScroll.left, rightVisible: showArrowScroll.right };
}
type AllAppsPropsType = { apps: (App & { credentials: Credential[] | undefined })[] };
type AllAppsPropsType = { apps: (App & { credentials: Credential[] | undefined })[]; searchText?: string };
interface CategoryTabProps {
selectedCategory: string | null;
categories: string[];
searchText?: string;
}
function CategoryTab({ selectedCategory, categories }: CategoryTabProps) {
function CategoryTab({ selectedCategory, categories, searchText }: CategoryTabProps) {
const { t } = useLocale();
const router = useRouter();
const { ref, calculateScroll, leftVisible, rightVisible } = useShouldShowArrows();
@@ -60,12 +61,14 @@ function CategoryTab({ selectedCategory, categories }: CategoryTabProps) {
};
return (
<div className="relative mb-4 flex flex-col justify-between lg:flex-row lg:items-center">
<h2 className="text-lg font-semibold text-gray-900 ">
{t("explore_apps", {
category:
(selectedCategory && selectedCategory[0].toUpperCase() + selectedCategory.slice(1)) ||
t("all_apps"),
})}
<h2 className="hidden text-lg font-semibold text-gray-900 sm:block">
{searchText
? t("search")
: t("explore_apps", {
category:
(selectedCategory && selectedCategory[0].toUpperCase() + selectedCategory.slice(1)) ||
t("all_apps"),
})}
</h2>
{leftVisible && (
<button onClick={handleLeft} className="absolute top-9 flex md:left-1/2 md:-top-1">
@@ -121,11 +124,11 @@ function CategoryTab({ selectedCategory, categories }: CategoryTabProps) {
);
}
export default function AllApps({ apps }: AllAppsPropsType) {
export default function AllApps({ apps, searchText }: AllAppsPropsType) {
const router = useRouter();
const { t } = useLocale();
const [selectedCategory, setSelectedCategory] = useState<string | null>(null);
const [appsContainerRef] = useAutoAnimate<HTMLDivElement>();
const [appsContainerRef, enableAnimation] = useAutoAnimate<HTMLDivElement>();
const categories = apps
.map((app) => app.category)
@@ -133,6 +136,10 @@ export default function AllApps({ apps }: AllAppsPropsType) {
return self.indexOf(cat) === pos;
});
if (searchText) {
enableAnimation(false);
}
useEffect(() => {
const queryCategory =
typeof router.query.category === "string" && categories.includes(router.query.category)
@@ -141,23 +148,27 @@ export default function AllApps({ apps }: AllAppsPropsType) {
setSelectedCategory(queryCategory);
}, [router.query.category]);
const filteredApps = apps
.filter((app) =>
selectedCategory !== null
? app.categories
? app.categories.includes(selectedCategory)
: app.category === selectedCategory
: true
)
.filter((app) => (searchText ? app.name.toLowerCase().includes(searchText.toLowerCase()) : true));
return (
<div className="mb-16">
<CategoryTab selectedCategory={selectedCategory} categories={categories} />
<CategoryTab selectedCategory={selectedCategory} searchText={searchText} categories={categories} />
<div
className="grid gap-3 lg:grid-cols-4 [@media(max-width:1270px)]:grid-cols-3 [@media(max-width:730px)]:grid-cols-2 [@media(max-width:500px)]:grid-cols-1"
ref={appsContainerRef}>
{apps
.filter((app) =>
selectedCategory !== null
? app.categories
? app.categories.includes(selectedCategory)
: app.category === selectedCategory
: true
)
.map((app) => (
<AppCard key={app.name} app={app} credentials={app.credentials} />
))}
{filteredApps.length
? filteredApps.map((app) => (
<AppCard key={app.name} app={app} searchText={searchText} credentials={app.credentials} />
))
: t("no_results")}
</div>
</div>
);
+21 -2
View File
@@ -1,5 +1,6 @@
import type { Credential } from "@prisma/client";
import { useRouter } from "next/router";
import { useEffect, useState } from "react";
import useAddAppMutation from "@calcom/app-store/_utils/useAddAppMutation";
import { InstallAppButton } from "@calcom/app-store/components";
@@ -12,9 +13,10 @@ import { showToast } from "../notifications";
interface AppCardProps {
app: App;
credentials?: Credential[];
searchText?: string;
}
export default function AppCard({ app, credentials }: AppCardProps) {
export default function AppCard({ app, credentials, searchText }: AppCardProps) {
const { t } = useLocale();
const router = useRouter();
const mutation = useAddAppMutation(null, {
@@ -31,6 +33,11 @@ export default function AppCard({ app, credentials }: AppCardProps) {
const allowedMultipleInstalls = app.categories && app.categories.indexOf("calendar") > -1;
const appAdded = (credentials && credentials.length) || 0;
const [searchTextIndex, setSearchTextIndex] = useState<number | undefined>(undefined);
useEffect(() => {
setSearchTextIndex(searchText ? app.name.toLowerCase().indexOf(searchText.toLowerCase()) : undefined);
}, [app.name, searchText]);
return (
<div className="relative flex h-64 flex-col rounded-md border border-gray-300 p-5">
@@ -38,7 +45,19 @@ export default function AppCard({ app, credentials }: AppCardProps) {
<img src={app.logo} alt={app.name + " Logo"} className="mb-4 h-12 w-12 rounded-sm" />
</div>
<div className="flex items-center">
<h3 className="font-medium">{app.name}</h3>
<h3 className="font-medium">
{searchTextIndex != undefined && searchText ? (
<>
{app.name.substring(0, searchTextIndex)}
<span className="bg-yellow-300">
{app.name.substring(searchTextIndex, searchTextIndex + searchText.length)}
</span>
{app.name.substring(searchTextIndex + searchText.length)}
</>
) : (
app.name
)}
</h3>
</div>
{/* TODO: add reviews <div className="flex text-sm text-gray-800">
<span>{props.rating} stars</span> <StarIcon className="ml-1 mt-0.5 h-4 w-4 text-yellow-600" />
+9 -7
View File
@@ -15,15 +15,17 @@ const tabs: HorizontalTabItemProps[] = [
},
];
export default function AppsLayout({
children,
...rest
}: { children: React.ReactNode } & ComponentProps<typeof Shell>) {
type AppsLayoutProps = {
children: React.ReactNode;
actions?: (className?: string) => JSX.Element;
} & Omit<ComponentProps<typeof Shell>, "actions">;
export default function AppsLayout({ children, actions, ...rest }: AppsLayoutProps) {
return (
<Shell {...rest}>
<div className="flex flex-col xl:flex-row ">
<Shell {...rest} actions={actions?.("hidden sm:block")}>
<div className="flex flex-col xl:flex-row">
<div className="block lg:hidden">
<HorizontalTabs tabs={tabs} />
<HorizontalTabs tabs={tabs} actions={actions?.("ml-6 mr-4 mt-3 block sm:hidden")} />
</div>
<main className="w-full">{children}</main>
</div>
@@ -5,9 +5,10 @@ export { HorizontalTabItem };
export interface NavTabProps {
tabs: HorizontalTabItemProps[];
linkProps?: HorizontalTabItemProps["linkProps"];
actions?: JSX.Element;
}
const HorizontalTabs = function ({ tabs, linkProps, ...props }: NavTabProps) {
const HorizontalTabs = function ({ tabs, linkProps, actions, ...props }: NavTabProps) {
return (
<div className="-mx-6 mb-2 w-[calc(100%+40px)]">
<nav
@@ -18,6 +19,7 @@ const HorizontalTabs = function ({ tabs, linkProps, ...props }: NavTabProps) {
<HorizontalTabItem {...tab} key={idx} {...linkProps} />
))}
</nav>
{actions && actions}
</div>
);
};