Skip to content

Commit

Permalink
fix: fix loading JSON and sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
bolinocroustibat committed Dec 2, 2024
1 parent 09d8d59 commit 20d8a30
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 37 deletions.
6 changes: 3 additions & 3 deletions frontend/src/components/SidebarComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<h2>Filters</h2>
<div v-if="loading" class="loading">Chargement...</div>
<div v-else>
<label for="natureCultureSelect">Nature de la culture</label>
<label for="natureCultureSelect">Choisir une nature de la culture</label>
<select id="natureCultureSelect" v-model="selectedNatureCulture">
<option v-for="(value, key) in natureCultureOptions" :key="key" :value="key">
{{ value }}
Expand Down Expand Up @@ -43,8 +43,8 @@ export default defineComponent({
<style>
.sidebar {
position: fixed;
top: 80px; /* Give some space below header */
left: 20px; /* Space from left edge */
top: 100px;
left: 20px;
width: 250px;
background-color: white;
padding: 20px;
Expand Down
43 changes: 9 additions & 34 deletions frontend/src/services/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,18 @@ import type { AggregatedLandMutation } from "../types/models";
export const api = {
async getAggregatedLandMutations(): Promise<AggregatedLandMutation[]> {
try {
const response = await fetch("../../../data/stats.csv");
const csvText = await response.text();
const response = await fetch("../../../data/stats.json");
const jsonData = await response.json();

const lines = csvText.split("\n");
const headers = lines[0].split(",");
return jsonData.map((item: any) => ({
departementCode: item.code_geo.padStart(2, "0"),
month: new Date(`${item.month}-01`),
natureCulture: fromCsv(item.nature_culture),
nbMutations: Number.parseInt(item.nb_mutations, 10),
}));

return lines
.slice(1)
.filter((line) => line.trim())
.map((line) => {
const values = line.split(",");
return {
departementCode: values[0].padStart(2, "0"),
month: new Date(`${values[1]}-01`),
natureCulture: fromCsv(values[2]),
nbMutations: Number.parseInt(values[3], 10),
};
});

// Return mock data for now
// return [
// {
// departementCode: "75",
// month: new Date("2023-01-01"),
// natureCulture: NatureCulture.T,
// nbMutations: 42,
// },
// {
// departementCode: "77",
// month: new Date("2023-01-01"),
// natureCulture: NatureCulture.VI,
// nbMutations: 23,
// },
// // Add more mock data as needed
// ];
} catch (error) {
console.error("Error loading CSV data:", error);
console.error("Error loading JSON data:", error);
throw error;
}
},
Expand Down

0 comments on commit 20d8a30

Please sign in to comment.