Skip to content

Commit

Permalink
Merge pull request #105 from dxw/change-day
Browse files Browse the repository at this point in the history
Make map update when day tab changes
  • Loading branch information
jdudley1123 authored Nov 15, 2024
2 parents 7d53a9f + 80271c1 commit f119c33
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
5 changes: 3 additions & 2 deletions app/components/day_tab_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
controller: "tab",
"tab-active-class": "active",
"tab-inactive-class": "inactive",
"tab-target": "dayPrediction"
"tab-target": "dayPrediction",
"map-target": "daySelector",
} do
%>
<%= link_to update_forecast_path(day: @day, format: :turbo_stream),
data: {
action: "click->tab#switch_tab"
action: "click->tab#switch_tab click->map#updateMap",
} do %>
<div class="day" data-tab-target="day">
<%= @forecast.date == Date.today ? 'Today' : @forecast.date.strftime('%A') %>
Expand Down
5 changes: 3 additions & 2 deletions app/javascript/controllers/map_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "@maptiler/leaflet-maptilersdk";
import * as zones from "../zone_boundaries/zone-boundaries";

export default class MapController extends Controller {
static targets = ["map", "pollutantSelector"];
static targets = ["map", "pollutantSelector", "daySelector"];

layers = {};
controls = {};
Expand Down Expand Up @@ -190,7 +190,8 @@ export default class MapController extends Controller {

updateMap() {
const pollutant = this.pollutantSelectorTarget.value;
const newSettings = { pollutant: pollutant };
const date = this.daySelector.dataset.date;
const newSettings = { pollutant: pollutant, date: date };
this.settings = Object.assign({}, this.defaultMapSettings, newSettings);

this.updatePollutionLayer();
Expand Down
12 changes: 7 additions & 5 deletions app/views/forecasts/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<%= render partial: "forecasts/location" %>
<%= render partial: "forecasts/forecast_tabs", cerc_forecasts: @forecasts %>
<%= render partial: "forecasts/map" %>
<%= render partial: "forecasts/predictions", locals: { forecast: @forecasts.first } %>
<%= render partial: "sharing" %>
<div data-controller="map">
<%= render partial: "forecasts/location" %>
<%= render partial: "forecasts/forecast_tabs", cerc_forecasts: @forecasts %>
<%= render partial: "forecasts/map" %>
<%= render partial: "forecasts/predictions", locals: { forecast: @forecasts.first } %>
<%= render partial: "sharing" %>
</div>
<%= render partial: "learning" %>
<%= render partial: "subscribe" %>
<%= javascript_include_tag "application", "data-turbo-track": "reload", type: "module" %>

0 comments on commit f119c33

Please sign in to comment.