Skip to content

Commit

Permalink
hotfix: Resolved AlpineJS conflict preventing data loading
Browse files Browse the repository at this point in the history
  • Loading branch information
hepplerj committed Sep 18, 2024
1 parent e6ec32f commit eb7d658
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 34 deletions.
47 changes: 33 additions & 14 deletions bom-website/assets/js/database.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Alpine from "alpinejs";
import collapse from '@alpinejs/collapse';
import collapse from "@alpinejs/collapse";

// initialize Alpine
window.Alpine = Alpine;
Expand Down Expand Up @@ -51,15 +51,20 @@ document.addEventListener("alpine:init", () => {
// Fetch the static data
this.fetchStaticData();

// Read URL parameters
let params = new URLSearchParams(window.location.search);

// Update filters and page based on URL parameters
if (params.has('start-year')) this.filters.selectedStartYear = parseInt(params.get('start-year'));
if (params.has('end-year')) this.filters.selectedEndYear = parseInt(params.get('end-year'));
if (params.has('count-type')) this.filters.selectedCountType = params.get('count-type');
if (params.has('parish')) this.filters.selectedParishes = params.get('parish').split(',');
if (params.has('page')) this.page = parseInt(params.get('page'));
if (params.has("start-year"))
this.filters.selectedStartYear = parseInt(params.get("start-year"));
if (params.has("end-year"))
this.filters.selectedEndYear = parseInt(params.get("end-year"));
if (params.has("count-type"))
this.filters.selectedCountType = params.get("count-type");
if (params.has("parishes")) {
const parishParam = params.get("parish");
const parishes = parishParam.split(",");
this.filters.selectedParishes =
parishes.length > 1 ? parishes : [parishParam];
}
if (params.has("page")) this.page = parseInt(params.get("page"));
// if (params.has('openTab')) this.openTab = parseInt(params.get('openTab'));

this.fetchData();
Expand All @@ -85,7 +90,10 @@ document.addEventListener("alpine:init", () => {
this.all_causes.forEach((d, i) => (d.id = i));
})
.catch((error) => {
console.error("There was an error fetching causes of death data:", error);
console.error(
"There was an error fetching causes of death data:",
error,
);
});

fetch("https://data.chnm.org/bom/list-christenings")
Expand All @@ -94,7 +102,10 @@ document.addEventListener("alpine:init", () => {
this.all_christenings = data;
})
.catch((error) => {
console.error("There was an error fetching christenings data:", error);
console.error(
"There was an error fetching christenings data:",
error,
);
});
},
async fetchData(billType) {
Expand All @@ -107,23 +118,31 @@ document.addEventListener("alpine:init", () => {
// billType defaults to filters.selectedBillType unless one is provided by the app
billType = billType || this.filters.selectedBillType;


// Bills data
let response = await fetch(
`https://data.chnm.org/bom/bills?start-year=${this.filters.selectedStartYear}&end-year=${this.filters.selectedEndYear}&bill-type=${billType}&count-type=${this.filters.selectedCountType}&parish=${this.filters.selectedParishes}&limit=${this.server.limit}&offset=${this.server.offset}`,
);

if (!response.ok) {
console.error("There was an error fetching weekly bills data:", response);
console.error(
"There was an error fetching weekly bills data:",
response,
);
this.meta.loading = false;
this.meta.fetching = false;
this.messages.loading = "No data available. Please try again with different filters.";
this.messages.loading =
"No data available. Please try again with different filters.";
return;
}

let data = await response.json();

if (data.error) {
console.error("There was an error fetching weekly bills data:", data.error);
console.error(
"There was an error fetching weekly bills data:",
data.error,
);
this.meta.loading = false;
this.meta.fetching = false;
return;
Expand Down
28 changes: 14 additions & 14 deletions bom-website/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions bom-website/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"dependencies": {
"@alpinejs/collapse": "^3.13.3",
"@alpinejs/collapse": "^3.14.1",
"@observablehq/plot": "^0.6.4",
"alpinejs": "^3.13.3",
"alpinejs": "^3.14.1",
"d3": "^7.8.3",
"d3-cloud": "^1.2.5"
}
Expand Down
4 changes: 0 additions & 4 deletions bom-website/themes/dbn/layouts/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,4 @@
rel="stylesheet"
href="https://unpkg.com/littlefoot/dist/littlefoot.css"
/>
<script
defer
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/cdn.min.js"
></script>
</head>

0 comments on commit eb7d658

Please sign in to comment.