import { useEffect, useState } from 'react'; import StorageUtils from '../utils/storage'; import { useAppContext } from '../utils/app.context'; import { classNames } from '../utils/misc'; import daisyuiThemes from 'daisyui/theme/object'; import { THEMES } from '../Config'; import { useNavigate } from 'react-router'; import toast from 'react-hot-toast'; import { useModals } from './ModalProvider'; import { ArrowUpTrayIcon, ArrowDownTrayIcon, PencilIcon, TrashIcon, } from '@heroicons/react/24/outline'; export default function Header() { const navigate = useNavigate(); const [selectedTheme, setSelectedTheme] = useState(StorageUtils.getTheme()); const { setShowSettings } = useAppContext(); const setTheme = (theme: string) => { StorageUtils.setTheme(theme); setSelectedTheme(theme); }; useEffect(() => { document.body.setAttribute('data-theme', selectedTheme); document.body.setAttribute( 'data-color-scheme', daisyuiThemes[selectedTheme]?.['color-scheme'] ?? 'auto' ); }, [selectedTheme]); const {showPrompt } = useModals(); const { isGenerating, viewingChat } = useAppContext(); const isCurrConvGenerating = isGenerating(viewingChat?.conv.id ?? ''); // remove conversation const removeConversation = () => { if (isCurrConvGenerating || !viewingChat) return; const convId = viewingChat?.conv.id; if (window.confirm('Are you sure to delete this conversation?')) { StorageUtils.remove(convId); navigate('/'); } }; // rename conversation async function renameConversation() { if (isGenerating(viewingChat?.conv.id ?? '')) { toast.error( 'Cannot rename conversation while generating' ); return; } const newName = await showPrompt( 'Enter new name for the conversation', viewingChat?.conv.name ); if (newName && newName.trim().length > 0) { StorageUtils.updateConversationName(viewingChat?.conv.id ?? '', newName); } //const importedConv = await StorageUtils.updateConversationName(); //if (importedConv) { //console.log('Successfully imported:', importedConv.name); // Refresh UI or navigate to conversation //} }; // at the top of your file, alongside ConversationExport: async function importConversation() { const importedConv = await StorageUtils.importConversationFromFile(); if (importedConv) { console.log('Successfully imported:', importedConv.name); // Refresh UI or navigate to conversation } }; const downloadConversation = () => { if (isCurrConvGenerating || !viewingChat) return; const convId = viewingChat?.conv.id; const conversationJson = JSON.stringify(viewingChat, null, 2); const blob = new Blob([conversationJson], { type: 'application/json' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = `conversation_${convId}.json`; document.body.appendChild(a); a.click(); document.body.removeChild(a); URL.revokeObjectURL(url); }; return (
{/* open sidebar button */}
ik_llama.cpp
{/* action buttons (top right) */}
{viewingChat && (
{/* "..." button */} {/* dropdown menu */}
)}
{/* theme controller is copied from https://daisyui.com/components/theme-controller/ */}
  • {THEMES.map((theme) => (
  • e.target.checked && setTheme(theme)} />
  • ))}
); }