Skip to content

Commit

Permalink
Add prev/next links to reading list
Browse files Browse the repository at this point in the history
  • Loading branch information
jonallured committed Jan 20, 2024
1 parent 2f211fd commit f104386
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
8 changes: 8 additions & 0 deletions app/models/reading_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ def initialize(year = Time.now.year)
@year = year
end

def prev_year
@year - 1
end

def next_year
@year + 1
end

def books
@books ||= select_books
end
Expand Down
6 changes: 5 additions & 1 deletion app/views/reading_list/index.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
%h1= reading_list.year
- content_for :header do
%nav.flex.justify-between.items-center.py-6.border-b-8.border-dark-gray
%p.m-0= link_to "prev", reading_list_path(reading_list.prev_year)
%h1.m-0= reading_list.year
%p.m-0= link_to "next", reading_list_path(reading_list.next_year)

%p #{reading_list.books.count} books for #{number_with_delimiter reading_list.total_pages} pages at a pace of #{reading_list.pace} pages/day.

Expand Down
7 changes: 7 additions & 0 deletions spec/models/reading_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,11 @@ def table_of_books(year)
end
end
end

describe "something" do
it "idk" do
reading_list = ReadingList.new(2020)
expect(reading_list.previous_year).to eq nil
end
end
end

0 comments on commit f104386

Please sign in to comment.