feat: store subscription posts with a read mark and split the library controller
This commit is contained in:
parent
b311b9f7dd
commit
953ae798eb
15 changed files with 1787 additions and 386 deletions
35
app/lib/application/controllers/bookmarks_controller.dart
Normal file
35
app/lib/application/controllers/bookmarks_controller.dart
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import 'package:signals/signals.dart';
|
||||
|
||||
import '../../database/database.dart';
|
||||
|
||||
/// Which pages the reader has bookmarked. Only the set of addresses is held
|
||||
/// here, because that is all the chrome watches; the list itself is read from
|
||||
/// the database whenever a page needs it.
|
||||
class BookmarksController {
|
||||
BookmarksController(this._db);
|
||||
|
||||
final MewsDatabase _db;
|
||||
|
||||
final bookmarkedUrls = signal(<String>{});
|
||||
|
||||
Future<void> load() async {
|
||||
final rows = await _db.allBookmarks();
|
||||
bookmarkedUrls.value = rows.map((row) => row.url).toSet();
|
||||
}
|
||||
|
||||
bool isBookmarked(String url) => bookmarkedUrls.value.contains(url);
|
||||
|
||||
Future<void> toggle(String url, String? title) async {
|
||||
if (isBookmarked(url)) {
|
||||
await remove(url);
|
||||
return;
|
||||
}
|
||||
await _db.addBookmark(url, title);
|
||||
bookmarkedUrls.value = {...bookmarkedUrls.value, url};
|
||||
}
|
||||
|
||||
Future<void> remove(String url) async {
|
||||
await _db.removeBookmark(url);
|
||||
bookmarkedUrls.value = {...bookmarkedUrls.value}..remove(url);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue