Skip to content

Commit 55ed368

Browse files
committed
replace body instead of reloading entire page
1 parent a091fb0 commit 55ed368

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

app/controllers/displays_controller.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,16 @@ class DisplaysController < ApplicationController
33
layout "display"
44

55
def thirteen
6-
@refresh = params[:refresh] || ""
7-
86
render "thirteen", locals: {view_object: DisplayContent.new.call}
97
rescue => e
108
render "error", locals: {klass: e.class.to_s, message: e.message, backtrace: e.backtrace}
119
end
1210

1311
def mira
14-
@refresh = params[:refresh] || 2
12+
@refresh = params[:refresh] != "false"
1513

1614
begin
17-
render "mira", locals: {view_object: DisplayContent.new.call}
15+
render("mira", locals: {view_object: DisplayContent.new.call}, layout: params[:layout] != "false")
1816
rescue => e
1917
render "error", locals: {klass: e.class.to_s, message: e.message, backtrace: e.backtrace}
2018
end

app/views/displays/mira.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<div class="fade-bottom"></div>
12
<style>
23
html { font-size: 46px }
34
body { padding: 0 2rem }

app/views/displays/thirteen.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<div class="fade-bottom"></div>
12
<div class="timestamp" style="position: absolute; bottom: .25rem; right: .25rem; font-size: .4rem; color: #777; z-index: 10">
23
<%= view_object[:timestamp] %>
34
</div>

app/views/layouts/display.html.erb

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,28 @@
33
<head>
44
<title>Timeframe</title>
55
<link rel="stylesheet" href="/css/display.css">
6-
<meta http-equiv="refresh" content="<%= @refresh %>">
6+
<% if @refresh %>
7+
<script>
8+
setInterval(function() {
9+
fetch(window.location.origin + window.location.pathname + '?layout=false')
10+
.then(response => {
11+
if (!response.ok) {
12+
throw new Error('Network response was not ok');
13+
}
14+
return response.text();
15+
})
16+
.then(data => {
17+
document.body.innerHTML = data
18+
})
19+
.catch(error => {
20+
console.error('There was a problem with the fetch operation:', error);
21+
});
22+
}, 1000);
23+
</script>
24+
<% end %>
725
</head>
826

927
<body>
10-
<div class="fade-bottom"></div>
1128
<%= yield %>
1229
</body>
1330
</html>

0 commit comments

Comments
 (0)