From 3897f82261a50ed332aa17cd2c78f4d4df0fc970 Mon Sep 17 00:00:00 2001 From: "Thomas F. K. Jorna" Date: Tue, 21 Sep 2021 19:46:23 +0200 Subject: chore: move filter panel to separate component --- components/tweaks.tsx | 319 ++------------------------------------------------ 1 file changed, 11 insertions(+), 308 deletions(-) (limited to 'components') diff --git a/components/tweaks.tsx b/components/tweaks.tsx index f03339b..2cb5b5d 100644 --- a/components/tweaks.tsx +++ b/components/tweaks.tsx @@ -57,6 +57,8 @@ import { colorList, } from './config' +import FilterPanel from './FilterPanel' + import { ThemeContext } from '../util/themecontext' import { usePersistantState } from '../util/persistant-state' @@ -194,138 +196,15 @@ export const Tweaks = (props: TweakProps) => { Filter - } - align="stretch" - paddingLeft={7} - color="gray.800" - > - - Link children to... - - } - colorScheme="" - color="black" - > - {(() => { - switch (filter.parent) { - case 'parent': - return File - case 'heading': - return Heading - default: - return Nothing - } - })()} - - - {' '} - - - setFilter((curr: typeof initialFilter) => ({ ...curr, parent: '' })) - } - > - Nothing - - - setFilter((curr: typeof initialFilter) => ({ - ...curr, - parent: 'parent', - })) - } - > - Parent file node - - - setFilter((curr: typeof initialFilter) => ({ - ...curr, - parent: 'heading', - })) - } - > - Next highest heading node - - - - - - - Orphans - { - setFilter((curr: typeof initialFilter) => { - return { ...curr, orphans: !curr.orphans } - }) - }} - isChecked={filter.orphans} - > - - - Citations without note files - { - setFilter({ ...filter, filelessCites: !filter.filelessCites }) - }} - isChecked={filter.filelessCites} - > - - - Non-existant nodes - { - setTagColors({ ...tagColors, bad: 'white' }) - setFilter({ ...filter, bad: !filter.bad }) - }} - isChecked={filter.bad} - > - - - - - - Tag filters - - - - - - - - - - Tag Colors - - - - - - - + @@ -1540,179 +1419,3 @@ export const ColorMenu = (props: ColorMenuProps) => { ) } - -export interface TagPanelProps { - tags: string[] - filter: typeof initialFilter - setFilter: any - highlightColor: string - mode: string -} - -export const TagPanel = (props: TagPanelProps) => { - const { filter, setFilter, tags, highlightColor, mode } = props - const tagArray = tags.map((tag) => { - return { value: tag, label: tag } - }) - - const currentTags = mode === 'blacklist' ? 'tagsBlacklist' : 'tagsWhitelist' - const [selectedItems, setSelectedItems] = useState( - filter[currentTags].map((tag) => { - return { value: tag, label: tag } - }), - ) - - return ( - null} - disableCreateItem={true} - selectedItems={selectedItems} - onSelectedItemsChange={(changes) => { - if (changes.selectedItems) { - setSelectedItems(changes.selectedItems) - setFilter({ ...filter, [currentTags]: changes.selectedItems.map((item) => item.value) }) - } - }} - listItemStyleProps={{ overflow: 'hidden' }} - highlightItemBg="gray.400" - toggleButtonStyleProps={{ variant: 'outline' }} - inputStyleProps={{ - focusBorderColor: highlightColor, - color: 'gray.800', - borderColor: 'gray.600', - }} - tagStyleProps={{ - rounded: 'full', - bg: highlightColor, - height: 8, - paddingLeft: 4, - fontWeight: 'bold', - }} - hideToggleButton - itemRenderer={(selected) => selected.label} - /> - ) -} - -export interface TagColorPanelProps { - tags: string[] - highlightColor: string - colorList: string[] - tagColors: TagColors - setTagColors: any -} -export const TagColorPanel = (props: TagColorPanelProps) => { - const { colorList, tagColors, setTagColors, highlightColor, tags } = props - const tagArray = tags.map((tag) => { - return { value: tag, label: tag } - }) - - const [selectedItems, setSelectedItems] = useState( - Object.keys(tagColors).map((tag) => { - return { value: tag, label: tag } - }), - ) - - return ( - - { - if (changes.selectedItems) { - setSelectedItems(Array.from(new Set(changes.selectedItems))) - setTagColors( - Object.fromEntries( - Array.from(new Set(changes.selectedItems)).map((item) => { - return [item.label, tagColors[item.label] ?? 'gray.600'] - }), - ), - ) - } - }} - listItemStyleProps={{ overflow: 'hidden' }} - highlightItemBg="gray.400" - toggleButtonStyleProps={{ variant: 'outline' }} - inputStyleProps={{ - focusBorderColor: highlightColor, - color: 'gray.800', - borderColor: 'gray.600', - }} - tagStyleProps={{ - display: 'none', - rounded: 'full', - bg: highlightColor, - height: 8, - paddingLeft: 4, - fontWeight: 'bold', - }} - hideToggleButton - itemRenderer={(selected) => selected.label} - /> - } - align="stretch" - color="gray.800" - > - {Object.keys(tagColors).map((tag) => { - return ( - - - {tag} - - - - {} - - - {' '} - - {colorList.map((color: string) => ( - - setTagColors({ - ...tagColors, - [tag]: color, - }) - } - justifyContent="space-between" - alignItems="center" - display="flex" - > - - - ))} - - - - } - onClick={() => { - setTagColors( - Object.fromEntries( - Array.from(new Set(selectedItems)).map((item) => { - return [item.label, tagColors[item.label] ?? 'gray.600'] - }), - ), - ) - setSelectedItems(selectedItems.filter((item) => item.value !== tag)) - }} - /> - - ) - })} - - - ) -} -- cgit v1.2.3