Skip to content

Commit

Permalink
Merge branch 'main' into paint-by-county-improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
nofurtherinformation committed Nov 21, 2024
2 parents df97c39 + 1d825a3 commit ef6c1d4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
3 changes: 3 additions & 0 deletions app/src/app/components/sidebar/ColorPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ export const ColorPicker = <T extends boolean>({
const indices = values.map(f => colorArray.indexOf(f));
onValueChange(indices, values);
}}
style={{
justifyContent: "flex-start"
}}
>
{!!mapDocument && colorArray.slice(0, mapDocument.num_districts ?? 0).map((color, i) => (
<CheckboxGroupItem
Expand Down
4 changes: 0 additions & 4 deletions app/src/app/components/sidebar/Layers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export default function Layers() {
const visibleLayerIds = useMapStore(state => state.visibleLayerIds);
const updateVisibleLayerIds = useMapStore(state => state.updateVisibleLayerIds);
const toggleHighlightBrokenDistricts = useMapStore(state => state.toggleHighlightBrokenDistricts);
const toggleLockAllAreas = useMapStore(state => state.toggleLockAllAreas);
const parentsAreBroken = useMapStore(state => state.shatterIds.parents.size);
const mapOptions = useMapStore(state => state.mapOptions);
const setMapOptions = useMapStore(state => state.setMapOptions);
Expand Down Expand Up @@ -78,9 +77,6 @@ export default function Layers() {
})}>
Highlight unassigned units
</CheckboxGroup.Item>
<CheckboxGroup.Item value="4" onClick={() => toggleLockAllAreas()}>
Lock All Painted Areas
</CheckboxGroup.Item>
</CheckboxGroup.Root>
<Heading as="h3" weight="bold" size="3">
Boundaries
Expand Down
14 changes: 14 additions & 0 deletions app/src/app/components/sidebar/ZoneLockPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ import * as RadioGroup from '@radix-ui/react-radio-group';
import {blackA} from '@radix-ui/colors';
import {useMapStore} from '../../store/mapStore';
import {ColorPicker} from './ColorPicker';
import { LockClosedIcon, LockOpen2Icon } from '@radix-ui/react-icons';

export function ZoneLockPicker() {
const lockedZones = useMapStore(state => state.mapOptions.lockPaintedAreas);
const mapDocument = useMapStore(state => state.mapDocument)
const numDistricts = mapDocument?.num_districts || 40
const allDistrictsNumbers = new Array(numDistricts-1).fill(null).map((_,i) => i+1)
const pickerValue = Array.isArray(lockedZones)
? lockedZones.map(f => (null === f ? 0 : f - 1))
: lockedZones === true
Expand All @@ -21,6 +25,8 @@ export function ZoneLockPicker() {
const zoneValues = indices.map(v => v + 1);
setLockedZones(zoneValues);
};
const lockAll = () => setLockedZones(allDistrictsNumbers)
const unlockAll = () => setLockedZones([])

return (
<div>
Expand All @@ -31,6 +37,14 @@ export function ZoneLockPicker() {
value={pickerValue}
multiple
/>
<Button onClick={lockAll} mr="2" mt="2" variant="outline">
<LockClosedIcon/>
Lock all
</Button>
<Button onClick={unlockAll} mt="2" variant="outline">
<LockOpen2Icon/>
Unlock all
</Button>
</div>
);
}
9 changes: 5 additions & 4 deletions app/src/app/store/mapStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ export const useMapStore = create(

const geoids = features.map(f => f.id?.toString()).filter(Boolean) as string[];

const shatterMappings = get().shatterMappings;
const {shatterIds, shatterMappings, lockedFeatures} = get();
const isAlreadyShattered = geoids.some(id => shatterMappings.hasOwnProperty(id));
const shatterResult: ShatterResult = isAlreadyShattered
? ({
Expand All @@ -475,6 +475,7 @@ export const useMapStore = create(
document_id,
geoids,
});

if (!shatterResult.children.length){
const mapDocument = get().mapDocument
set({
Expand All @@ -488,13 +489,12 @@ export const useMapStore = create(
}
// TODO Need to return child edges even if the parent is already shattered
// currently returns nothing
const shatterIds = get().shatterIds;

const newLockedFeatures = new Set(lockedFeatures)
let existingParents = new Set(shatterIds.parents);
let existingChildren = new Set(shatterIds.children);
const newParent = shatterResult.parents.geoids;
const newChildren = new Set(shatterResult.children.map(child => child.geo_id));

newChildren.forEach(child => newLockedFeatures.delete(child))
const zoneAssignments = new Map(get().zoneAssignments);
const multipleShattered = shatterResult.parents.geoids.length > 1;
const featureBbox = features[0].geometry && bbox(features[0].geometry);
Expand All @@ -521,6 +521,7 @@ export const useMapStore = create(
},
mapLock: false,
captiveIds: newChildren,
lockedFeatures: newLockedFeatures,
focusFeatures: [
{
id: features[0].id,
Expand Down

0 comments on commit ef6c1d4

Please sign in to comment.