mirror of
https://github.com/bellingcat/ukraine-timemap.git
synced 2026-06-11 21:08:36 +03:00
fix hierarchical tag toggle
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
import React, { useState } from 'react'
|
||||
|
||||
export default ({ showing, onClickHandler, timelineDims }) => {
|
||||
const [checked, setChecked] = useState(true)
|
||||
const handleCheck = () => setChecked(!checked)
|
||||
const onNarrativise = () => onClickHandler(checked)
|
||||
|
||||
if (!showing) {
|
||||
return null
|
||||
}
|
||||
|
||||
const [checked, setChecked] = useState(true)
|
||||
const handleCheck = () => setChecked(!checked)
|
||||
const onNarrativise = () => onClickHandler(checked)
|
||||
|
||||
return <div className='stateoptions-panel' style={{ bottom: timelineDims.height }}>
|
||||
<div>
|
||||
<div className='button' onClick={onNarrativise}>Narrativise</div>
|
||||
|
||||
@@ -2,11 +2,19 @@ import React from 'react'
|
||||
import Checkbox from '../presentational/Checkbox'
|
||||
import copy from '../../common/data/copy.json'
|
||||
|
||||
/** recursively get an array of node keys */
|
||||
function allAssociatedKeys (node) {
|
||||
if (!node.children) return [node.key]
|
||||
const childKeys = Object.values(node.children).flatMap(n => allAssociatedKeys(n))
|
||||
childKeys.push(node.key)
|
||||
/** recursively get an array of node keys to toggle */
|
||||
function childrenToToggle (node, activeFilters, parentOn) {
|
||||
const isOn = activeFilters.includes(node.key)
|
||||
if (!node.children) {
|
||||
return [node.key]
|
||||
}
|
||||
const childKeys = Object.values(node.children)
|
||||
.flatMap(n => childrenToToggle(n, activeFilters, isOn))
|
||||
// NB: if turning a parent off, don't toggle off children on.
|
||||
// likewise if turning a parent on, don't toggle on children off
|
||||
if (!((!parentOn && isOn) || (parentOn && !isOn))) {
|
||||
childKeys.push(node.key)
|
||||
}
|
||||
return childKeys
|
||||
}
|
||||
|
||||
@@ -17,7 +25,7 @@ function FilterListPanel ({
|
||||
language
|
||||
}) {
|
||||
function createNodeComponent (node, depth) {
|
||||
const matchingKeys = allAssociatedKeys(node)
|
||||
const matchingKeys = childrenToToggle(node, activeFilters, activeFilters.includes(node.key))
|
||||
const children = Object.values(node.children)
|
||||
return (
|
||||
<li
|
||||
|
||||
Reference in New Issue
Block a user