Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/lib/config/app_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,11 @@ class AppRouter {

return NoTransitionPage(
key: state.pageKey,
child: ReaderPage(bookId: bookId),
child: ReaderPage(
key: ValueKey(state.uri.toString()),
bookId: bookId,
location: state.uri.queryParameters['location'],
),
);
},
),
Expand Down
34 changes: 32 additions & 2 deletions app/lib/models/annotation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,24 @@ class BookLocation {
final String? chapterTitle;
final int pageNumber;
final double? percentage;
final Map<String, Object?>? readerLocator;
final Map<String, Object?>? selection;

const BookLocation({this.chapter, this.chapterTitle, required this.pageNumber, this.percentage});
const BookLocation({
this.chapter,
this.chapterTitle,
required this.pageNumber,
this.percentage,
this.readerLocator,
this.selection,
});

/// Get a display-friendly location string.
String get displayLocation {
if (readerLocator?['type'] == 'epub') {
return '${chapterTitle ?? 'Chapter $chapter'} · ${((percentage ?? 0) * 100).round()}%';
}

if (chapterTitle != null && chapter != null) {
return 'Chapter $chapter: $chapterTitle, Page $pageNumber';
}
Expand All @@ -83,19 +96,32 @@ class BookLocation {

/// Get a short location string.
String get shortLocation {
if (readerLocator?['type'] == 'epub') {
return 'Ch. $chapter · ${((percentage ?? 0) * 100).round()}%';
}

if (chapter != null) {
return 'Ch. $chapter, p. $pageNumber';
}

return 'Page $pageNumber';
}

BookLocation copyWith({int? chapter, String? chapterTitle, int? pageNumber, double? percentage}) {
BookLocation copyWith({
int? chapter,
String? chapterTitle,
int? pageNumber,
double? percentage,
Map<String, Object?>? readerLocator,
Map<String, Object?>? selection,
}) {
return BookLocation(
chapter: chapter ?? this.chapter,
chapterTitle: chapterTitle ?? this.chapterTitle,
pageNumber: pageNumber ?? this.pageNumber,
percentage: percentage ?? this.percentage,
readerLocator: readerLocator ?? this.readerLocator,
selection: selection ?? this.selection,
);
}
}
Expand Down Expand Up @@ -157,6 +183,8 @@ class Annotation {
'chapter_title': location.chapterTitle,
'page_number': location.pageNumber,
'percentage': location.percentage,
'reader_locator': location.readerLocator,
'selection': location.selection,
'note': note,
'created_at': createdAt.toIso8601String(),
'updated_at': updatedAt?.toIso8601String(),
Expand All @@ -174,6 +202,8 @@ class Annotation {
chapterTitle: json['chapter_title'] as String?,
pageNumber: json['page_number'] as int,
percentage: (json['percentage'] as num?)?.toDouble(),
readerLocator: (json['reader_locator'] as Map?)?.cast<String, Object?>(),
selection: (json['selection'] as Map?)?.cast<String, Object?>(),
),
note: json['note'] as String?,
createdAt: DateTime.parse(json['created_at'] as String),
Expand Down
10 changes: 10 additions & 0 deletions app/lib/models/bookmark.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const _sentinel = _Sentinel();
class Bookmark {
final String id;
final String bookId;
final Map<String, Object?>? readerLocator;
final double position; // 0.0 to 1.0
final int? pageNumber;
final String? chapterTitle;
Expand All @@ -20,6 +21,7 @@ class Bookmark {
required this.id,
required this.bookId,
required this.position,
this.readerLocator,
this.pageNumber,
this.chapterTitle,
this.note,
Expand All @@ -38,6 +40,10 @@ class Bookmark {

/// Get a display-friendly location string.
String get displayLocation {
if (readerLocator?['type'] == 'epub' && chapterTitle != null) {
return '$chapterTitle · ${(position * 100).round()}%';
}

if (chapterTitle != null && pageNumber != null) {
return '$chapterTitle, Page $pageNumber';
}
Expand All @@ -61,6 +67,7 @@ class Bookmark {
String? id,
String? bookId,
double? position,
Object? readerLocator = _sentinel,
Object? pageNumber = _sentinel,
Object? chapterTitle = _sentinel,
Object? note = _sentinel,
Expand All @@ -71,6 +78,7 @@ class Bookmark {
id: id ?? this.id,
bookId: bookId ?? this.bookId,
position: position ?? this.position,
readerLocator: identical(readerLocator, _sentinel) ? this.readerLocator : readerLocator as Map<String, Object?>?,
pageNumber: identical(pageNumber, _sentinel) ? this.pageNumber : pageNumber as int?,
chapterTitle: identical(chapterTitle, _sentinel) ? this.chapterTitle : chapterTitle as String?,
note: identical(note, _sentinel) ? this.note : note as String?,
Expand All @@ -84,6 +92,7 @@ class Bookmark {
'id': id,
'book_id': bookId,
'position': position,
'reader_locator': readerLocator,
'page_number': pageNumber,
'chapter_title': chapterTitle,
'note': note,
Expand All @@ -97,6 +106,7 @@ class Bookmark {
id: json['id'] as String,
bookId: json['book_id'] as String,
position: (json['position'] as num).toDouble(),
readerLocator: (json['reader_locator'] as Map?)?.cast<String, Object?>(),
pageNumber: json['page_number'] as int?,
chapterTitle: json['chapter_title'] as String?,
note: json['note'] as String?,
Expand Down
13 changes: 7 additions & 6 deletions app/lib/pages/annotations_page.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:papyrus/widgets/shared/app_drawer.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:papyrus/reader/reader_navigation.dart';
import 'package:papyrus/data/data_store.dart';
import 'package:papyrus/data/repositories/library_repository.dart';
import 'package:papyrus/models/annotation.dart';
Expand Down Expand Up @@ -300,7 +300,12 @@ class _AnnotationsPageState extends State<AnnotationsPage> {
AnnotationCard(
annotation: annotation,
showActionMenu: isDesktop,
onTap: () => _navigateToBook(context, annotation.bookId),
onTap: () => openSavedReadingLocation(
context,
bookId: annotation.bookId,
anchor: annotation.location.readerLocator,
pageNumber: annotation.location.pageNumber,
),
onLongPress: () => _onAnnotationActions(context, provider, annotation),
),
);
Expand All @@ -314,10 +319,6 @@ class _AnnotationsPageState extends State<AnnotationsPage> {
);
}

void _navigateToBook(BuildContext context, String bookId) {
context.goNamed('BOOK_DETAILS', pathParameters: {'bookId': bookId});
}

void _onAnnotationActions(BuildContext context, AnnotationsProvider provider, Annotation annotation) async {
final repository = context.read<DataStore>().libraryRepository?.annotations;
final action = await AnnotationActionSheet.show(context, annotation: annotation);
Expand Down
Loading
Loading