feat: add weather forecasting

This commit is contained in:
insects 2025-03-11 14:57:28 +01:00
parent 6eea0dc29f
commit 705e7b1dc0
20 changed files with 181 additions and 19 deletions

View file

@ -29,6 +29,11 @@ header .muted {
font-weight: normal;
}
main {
display: grid;
grid-template-columns: 5fr 1fr;
}
.new-buttons {
display: flex;
gap: 5px;
@ -169,3 +174,26 @@ span#password {
.copyable:hover {
cursor: pointer;
}
.sidebar {
display: flex;
flex-direction: column;
align-items: center;
margin: 10px 0;
}
.weather-list {
display: flex;
align-items: center;
gap: 3px;
}
.weather {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
font-size: 12px;
color: #555;
}

View file

@ -1,8 +1,2 @@
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails
import "htmx.org"
import htmx from "htmx.org"
htmx.logger = function(elt, event, data) {
if(console) {
console.log(event, elt, data);
}
}

View file

@ -1,4 +1,4 @@
<main id="nm-list">
<div id="nm-list">
<% APP_DATA[instance.zone.to_sym][:nms].each do |nm| %>
<% is_popped = instance.pops.filter { |pop| (Time.current - 120.minutes) <= pop.created_at }.any? { |pop| pop.name == nm[:name].parameterize } %>
<section class="<%= class_names(popped: is_popped) %>">
@ -10,7 +10,7 @@
<span class="badge">LV<%= nm[:level].to_s.rjust(2, "0") %></span>
<%= nm[:name] %>
<% if nm[:weather] %>
<img src="/<%= nm[:weather] %>.png" title="during <%= nm[:weather] %> only" width="15" />
<img src="/weather/<%= nm[:weather] %>.png" title="during <%= nm[:weather] %> only" width="15" />
<% end %>
</h3>
<div class="spawn-info">
@ -20,7 +20,7 @@
<span title="only at night">🌙</span>
<% end %>
<% if nm[:spawned_by][:weather] %>
<img src="/<%= nm[:spawned_by][:weather] %>.png" title="during <%= nm[:spawned_by][:weather] %> only" width="15" />
<img src="/weather/<%= nm[:spawned_by][:weather] %>.png" title="during <%= nm[:spawned_by][:weather] %> only" width="15" />
<% end %>
<small class="badge">LV<%= nm[:spawned_by][:level].to_s.rjust(2, "0") %></small>
</div>
@ -52,4 +52,4 @@
</div>
</section>
<% end %>
</main>
</div>

View file

@ -22,7 +22,26 @@
</div>
</header>
<%= render partial: "list", locals: { instance: @instance } %>
<main>
<%= render partial: "list", locals: { instance: @instance } %>
<div class="sidebar">
<div class="weather-list">
<% forecast = Weather.forecast(@instance.zone.to_sym) %>
<div class="weather">
<img src="/weather/<%= forecast[0][:curr_weather] %>.png" width="25" title="<%= forecast[0][:weather_name] %>" />
<div>now</div>
</div>
<% 4.times do |i| %>
»
<div class="weather">
<img src="/weather/<%= forecast[i + 1][:curr_weather] %>.png" width="25" title="<%= forecast[i + 1][:weather_name] %>" />
<div><%= ((forecast[i + 1][:time] - Time.now.utc) / 1.minutes).floor %>m</div>
</div>
<% end %>
</div>
</div>
</main>
<%= javascript_include_tag "list" %>
</div>