Added mark as read or unread
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 != ""
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user