Added mark as read or unread

This commit is contained in:
Juan Gilsanz Polo
2024-02-25 21:09:54 +01:00
parent 776ec9f392
commit 175963883f
12 changed files with 145 additions and 18 deletions

3
lib/config/options.dart Normal file
View File

@@ -0,0 +1,3 @@
class ConfigOptions {
static const int listLimit = 20;
}

View File

@@ -4,9 +4,9 @@
/// To regenerate, run: `dart run slang`
///
/// Locales: 2
/// Strings: 256 (128 per locale)
/// Strings: 268 (134 per locale)
///
/// Built on 2024-02-25 at 19:19 UTC
/// Built on 2024-02-25 at 20:04 UTC
// coverage:ignore-file
// ignore_for_file: type=lint
@@ -367,6 +367,12 @@ class _StringsBookmarksBookmarkOptionsEn {
String get bookmarkNotDeleted => 'The bookmark couldn\'t be deleted due to an error.';
String get deleteBookmark => 'Delete bookmark';
String get followingBookmarkDeleted => 'The following bookmark will be deleted:';
String get markingAsRead => 'Marking as read...';
String get markingAsUnead => 'Marking as unread...';
String get markedAsReadSuccessfully => 'Bookmark marked as read successfully.';
String get markedAsUnreadSuccessfully => 'Bookmark marked as unread successfully.';
String get bookmarkNotMarkedAsRead => 'The bookmark couldn\'t be marked as read.';
String get bookmarkNotMarkedAsUnread => 'The bookmark couldn\'t be marked as unread.';
}
// Path: tags.createTag
@@ -681,6 +687,12 @@ class _StringsBookmarksBookmarkOptionsEs implements _StringsBookmarksBookmarkOpt
@override String get bookmarkNotDeleted => 'El marcador no se ha podido eliminar debido a un error.';
@override String get deleteBookmark => 'Eliminar marcador';
@override String get followingBookmarkDeleted => 'El siguiente marcador será eliminado:';
@override String get markingAsRead => 'Marcando como leído...';
@override String get markingAsUnead => 'Marcando como no leído...';
@override String get markedAsReadSuccessfully => 'Marcador marcado como leído correctamente..';
@override String get markedAsUnreadSuccessfully => 'Marcador marcado como no leído correctamente.';
@override String get bookmarkNotMarkedAsRead => 'El marcador no se ha podido marcar como leído.';
@override String get bookmarkNotMarkedAsUnread => 'El marcador no se ha podido marcar como no leído.';
}
// Path: tags.createTag
@@ -836,6 +848,12 @@ extension on Translations {
case 'bookmarks.bookmarkOptions.bookmarkNotDeleted': return 'The bookmark couldn\'t be deleted due to an error.';
case 'bookmarks.bookmarkOptions.deleteBookmark': return 'Delete bookmark';
case 'bookmarks.bookmarkOptions.followingBookmarkDeleted': return 'The following bookmark will be deleted:';
case 'bookmarks.bookmarkOptions.markingAsRead': return 'Marking as read...';
case 'bookmarks.bookmarkOptions.markingAsUnead': return 'Marking as unread...';
case 'bookmarks.bookmarkOptions.markedAsReadSuccessfully': return 'Bookmark marked as read successfully.';
case 'bookmarks.bookmarkOptions.markedAsUnreadSuccessfully': return 'Bookmark marked as unread successfully.';
case 'bookmarks.bookmarkOptions.bookmarkNotMarkedAsRead': return 'The bookmark couldn\'t be marked as read.';
case 'bookmarks.bookmarkOptions.bookmarkNotMarkedAsUnread': return 'The bookmark couldn\'t be marked as unread.';
case 'tags.tags': return 'Tags';
case 'tags.created': return ({required Object created}) => 'Created: ${created}';
case 'tags.createTag.createTag': return 'Create tag';
@@ -972,6 +990,12 @@ extension on _StringsEs {
case 'bookmarks.bookmarkOptions.bookmarkNotDeleted': return 'El marcador no se ha podido eliminar debido a un error.';
case 'bookmarks.bookmarkOptions.deleteBookmark': return 'Eliminar marcador';
case 'bookmarks.bookmarkOptions.followingBookmarkDeleted': return 'El siguiente marcador será eliminado:';
case 'bookmarks.bookmarkOptions.markingAsRead': return 'Marcando como leído...';
case 'bookmarks.bookmarkOptions.markingAsUnead': return 'Marcando como no leído...';
case 'bookmarks.bookmarkOptions.markedAsReadSuccessfully': return 'Marcador marcado como leído correctamente..';
case 'bookmarks.bookmarkOptions.markedAsUnreadSuccessfully': return 'Marcador marcado como no leído correctamente.';
case 'bookmarks.bookmarkOptions.bookmarkNotMarkedAsRead': return 'El marcador no se ha podido marcar como leído.';
case 'bookmarks.bookmarkOptions.bookmarkNotMarkedAsUnread': return 'El marcador no se ha podido marcar como no leído.';
case 'tags.tags': return 'Etiquetas';
case 'tags.created': return ({required Object created}) => 'Creado: ${created}';
case 'tags.createTag.createTag': return 'Crear etiqueta';

View File

@@ -88,7 +88,13 @@
"bookmarkDeleted": "Bookmark deleted successfully",
"bookmarkNotDeleted": "The bookmark couldn't be deleted due to an error.",
"deleteBookmark": "Delete bookmark",
"followingBookmarkDeleted": "The following bookmark will be deleted:"
"followingBookmarkDeleted": "The following bookmark will be deleted:",
"markingAsRead": "Marking as read...",
"markingAsUnead": "Marking as unread...",
"markedAsReadSuccessfully": "Bookmark marked as read successfully.",
"markedAsUnreadSuccessfully": "Bookmark marked as unread successfully.",
"bookmarkNotMarkedAsRead": "The bookmark couldn't be marked as read.",
"bookmarkNotMarkedAsUnread": "The bookmark couldn't be marked as unread."
}
},
"tags": {

View File

@@ -88,7 +88,13 @@
"bookmarkDeleted": "Marcador eliminado correctamente",
"bookmarkNotDeleted": "El marcador no se ha podido eliminar debido a un error.",
"deleteBookmark": "Eliminar marcador",
"followingBookmarkDeleted": "El siguiente marcador será eliminado:"
"followingBookmarkDeleted": "El siguiente marcador será eliminado:",
"markingAsRead": "Marcando como leído...",
"markingAsUnead": "Marcando como no leído...",
"markedAsReadSuccessfully": "Marcador marcado como leído correctamente..",
"markedAsUnreadSuccessfully": "Marcador marcado como no leído correctamente.",
"bookmarkNotMarkedAsRead": "El marcador no se ha podido marcar como leído.",
"bookmarkNotMarkedAsUnread": "El marcador no se ha podido marcar como no leído."
}
},
"tags": {

View File

@@ -1,4 +1,4 @@
class PostBookmark {
class SetBookmarkData {
final String url;
final String title;
final String description;
@@ -7,7 +7,7 @@ class PostBookmark {
final bool shared;
final String tagNames;
const PostBookmark({
const SetBookmarkData({
required this.url,
required this.title,
required this.description,

View File

@@ -1,3 +1,4 @@
import 'package:linkdy/config/options.dart';
import 'package:linkdy/constants/enums.dart';
import 'package:linkdy/models/data/bookmarks.dart';
@@ -11,7 +12,7 @@ class BookmarksModel {
BookmarksModel({
this.currentPage = 0,
this.limit = 30,
this.limit = ConfigOptions.listLimit,
required this.bookmarks,
this.inialLoadStatus = LoadStatus.loading,
this.loadingMore = false,

View File

@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:linkdy/config/options.dart';
import 'package:linkdy/constants/enums.dart';
import 'package:linkdy/models/data/bookmarks.dart';
@@ -17,7 +18,7 @@ class SearchBookmarksModel {
required this.searchController,
this.searchTerm = "",
this.currentPage = 0,
this.limit = 30,
this.limit = ConfigOptions.listLimit,
required this.bookmarks,
this.inialLoadStatus = LoadStatus.loaded,
this.loadingMore = false,

View File

@@ -8,7 +8,7 @@ import 'package:linkdy/models/data/tags.dart';
import 'package:linkdy/utils/snackbar.dart';
import 'package:linkdy/i18n/strings.g.dart';
import 'package:linkdy/utils/process_modal.dart';
import 'package:linkdy/models/data/post_bookmark.dart';
import 'package:linkdy/models/data/set_bookmark_data.dart';
import 'package:linkdy/providers/router.provider.dart';
import 'package:linkdy/constants/enums.dart';
import 'package:linkdy/constants/regexp.dart';
@@ -78,7 +78,7 @@ class AddBookmark extends _$AddBookmark {
}
void addBookmark() async {
final newBookmark = PostBookmark(
final newBookmark = SetBookmarkData(
url: state.urlController.text,
title: state.titleController.text != "" ? state.titleController.text : state.checkBookmark?.metadata?.title ?? '',
description: state.descriptionController.text != ""

View File

@@ -4,6 +4,7 @@ import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:linkdy/screens/bookmarks/provider/favicon_loader.provider.dart';
import 'package:linkdy/screens/bookmarks/model/bookmarks.model.dart';
import 'package:linkdy/models/data/set_bookmark_data.dart';
import 'package:linkdy/utils/process_modal.dart';
import 'package:linkdy/utils/snackbar.dart';
import 'package:linkdy/i18n/strings.g.dart';
@@ -101,4 +102,43 @@ class Bookmarks extends _$Bookmarks {
showSnacbkar(label: t.bookmarks.bookmarkOptions.bookmarkNotDeleted, color: Colors.red);
}
}
void markAsReadUnread(Bookmark bookmark) async {
final processModal = ProcessModal();
processModal.open(
bookmark.unread == true ? t.bookmarks.bookmarkOptions.markingAsRead : t.bookmarks.bookmarkOptions.markingAsUnead,
);
final result = await ref.read(apiClientProvider)!.putUpdateBookmark(
bookmark.id!,
SetBookmarkData(
url: bookmark.url!,
description: bookmark.description ?? '',
isArchived: bookmark.isArchived ?? false,
shared: bookmark.shared ?? false,
unread: bookmark.unread == true ? false : true,
tagNames: bookmark.tagNames?.join(",") ?? '',
title: bookmark.title ?? '',
),
);
processModal.close();
if (result.successful == true) {
state.bookmarks = state.bookmarks.map((b) => b.id == result.content!.id ? result.content! : b).toList();
ref.notifyListeners();
showSnacbkar(
label: bookmark.unread == true
? t.bookmarks.bookmarkOptions.markedAsReadSuccessfully
: t.bookmarks.bookmarkOptions.markedAsUnreadSuccessfully,
color: Colors.green,
);
} else {
showSnacbkar(
label: bookmark.unread == true
? t.bookmarks.bookmarkOptions.bookmarkNotMarkedAsRead
: t.bookmarks.bookmarkOptions.bookmarkNotMarkedAsUnread,
color: Colors.red,
);
}
}
}

View File

@@ -4,6 +4,7 @@ import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:skeletonizer/skeletonizer.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:linkdy/screens/bookmarks/provider/bookmarks.provider.dart';
import 'package:linkdy/screens/bookmarks/ui/delete_bookmark_modal.dart';
import 'package:linkdy/screens/bookmarks/provider/favicon_loader.provider.dart';
@@ -48,10 +49,10 @@ class BookmarkItem extends ConsumerWidget {
extentRatio: 0.75,
children: [
SlidableAction(
onPressed: (ctx) => {},
onPressed: (ctx) => ref.read(bookmarksProvider.notifier).markAsReadUnread(bookmark),
backgroundColor: Colors.blue,
label: t.bookmarks.bookmarkOptions.unread,
icon: Icons.mark_as_unread_rounded,
label: bookmark.unread == true ? t.bookmarks.bookmarkOptions.read : t.bookmarks.bookmarkOptions.unread,
icon: bookmark.unread == true ? Icons.mark_email_read_rounded : Icons.mark_as_unread_rounded,
padding: const EdgeInsets.all(4),
),
SlidableAction(
@@ -203,13 +204,14 @@ class BookmarkItem extends ConsumerWidget {
child: Text(
bookmark.tagNames?.map((tag) => "#$tag").join(" ") ?? '',
overflow: TextOverflow.ellipsis,
style: const TextStyle(
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w500,
color: Theme.of(context).colorScheme.onSurface,
),
),
),
if (bookmark.dateModified != null) ...[
if (bookmark.unread == true) ...[
if (bookmark.tagNames?.isNotEmpty == true)
Container(
width: 1,
@@ -217,6 +219,33 @@ class BookmarkItem extends ConsumerWidget {
margin: const EdgeInsets.symmetric(horizontal: 8),
color: Theme.of(context).colorScheme.tertiary.withOpacity(0.3),
),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 6,
vertical: 2,
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Theme.of(context).colorScheme.primaryContainer,
),
child: Text(
t.bookmarks.bookmarkOptions.unread,
style: TextStyle(
fontSize: 10,
color: Theme.of(context).colorScheme.onPrimaryContainer,
fontWeight: FontWeight.w700,
),
),
),
],
if (bookmark.dateModified != null) ...[
if (bookmark.unread == true)
Container(
width: 1,
height: 12,
margin: const EdgeInsets.symmetric(horizontal: 8),
color: Theme.of(context).colorScheme.tertiary.withOpacity(0.3),
),
Text(
dateToString(bookmark.dateModified!),
style: TextStyle(

View File

@@ -1,3 +1,4 @@
import 'package:linkdy/config/options.dart';
import 'package:linkdy/constants/enums.dart';
import 'package:linkdy/models/data/bookmarks.dart';
import 'package:linkdy/models/data/tags.dart';
@@ -16,7 +17,7 @@ class TagBookmarksModel {
this.tagId,
this.tag,
this.currentPage = 0,
this.limit = 30,
this.limit = ConfigOptions.listLimit,
this.initialLoadStatus = LoadStatus.loading,
required this.bookmarks,
this.maxNumber = 0,

View File

@@ -5,7 +5,7 @@ import 'package:linkdy/constants/enums.dart';
import 'package:linkdy/models/api_response.dart';
import 'package:linkdy/models/data/bookmarks.dart';
import 'package:linkdy/models/data/check_bookmark.dart';
import 'package:linkdy/models/data/post_bookmark.dart';
import 'package:linkdy/models/data/set_bookmark_data.dart';
import 'package:linkdy/models/data/tags.dart';
import 'package:linkdy/models/server_instance.dart';
@@ -70,7 +70,7 @@ class ApiClientService {
}
}
Future<ApiResponse<Bookmark>> postBookmark(PostBookmark bookmark) async {
Future<ApiResponse<Bookmark>> postBookmark(SetBookmarkData bookmark) async {
try {
final response = await dioInstance.post(
"/bookmarks/",
@@ -144,4 +144,20 @@ class ApiClientService {
return const ApiResponse(successful: false);
}
}
Future<ApiResponse<Bookmark>> putUpdateBookmark(int bookmarkId, SetBookmarkData bookmark) async {
try {
final result = await dioInstance.put(
"/bookmarks/$bookmarkId/",
data: FormData.fromMap(bookmark.toJson()),
);
return ApiResponse(
successful: true,
content: Bookmark.fromJson(result.data),
);
} catch (e, stackTrace) {
Sentry.captureException(e, stackTrace: stackTrace);
return const ApiResponse(successful: false);
}
}
}