Skip to content

Commit

Permalink
🪲 Fix wrong start values, because of unset district.
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasGilg committed Jan 20, 2025
1 parent 8a61369 commit 9fce4bd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
11 changes: 10 additions & 1 deletion frontend/src/DataContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ export const DataProvider = ({children}: {children: React.ReactNode}) => {
return groups?.find((group) => group.name === 'Total');
}, [groups]);

useEffect(() => {
if (!selectedDistrict) {
const germanyNode = nodes?.find((node) => node.name === '00000');
if (germanyNode) {
dispatch(selectDistrict({...germanyNode, type: ''}));
}
}
}, [dispatch, nodes, selectedDistrict]);

useEffect(() => {
if (scenarios) {
for (const [id, _] of Object.entries(scenariosState)) {
Expand Down Expand Up @@ -164,7 +173,7 @@ export const DataProvider = ({children}: {children: React.ReactNode}) => {
useEffect(() => {
const node = nodes?.find((node) => node.name === '00000');
if (node) {
dispatch(selectDistrict({id: node.id, ags: node.name, name: '', type: ''}));
dispatch(selectDistrict({id: node.id, nuts: node.name, name: '', type: ''}));
}
}, [dispatch, nodes]);

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/Sidebar/SidebarContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default function MapContainer() {

const [selectedArea, setSelectedArea] = useState<GeoJsonProperties>(
storeSelectedArea.name != ''
? {RS: storeSelectedArea.ags, GEN: storeSelectedArea.name, BEZ: storeSelectedArea.type}
? {RS: storeSelectedArea.nuts, GEN: storeSelectedArea.name, BEZ: storeSelectedArea.type}
: defaultValue
);
const [aggregatedMax, setAggregatedMax] = useState<number>(1);
Expand All @@ -75,7 +75,7 @@ export default function MapContainer() {
dispatch(
selectDistrict({
id: String(id.id),
ags: String(selectedArea?.['RS']),
nuts: String(selectedArea?.['RS']),
name: String(selectedArea?.['GEN']),
type: String(selectedArea?.['BEZ']),
})
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/store/DataSelectionSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface ScenarioState {
export interface DataSelection {
district: {
id: string;
ags: AGS;
nuts: AGS;
name: string;
type: string;
};
Expand All @@ -47,7 +47,7 @@ export interface DataSelection {
}

const initialState: DataSelection = {
district: {id: '', ags: '00000', name: '', type: ''},
district: {id: '', nuts: '00000', name: '', type: ''},
date: null,
scenario: null,
compartment: null,
Expand Down Expand Up @@ -90,7 +90,7 @@ export const DataSelectionSlice = createSlice({
setGroupFilters(state, action: PayloadAction<Record<string, GroupFilter>>) {
state.groupFilters = action.payload;
},
selectDistrict(state, action: PayloadAction<{id: string; ags: AGS; name: string; type: string}>) {
selectDistrict(state, action: PayloadAction<{id: string; nuts: AGS; name: string; type: string}>) {
state.district = action.payload;
},
selectDate(state, action: PayloadAction<string>) {
Expand Down

0 comments on commit 9fce4bd

Please sign in to comment.