-
-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
23 additions
and
0 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -287,6 +287,15 @@ class Title | |
else | ||
info.progress[username][entry] = page | ||
end | ||
# should this be a separate method? | ||
This comment has been minimized.
Sorry, something went wrong. |
||
# 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? | ||
This comment has been minimized.
Sorry, something went wrong.
hkalexling
Member
|
||
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 = "" | ||
|
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 |
---|---|---|
|
@@ -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 | ||
This comment has been minimized.
Sorry, something went wrong.
hkalexling
Member
|
||
end | ||
|
||
layout "home" | ||
|
I think leaving it like this is fine. Having to call two methods when updating the progress is troublesome.