import { FolderIcon, PhotoIcon } from '@heroicons/react/24/outline' import { PlayIcon, ReloadIcon } from '@radix-ui/react-icons' import React, { useCallback, useState } from 'react' import { useRecoilState, useRecoilValue } from 'recoil' import * as PopoverPrimitive from '@radix-ui/react-popover' import { enableFileManagerState, fileState, isInpaintingState, isPix2PixState, isSDState, maskState, runManuallyState, showFileManagerState, } from '../../store/Atoms' import Button from '../shared/Button' import Shortcuts from '../Shortcuts/Shortcuts' import { ThemeChanger } from './ThemeChanger' import SettingIcon from '../Settings/SettingIcon' import PromptInput from './PromptInput' import CoffeeIcon from '../CoffeeIcon/CoffeeIcon' import emitter, { EVENT_CUSTOM_MASK, RERUN_LAST_MASK } from '../../event' import { useImage } from '../../utils' import useHotKey from '../../hooks/useHotkey' const Header = () => { const isInpainting = useRecoilValue(isInpaintingState) const [file, setFile] = useRecoilState(fileState) const [mask, setMask] = useRecoilState(maskState) const [maskImage, maskImageLoaded] = useImage(mask) const [uploadElemId] = useState(`file-upload-${Math.random().toString()}`) const [maskUploadElemId] = useState(`mask-upload-${Math.random().toString()}`) const isSD = useRecoilValue(isSDState) const isPix2Pix = useRecoilValue(isPix2PixState) const runManually = useRecoilValue(runManuallyState) const [openMaskPopover, setOpenMaskPopover] = useState(false) const [showFileManager, setShowFileManager] = useRecoilState(showFileManagerState) const enableFileManager = useRecoilValue(enableFileManagerState) useHotKey( 'f', () => { if (enableFileManager && !isInpainting) { setShowFileManager(!showFileManager) } }, {}, [showFileManager, enableFileManager, isInpainting] ) const handleRerunLastMask = useCallback(() => { emitter.emit(RERUN_LAST_MASK) }, []) useHotKey( 'r', () => { if (!isInpainting) { handleRerunLastMask() } }, {}, [isInpainting, handleRerunLastMask] ) const renderHeader = () => { return (
{enableFileManager ? (
{mask ? ( setOpenMaskPopover(true)} onMouseLeave={() => setOpenMaskPopover(false)} style={{ visibility: mask ? 'visible' : 'hidden', outline: 'none', }} onClick={() => { if (mask) { emitter.emit(EVENT_CUSTOM_MASK, { mask }) } }} > {maskImageLoaded ? ( mask ) : ( <> )} ) : ( <> )}
{(isSD || isPix2Pix) && file ? : <>}
) } return renderHeader() } export default Header