mirror of
https://github.com/ItzCrazyKns/Perplexica.git
synced 2025-05-03 17:52:37 +00:00
feat(copilot): respect preferences
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
import { Switch } from '@headlessui/react';
|
import { Switch } from '@headlessui/react';
|
||||||
|
import { useEffect } from 'react';
|
||||||
|
|
||||||
const CopilotToggle = ({
|
const CopilotToggle = ({
|
||||||
copilotEnabled,
|
copilotEnabled,
|
||||||
@ -8,11 +9,33 @@ const CopilotToggle = ({
|
|||||||
copilotEnabled: boolean;
|
copilotEnabled: boolean;
|
||||||
setCopilotEnabled: (enabled: boolean) => void;
|
setCopilotEnabled: (enabled: boolean) => void;
|
||||||
}) => {
|
}) => {
|
||||||
|
const fetchAndSetCopilotEnabled = async () => {
|
||||||
|
const res = await fetch(
|
||||||
|
`${process.env.NEXT_PUBLIC_API_URL}/config/preferences`,
|
||||||
|
{
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const preferences = await res.json();
|
||||||
|
|
||||||
|
setCopilotEnabled(preferences.isCopilotEnabled);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetchAndSetCopilotEnabled();
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="group flex flex-row items-center space-x-1 active:scale-95 duration-200 transition cursor-pointer">
|
<div className="group flex flex-row items-center space-x-1 active:scale-95 duration-200 transition cursor-pointer">
|
||||||
<Switch
|
<Switch
|
||||||
checked={copilotEnabled}
|
checked={copilotEnabled}
|
||||||
onChange={setCopilotEnabled}
|
onChange={setCopilotEnabled}
|
||||||
|
disabled={true}
|
||||||
className="bg-light-secondary dark:bg-dark-secondary border border-light-200/70 dark:border-dark-200 relative inline-flex h-5 w-10 sm:h-6 sm:w-11 items-center rounded-full"
|
className="bg-light-secondary dark:bg-dark-secondary border border-light-200/70 dark:border-dark-200 relative inline-flex h-5 w-10 sm:h-6 sm:w-11 items-center rounded-full"
|
||||||
>
|
>
|
||||||
<span className="sr-only">Copilot</span>
|
<span className="sr-only">Copilot</span>
|
||||||
|
Reference in New Issue
Block a user