Perplexica/ui/components/MessageInputActions/Focus.tsx

172 lines
5 KiB
TypeScript
Raw Normal View History

2024-04-13 12:11:47 +05:30
import {
2025-02-02 16:38:57 -10:00
BadgePercent, Calculator,
ChevronDown,
2024-04-13 12:11:47 +05:30
Globe,
Pencil,
ScanEye,
SwatchBook,
} from 'lucide-react';
2024-04-09 16:21:05 +05:30
import { cn } from '@/lib/utils';
2024-10-11 10:35:33 +05:30
import {
Popover,
PopoverButton,
PopoverPanel,
Transition,
} from '@headlessui/react';
2025-02-02 16:38:57 -10:00
import {SiGoogletranslate, SiReddit, SiYoutube} from '@icons-pack/react-simple-icons';
2024-04-13 12:11:47 +05:30
import { Fragment } from 'react';
2025-02-02 16:53:40 -10:00
import DeepSeekIcon from "@/assets/DeepSeekIcon";
2024-04-09 16:21:05 +05:30
2024-04-13 12:11:47 +05:30
const focusModes = [
{
key: 'webSearch',
2025-02-02 16:54:31 -10:00
title: 'Search',
2024-04-13 12:11:47 +05:30
description: 'Searches across all of the internet',
icon: <Globe size={20} />,
},
{
key: 'academicSearch',
title: 'Academic',
description: 'Search in published academic papers',
icon: <SwatchBook size={20} />,
},
2025-02-02 16:38:57 -10:00
{
key: 'wolframAlphaSearch',
title: 'Wolfram Alpha',
description: 'Computational knowledge engine',
icon: <BadgePercent size={20} />,
},
2024-04-13 12:11:47 +05:30
{
key: 'writingAssistant',
title: 'Writing',
description: 'Chat without searching the web',
icon: <Pencil size={16} />,
2024-04-13 12:11:47 +05:30
},
{
2025-02-02 16:38:57 -10:00
key: 'mathAssistant',
title: 'Math',
description: 'Chat without searching the web',
icon: <Calculator size={25} />,
2024-04-13 12:11:47 +05:30
},
2025-02-02 16:38:57 -10:00
{
key: 'translator',
2025-02-03 01:27:27 -10:00
title: 'Translator',
2025-02-02 16:38:57 -10:00
description: 'Chat without searching the web',
icon: (
<SiGoogletranslate
className="h-5 w-auto mr-0.5"
onPointerEnterCapture={undefined}
onPointerLeaveCapture={undefined}
/>
),
},
2024-04-13 12:11:47 +05:30
{
key: 'youtubeSearch',
title: 'Youtube',
description: 'Search and watch videos',
icon: (
<SiYoutube
className="h-5 w-auto mr-0.5"
onPointerEnterCapture={undefined}
onPointerLeaveCapture={undefined}
/>
),
},
{
key: 'redditSearch',
title: 'Reddit',
description: 'Search for discussions and opinions',
icon: (
<SiReddit
className="h-5 w-auto mr-0.5"
onPointerEnterCapture={undefined}
onPointerLeaveCapture={undefined}
/>
),
},
2025-02-02 16:53:40 -10:00
{
key: 'deepSeek',
title: 'DeepSeek',
description: 'Chat with DeepSeek',
icon: (
<DeepSeekIcon className="h-8 w-auto mr-0.5" />
),
},
2024-04-13 12:11:47 +05:30
];
const Focus = ({
2024-04-13 12:11:47 +05:30
focusMode,
setFocusMode,
}: {
focusMode: string;
setFocusMode: (mode: string) => void;
}) => {
2024-04-09 16:21:05 +05:30
return (
2024-11-23 15:04:19 +05:30
<Popover className="relative w-full max-w-[15rem] md:max-w-md lg:max-w-lg mt-[6.5px]">
2024-10-11 10:35:33 +05:30
<PopoverButton
2024-04-13 12:11:47 +05:30
type="button"
2024-10-11 10:35:33 +05:30
className=" text-black/50 dark:text-white/50 rounded-xl hover:bg-light-secondary dark:hover:bg-dark-secondary active:scale-95 transition duration-200 hover:text-black dark:hover:text-white"
2024-04-13 12:11:47 +05:30
>
{focusMode !== 'webSearch' ? (
<div className="flex flex-row items-center space-x-1">
{focusModes.find((mode) => mode.key === focusMode)?.icon}
2025-02-03 08:48:19 -10:00
<p className="text-xs font-medium">
{focusModes.find((mode) => mode.key === focusMode)?.title}
</p>
2024-11-23 15:04:19 +05:30
<ChevronDown size={20} className="-translate-x-1" />
</div>
) : (
2024-11-23 15:04:19 +05:30
<div className="flex flex-row items-center space-x-1">
<ScanEye size={20} />
2025-02-03 08:48:19 -10:00
<p className="text-xs font-medium">Focus</p>
2024-11-23 15:04:19 +05:30
</div>
)}
2024-10-11 10:35:33 +05:30
</PopoverButton>
2024-04-13 12:11:47 +05:30
<Transition
as={Fragment}
enter="transition ease-out duration-150"
enterFrom="opacity-0 translate-y-1"
enterTo="opacity-100 translate-y-0"
leave="transition ease-in duration-150"
leaveFrom="opacity-100 translate-y-0"
leaveTo="opacity-0 translate-y-1"
>
2024-10-11 10:35:33 +05:30
<PopoverPanel className="absolute z-10 w-64 md:w-[500px] left-0">
2025-02-03 14:45:45 -10:00
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-2 bg-light-primary dark:bg-dark-primary border rounded-lg border-light-200 dark:border-dark-200 w-full p-4 max-h-[calc(100vh-6rem)] md:max-h-none overflow-y-auto pb-20">
2024-04-13 12:11:47 +05:30
{focusModes.map((mode, i) => (
2024-10-11 10:35:33 +05:30
<PopoverButton
2024-04-13 12:11:47 +05:30
onClick={() => setFocusMode(mode.key)}
key={i}
className={cn(
'p-2 rounded-lg flex flex-col items-start justify-start text-start space-y-2 duration-200 cursor-pointer transition',
focusMode === mode.key
? 'bg-light-secondary dark:bg-dark-secondary'
: 'hover:bg-light-secondary dark:hover:bg-dark-secondary',
2024-04-13 12:11:47 +05:30
)}
>
<div
className={cn(
'flex flex-row items-center space-x-1',
2024-05-24 20:29:49 +08:00
focusMode === mode.key
? 'text-[#24A0ED]'
: 'text-black dark:text-white',
2024-04-13 12:11:47 +05:30
)}
>
{mode.icon}
<p className="text-sm font-medium">{mode.title}</p>
</div>
2024-05-24 20:29:49 +08:00
<p className="text-black/70 dark:text-white/70 text-xs">
{mode.description}
</p>
2024-10-11 10:35:33 +05:30
</PopoverButton>
2024-04-13 12:11:47 +05:30
))}
</div>
2024-10-11 10:35:33 +05:30
</PopoverPanel>
2024-04-13 12:11:47 +05:30
</Transition>
</Popover>
2024-04-09 16:21:05 +05:30
);
};
export default Focus;