Skip to content

Commit

Permalink
refactor: populate store vars when fetching for Project contents
Browse files Browse the repository at this point in the history
  • Loading branch information
annehaley committed Oct 1, 2024
1 parent 13f00ea commit 7afef9b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 45 deletions.
39 changes: 33 additions & 6 deletions web/src/components/ProjectContents.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ import {
getProjectSimulationTypes,
} from "@/api/rest";
import DatasetList from "./DatasetList.vue";
import { currentChart, currentSimulationType } from "@/store";
import {
availableCharts,
availableDatasets,
availableDerivedRegions,
availableSimulationTypes,
currentChart,
currentSimulationType,
} from "@/store";
import { getDatasetLayerForDataObject, toggleDatasetLayer } from "@/layers";
export default {
components: { DatasetList },
Expand All @@ -27,10 +35,26 @@ export default {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
setup(props: any) {
const panels = [
{ label: "Datasets", loadFunction: getProjectDatasets },
{ label: "Regions", loadFunction: getProjectDerivedRegions },
{ label: "Charts", loadFunction: getProjectCharts },
{ label: "Simulations", loadFunction: getProjectSimulationTypes },
{
label: "Datasets",
loadFunction: getProjectDatasets,
storeVar: availableDatasets,
},
{
label: "Regions",
loadFunction: getProjectDerivedRegions,
storeVar: availableDerivedRegions,
},
{
label: "Charts",
loadFunction: getProjectCharts,
storeVar: availableCharts,
},
{
label: "Simulations",
loadFunction: getProjectSimulationTypes,
storeVar: availableSimulationTypes,
},
];
const openPanels: Ref<string[]> = ref([]);
Expand All @@ -43,7 +67,9 @@ export default {
item: Dataset | DerivedRegion | Chart | SimulationType
) {
if (panelLabel == "Regions") {
// TODO: select region
getDatasetLayerForDataObject(item as DerivedRegion).then((layer) => {
toggleDatasetLayer(layer);
});
} else if (panelLabel == "Charts") {
currentChart.value = item as Chart;
} else if (panelLabel == "Simulations") {
Expand All @@ -57,6 +83,7 @@ export default {
if (openPanels.value.includes(panel.label)) {
panel.loadFunction(props.project.id).then((data) => {
projectContents.value[panel.label] = data;
panel.storeVar.value = data;
});
}
});
Expand Down
40 changes: 1 addition & 39 deletions web/src/storeFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,7 @@ import {
tooltipOverlay,
clickedFeatureCandidates,
} from "./store";
import { Dataset } from "./types";
import {
getProjectDatasets,
getProjects,
getDataset,
getProjectCharts,
getProjectSimulationTypes,
getProjectDerivedRegions,
} from "@/api/rest";
import { getProjects, getDataset, getProjectDerivedRegions } from "@/api/rest";
import {
datasetLayerFromMapLayerID,
styleNetworkVectorTileLayer,
Expand Down Expand Up @@ -115,32 +107,6 @@ export function getCurrentMapPosition() {
return { center, zoom };
}

export function loadDatasets() {
if (!currentProject.value) return;
availableDatasets.value = undefined;
getProjectDatasets(currentProject.value.id).then((data: Dataset[]) => {
availableDatasets.value = data;
});
}

export function loadCharts() {
if (!currentProject.value) return;
availableCharts.value = undefined;
currentChart.value = undefined;
getProjectCharts(currentProject.value.id).then((charts) => {
availableCharts.value = charts;
});
}

export function loadSimulationTypes() {
if (!currentProject.value) return;
availableSimulationTypes.value = undefined;
currentSimulationType.value = undefined;
getProjectSimulationTypes(currentProject.value.id).then((sims) => {
availableSimulationTypes.value = sims;
});
}

export async function loadDerivedRegions() {
if (!currentProject.value) {
return;
Expand Down Expand Up @@ -199,10 +165,6 @@ export function clearCurrentNetwork() {
watch(currentProject, () => {
clearState();
setMapCenter();
loadDatasets();
loadCharts();
loadSimulationTypes();
loadDerivedRegions();
});
watch(currentDataset, () => {
rasterTooltipEnabled.value = false;
Expand Down

0 comments on commit 7afef9b

Please sign in to comment.