WIP last_read property for Entries

This commit is contained in:
Jared Turner 2020-05-29 13:26:47 +01:00
parent ddb6a860ae
commit d2ad7fef77
2 changed files with 23 additions and 0 deletions

View File

@ -287,6 +287,15 @@ class Title
else
info.progress[username][entry] = page
end
# should this be a separate method?
# eg. def save_last_read(username, entry)
# if so, we would need to open the json file twice every
# time we save. Does that matter?
if info.last_read[username]?.nil?
info.last_read[username] = {entry => Time.utc}
else
info.last_read[username][entry] = Time.utc
end
info.save
end
end
@ -319,6 +328,18 @@ class Title
read_pages / total_pages
end
def load_last_read(username, entry)
last_read = nil
TitleInfo.new @dir do |info|
unless info.last_read[username]?.nil? ||
info.last_read[username][entry]?.nil?
last_read = info.last_read[username][entry]
end
end
return nil if last_read.nil?
last_read
end
def next_entry(current_entry_obj)
idx = @entries.index current_entry_obj
return nil if idx.nil? || idx == @entries.size - 1
@ -350,6 +371,7 @@ class TitleInfo
property entry_display_name = {} of String => String
property cover_url = ""
property entry_cover_url = {} of String => String
property last_read = {} of String => Hash(String, Time)
@[JSON::Field(ignore: true)]
property dir : String = ""

View File

@ -77,6 +77,7 @@ class MainRouter < Router
percentage = continue_reading_entries.map do |e|
e.book.load_percentage username, e.title
pp e.book.load_last_read username, e.title
end
layout "home"