From f10438688feaedab9c70c702fa291dfc1b3587ab Mon Sep 17 00:00:00 2001 From: Jon Allured Date: Sat, 20 Jan 2024 14:57:37 -0600 Subject: [PATCH] Add prev/next links to reading list --- app/models/reading_list.rb | 8 ++++++++ app/views/reading_list/index.html.haml | 6 +++++- spec/models/reading_list_spec.rb | 7 +++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/models/reading_list.rb b/app/models/reading_list.rb index a584acd..206fce3 100644 --- a/app/models/reading_list.rb +++ b/app/models/reading_list.rb @@ -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 diff --git a/app/views/reading_list/index.html.haml b/app/views/reading_list/index.html.haml index efae87e..05f83df 100644 --- a/app/views/reading_list/index.html.haml +++ b/app/views/reading_list/index.html.haml @@ -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. diff --git a/spec/models/reading_list_spec.rb b/spec/models/reading_list_spec.rb index 9d55753..923e378 100644 --- a/spec/models/reading_list_spec.rb +++ b/spec/models/reading_list_spec.rb @@ -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