2025-02-06 08:11:47 -08:00
|
|
|
import { useMemo } from 'react';
|
|
|
|
|
|
|
|
|
|
import { MessageCircleDashed } from 'lucide-react';
|
|
|
|
|
import { useRecoilState, useRecoilValue } from 'recoil';
|
|
|
|
|
import { Constants, getConfigDefaults } from 'librechat-data-provider';
|
2025-02-06 19:30:15 +01:00
|
|
|
import { useGetStartupConfig } from '~/data-provider';
|
2025-02-06 08:11:47 -08:00
|
|
|
import { Switch } from '~/components/ui';
|
2025-02-07 02:15:38 +01:00
|
|
|
import { useLocalize } from '~/hooks';
|
2025-02-06 08:11:47 -08:00
|
|
|
import { cn } from '~/utils';
|
|
|
|
|
import store from '~/store';
|
|
|
|
|
|
|
|
|
|
export const TemporaryChat = () => {
|
2025-02-07 02:15:38 +01:00
|
|
|
const localize = useLocalize();
|
2025-02-06 08:11:47 -08:00
|
|
|
const { data: startupConfig } = useGetStartupConfig();
|
|
|
|
|
const defaultInterface = getConfigDefaults().interface;
|
2025-02-07 02:15:38 +01:00
|
|
|
const [isTemporary, setIsTemporary] = useRecoilState(store.isTemporary);
|
2025-02-06 08:11:47 -08:00
|
|
|
const conversation = useRecoilValue(store.conversationByIndex(0)) || undefined;
|
|
|
|
|
const conversationId = conversation?.conversationId ?? '';
|
|
|
|
|
const interfaceConfig = useMemo(
|
|
|
|
|
() => startupConfig?.interface ?? defaultInterface,
|
|
|
|
|
[startupConfig],
|
|
|
|
|
);
|
|
|
|
|
|
2025-02-07 02:15:38 +01:00
|
|
|
if (interfaceConfig.temporaryChat === false) {
|
2025-02-06 08:11:47 -08:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const isActiveConvo = Boolean(
|
|
|
|
|
conversation &&
|
|
|
|
|
conversationId &&
|
|
|
|
|
conversationId !== Constants.NEW_CONVO &&
|
|
|
|
|
conversationId !== 'search',
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const onClick = () => {
|
|
|
|
|
if (isActiveConvo) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
setIsTemporary(!isTemporary);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
2025-02-07 02:15:38 +01:00
|
|
|
<div className="sticky bottom-0 border-none bg-surface-tertiary px-6 py-4 ">
|
2025-02-06 08:11:47 -08:00
|
|
|
<div className="flex items-center">
|
|
|
|
|
<div className={cn('flex flex-1 items-center gap-2', isActiveConvo && 'opacity-40')}>
|
|
|
|
|
<MessageCircleDashed className="icon-sm" />
|
2025-02-07 02:15:38 +01:00
|
|
|
<span className="text-sm text-text-primary">{localize('com_ui_temporary_chat')}</span>
|
2025-02-06 08:11:47 -08:00
|
|
|
</div>
|
|
|
|
|
<div className="ml-auto flex items-center">
|
|
|
|
|
<Switch
|
2025-02-07 02:15:38 +01:00
|
|
|
id="temporary-chat-switch"
|
2025-02-06 08:11:47 -08:00
|
|
|
checked={isTemporary}
|
|
|
|
|
onCheckedChange={onClick}
|
|
|
|
|
disabled={isActiveConvo}
|
|
|
|
|
className="ml-4"
|
2025-02-07 02:15:38 +01:00
|
|
|
aria-label="Toggle temporary chat"
|
|
|
|
|
data-testid="temporary-chat-switch"
|
2025-02-06 08:11:47 -08:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|