-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat: Calendar | view: add Next day button for time-passing simulat…
…ion (#43)
- Loading branch information
1 parent
264301a
commit 0cf2099
Showing
4 changed files
with
77 additions
and
8 deletions.
There are no files selected for viewing
27 changes: 24 additions & 3 deletions
27
heroesofddd_rails_application/app/assets/stylesheets/current_date.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
heroesofddd_rails_application/app/controllers/heroes/calendars_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
14 changes: 9 additions & 5 deletions
14
heroesofddd_rails_application/app/views/heroes/calendar/_current_date.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,9 @@ | |
post "recruit", on: :member | ||
end | ||
end | ||
resource :calendar, only: [] do | ||
post :next_day, on: :member | ||
end | ||
end | ||
end | ||
end |