Skip to content

Commit

Permalink
✨ feat: Calendar | view: add Next day button for time-passing simulat…
Browse files Browse the repository at this point in the history
…ion (#43)
  • Loading branch information
MateuszNaKodach authored Sep 29, 2024
1 parent 264301a commit 0cf2099
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
.current-date {
margin: 2rem;
background-color: #f0f0f0;
background-color: #221811;
border: 1px solid #ccc;
border-radius: 5px;
padding: 10px;
font-weight: bold;
// align-self: flex-end;
color: #F8F0D6;
font-weight: 200;
margin-top: 2rem;

&__text {
padding: 0;
margin: 0
}

&__next-day-button {
margin-top: 10px;
padding: 5px 10px;
background-color: #F5DA76;
color: #2B1E12;
border: none;
cursor: pointer;
font-weight: bold;

&:hover {
background-color: #A3813F;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module Heroes
class CalendarsController < ApplicationController
def next_day
game_id = params[:game_id]
current_date = Heroes::Calendar::CurrentDateReadModel::State.find_by(game_id: game_id)

finish_day = Heroes::Calendar::FinishDay.new(current_date.month, current_date.week, current_date.day)
command_bus.call(finish_day, BuildingBlocks::Application::AppContext.for_game(game_id))

next_day = calculate_next_day(current_date)
start_day = Heroes::Calendar::StartDay.new(next_day[:month], next_day[:week], next_day[:day])
command_bus.call(start_day, BuildingBlocks::Application::AppContext.for_game(game_id))

@current_date = Heroes::Calendar::CurrentDateReadModel::State.find_by(game_id: game_id)

respond_to do |format|
format.turbo_stream { render turbo_stream: turbo_stream.update("current-date", partial: "heroes/calendar/current_date") }
end
end

private

def calculate_next_day(current_date)
day = current_date.day + 1
week = current_date.week
month = current_date.month

if day > 7
day = 1
week += 1
end

if week > 4
week = 1
month += 1
end

{ month: month, week: week, day: day }
end
end
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<div class="current-date">
<% if @current_date %>
<p>Month: <%= @current_date.month %>, Week: <%= @current_date.week %>, Day: <%= @current_date.day %></p>
<% end %>
</div>
<%= turbo_frame_tag "current-date" do %>
<div class="current-date">
<% if @current_date %>
<p class="current-date__text">Month: <%= @current_date.month %>, Week: <%= @current_date.week %>,
Day: <%= @current_date.day %></p>
<%= button_to "Next day", next_day_heroes_game_calendar_path(@current_date.game_id), method: :post, class: "current-date__next-day-button" %>
<% end %>
</div>
<% end %>
3 changes: 3 additions & 0 deletions heroesofddd_rails_application/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
post "recruit", on: :member
end
end
resource :calendar, only: [] do
post :next_day, on: :member
end
end
end
end

0 comments on commit 0cf2099

Please sign in to comment.