import { PropsWithChildren, ReactElement } from 'react'; import MultiSelectActions from './MultiSelectActions'; import Typography from '@mui/joy/Typography'; import { useAppDispatch, useAppSelector } from '../../store/hooks'; import { clearSelection, selectSelectedUrls, selectAutoComputeSimilarity, setAutoComputeSimilarity } from '../../store/uiSlice'; import { setSimilarUrlsAsync } from '../../store/windowsSlice'; import { useLiveQuery } from 'dexie-react-hooks'; import { addTag, fetchPages } from '../../db/pages'; import { faSquare, faSquareCheck, faSquareMinus } from '@fortawesome/free-regular-svg-icons'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { Stack, Button, Tooltip, Switch, } from '@mui/joy'; interface InspectorProps { onSelectAll?: () => void; } const Inspector = ({ children, onSelectAll, }: PropsWithChildren): ReactElement => { const dispatch = useAppDispatch(); const selectedUrls = useAppSelector(selectSelectedUrls); // const selectedPages = // useLiveQuery( // monitorAsync(() => selectPages(selectedUrls), 'Inspector selectPages'), // [selectedUrls] // ) || []; const autoComputeSimilarity = useAppSelector(selectAutoComputeSimilarity); return ( {children} Auto-compute Similar Pages { const checked = event.target.checked; dispatch(setAutoComputeSimilarity(checked)); if (checked && selectedUrls.length > 0) { dispatch(setSimilarUrlsAsync()); } }} /> Selection {onSelectAll && ( 0 ? "Clear Selection" : "Select All"} placement="top">
{ event.stopPropagation(); if (selectedUrls.length > 0) { dispatch(clearSelection()); } else { onSelectAll(); } }} > 0 ? faSquareMinus : faSquare} // Using minus for "clear all" concept if some selected, or check if we want check? User said "unselect all". // Actually user said "unselect all if anything is selected". So standard behavior for a bulk select is: // If anything selected -> Indeterminate (minus) or Checked -> Click -> Clear. // If nothing selected -> Unchecked -> Click -> Select All. // Since "Select All" selects *everything* (not just what's selected), showing 'checked' might be misleading if only 1 item is selected. // But "Indeterminate" (minus) is good for "some selected". style={{ fontSize: '1rem', color: 'var(--joy-palette-text-icon)' }} />
)} {onSelectAll && ( )}
addTag(selectedUrls, tag)} />
); }; export default Inspector;