bookmarks feature initial
This commit is contained in:
@@ -79,6 +79,26 @@ part of 'routes.dart';
|
||||
),
|
||||
],
|
||||
),
|
||||
TypedGoRoute<BookmarkListRoute>(
|
||||
name: 'BookmarkListRoute',
|
||||
path: 'bookmarks/:entryGuid',
|
||||
),
|
||||
TypedGoRoute<BookmarkFolderAddRoute>(
|
||||
name: 'BookmarkFolderAddRoute',
|
||||
path: 'createFolder',
|
||||
),
|
||||
TypedGoRoute<BookmarkFolderEditRoute>(
|
||||
name: 'BookmarkFolderEditRoute',
|
||||
path: 'editFolder',
|
||||
),
|
||||
TypedGoRoute<BookmarkEntryAddRoute>(
|
||||
name: 'BookmarkEntryAddRoute',
|
||||
path: 'createEntry',
|
||||
),
|
||||
TypedGoRoute<BookmarkEntryEditRoute>(
|
||||
name: 'BookmarkEntryEditRoute',
|
||||
path: 'editEntry',
|
||||
),
|
||||
],
|
||||
)
|
||||
class BrowserRoute extends GoRouteData with $BrowserRoute {
|
||||
@@ -282,3 +302,71 @@ class EditProfileRoute extends GoRouteData with $EditProfileRoute {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class BookmarkListRoute extends GoRouteData with $BookmarkListRoute {
|
||||
final String entryGuid;
|
||||
|
||||
const BookmarkListRoute({required this.entryGuid});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, GoRouterState state) {
|
||||
return BookmarkListScreen(entryGuid: entryGuid);
|
||||
}
|
||||
}
|
||||
|
||||
class BookmarkFolderAddRoute extends GoRouteData with $BookmarkFolderAddRoute {
|
||||
final String? parentGuid;
|
||||
|
||||
const BookmarkFolderAddRoute({required this.parentGuid});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, GoRouterState state) {
|
||||
return BookmarkFolderEditScreen(parentGuid: parentGuid, folder: null);
|
||||
}
|
||||
}
|
||||
|
||||
class BookmarkFolderEditRoute extends GoRouteData
|
||||
with $BookmarkFolderEditRoute {
|
||||
final String folder;
|
||||
|
||||
const BookmarkFolderEditRoute({required this.folder});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, GoRouterState state) {
|
||||
return BookmarkFolderEditScreen(
|
||||
folder: BookmarkFolder.fromJson(
|
||||
jsonDecode(folder) as Map<String, dynamic>,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class BookmarkEntryAddRoute extends GoRouteData with $BookmarkEntryAddRoute {
|
||||
final String bookmarkInfo;
|
||||
|
||||
const BookmarkEntryAddRoute({required this.bookmarkInfo});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, GoRouterState state) {
|
||||
return BookmarkEntryEditScreen(
|
||||
initialInfo: BookmarkInfo.decode(jsonDecode(bookmarkInfo) as Object),
|
||||
exisitingEntry: null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class BookmarkEntryEditRoute extends GoRouteData with $BookmarkEntryEditRoute {
|
||||
final String bookmarkEntry;
|
||||
|
||||
const BookmarkEntryEditRoute({required this.bookmarkEntry});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, GoRouterState state) {
|
||||
return BookmarkEntryEditScreen(
|
||||
initialInfo: null,
|
||||
exisitingEntry: BookmarkEntry.fromJson(
|
||||
jsonDecode(bookmarkEntry) as Map<String, dynamic>,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_mozilla_components/flutter_mozilla_components.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:nullability/nullability.dart';
|
||||
import 'package:weblibre/core/routing/widgets/dialog_page.dart';
|
||||
@@ -32,6 +33,10 @@ import 'package:weblibre/features/bangs/presentation/screens/edit.dart';
|
||||
import 'package:weblibre/features/bangs/presentation/screens/menu.dart';
|
||||
import 'package:weblibre/features/bangs/presentation/screens/search.dart';
|
||||
import 'package:weblibre/features/bangs/presentation/screens/user.dart';
|
||||
import 'package:weblibre/features/geckoview/features/bookmarks/domain/entities/bookmark_item.dart';
|
||||
import 'package:weblibre/features/geckoview/features/bookmarks/presentation/screens/bookmark_entry_edit.dart';
|
||||
import 'package:weblibre/features/geckoview/features/bookmarks/presentation/screens/bookmark_folder_edit.dart';
|
||||
import 'package:weblibre/features/geckoview/features/bookmarks/presentation/screens/bookmark_list.dart';
|
||||
import 'package:weblibre/features/geckoview/features/browser/presentation/dialogs/open_shared_content.dart';
|
||||
import 'package:weblibre/features/geckoview/features/browser/presentation/dialogs/tab_tree.dart';
|
||||
import 'package:weblibre/features/geckoview/features/browser/presentation/screens/browser.dart';
|
||||
|
||||
@@ -464,6 +464,31 @@ RouteBase get $browserRoute => GoRouteData.$route(
|
||||
),
|
||||
],
|
||||
),
|
||||
GoRouteData.$route(
|
||||
path: 'bookmarks/:entryGuid',
|
||||
name: 'BookmarkListRoute',
|
||||
factory: $BookmarkListRoute._fromState,
|
||||
),
|
||||
GoRouteData.$route(
|
||||
path: 'createFolder',
|
||||
name: 'BookmarkFolderAddRoute',
|
||||
factory: $BookmarkFolderAddRoute._fromState,
|
||||
),
|
||||
GoRouteData.$route(
|
||||
path: 'editFolder',
|
||||
name: 'BookmarkFolderEditRoute',
|
||||
factory: $BookmarkFolderEditRoute._fromState,
|
||||
),
|
||||
GoRouteData.$route(
|
||||
path: 'createEntry',
|
||||
name: 'BookmarkEntryAddRoute',
|
||||
factory: $BookmarkEntryAddRoute._fromState,
|
||||
),
|
||||
GoRouteData.$route(
|
||||
path: 'editEntry',
|
||||
name: 'BookmarkEntryEditRoute',
|
||||
factory: $BookmarkEntryEditRoute._fromState,
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -876,6 +901,143 @@ mixin $CreateProfileRoute on GoRouteData {
|
||||
void replace(BuildContext context) => context.replace(location);
|
||||
}
|
||||
|
||||
mixin $BookmarkListRoute on GoRouteData {
|
||||
static BookmarkListRoute _fromState(GoRouterState state) =>
|
||||
BookmarkListRoute(entryGuid: state.pathParameters['entryGuid']!);
|
||||
|
||||
BookmarkListRoute get _self => this as BookmarkListRoute;
|
||||
|
||||
@override
|
||||
String get location => GoRouteData.$location(
|
||||
'/browser/bookmarks/${Uri.encodeComponent(_self.entryGuid)}',
|
||||
);
|
||||
|
||||
@override
|
||||
void go(BuildContext context) => context.go(location);
|
||||
|
||||
@override
|
||||
Future<T?> push<T>(BuildContext context) => context.push<T>(location);
|
||||
|
||||
@override
|
||||
void pushReplacement(BuildContext context) =>
|
||||
context.pushReplacement(location);
|
||||
|
||||
@override
|
||||
void replace(BuildContext context) => context.replace(location);
|
||||
}
|
||||
|
||||
mixin $BookmarkFolderAddRoute on GoRouteData {
|
||||
static BookmarkFolderAddRoute _fromState(GoRouterState state) =>
|
||||
BookmarkFolderAddRoute(
|
||||
parentGuid: state.uri.queryParameters['parent-guid'],
|
||||
);
|
||||
|
||||
BookmarkFolderAddRoute get _self => this as BookmarkFolderAddRoute;
|
||||
|
||||
@override
|
||||
String get location => GoRouteData.$location(
|
||||
'/browser/createFolder',
|
||||
queryParams: {
|
||||
if (_self.parentGuid != null) 'parent-guid': _self.parentGuid,
|
||||
},
|
||||
);
|
||||
|
||||
@override
|
||||
void go(BuildContext context) => context.go(location);
|
||||
|
||||
@override
|
||||
Future<T?> push<T>(BuildContext context) => context.push<T>(location);
|
||||
|
||||
@override
|
||||
void pushReplacement(BuildContext context) =>
|
||||
context.pushReplacement(location);
|
||||
|
||||
@override
|
||||
void replace(BuildContext context) => context.replace(location);
|
||||
}
|
||||
|
||||
mixin $BookmarkFolderEditRoute on GoRouteData {
|
||||
static BookmarkFolderEditRoute _fromState(GoRouterState state) =>
|
||||
BookmarkFolderEditRoute(folder: state.uri.queryParameters['folder']!);
|
||||
|
||||
BookmarkFolderEditRoute get _self => this as BookmarkFolderEditRoute;
|
||||
|
||||
@override
|
||||
String get location => GoRouteData.$location(
|
||||
'/browser/editFolder',
|
||||
queryParams: {'folder': _self.folder},
|
||||
);
|
||||
|
||||
@override
|
||||
void go(BuildContext context) => context.go(location);
|
||||
|
||||
@override
|
||||
Future<T?> push<T>(BuildContext context) => context.push<T>(location);
|
||||
|
||||
@override
|
||||
void pushReplacement(BuildContext context) =>
|
||||
context.pushReplacement(location);
|
||||
|
||||
@override
|
||||
void replace(BuildContext context) => context.replace(location);
|
||||
}
|
||||
|
||||
mixin $BookmarkEntryAddRoute on GoRouteData {
|
||||
static BookmarkEntryAddRoute _fromState(GoRouterState state) =>
|
||||
BookmarkEntryAddRoute(
|
||||
bookmarkInfo: state.uri.queryParameters['bookmark-info']!,
|
||||
);
|
||||
|
||||
BookmarkEntryAddRoute get _self => this as BookmarkEntryAddRoute;
|
||||
|
||||
@override
|
||||
String get location => GoRouteData.$location(
|
||||
'/browser/createEntry',
|
||||
queryParams: {'bookmark-info': _self.bookmarkInfo},
|
||||
);
|
||||
|
||||
@override
|
||||
void go(BuildContext context) => context.go(location);
|
||||
|
||||
@override
|
||||
Future<T?> push<T>(BuildContext context) => context.push<T>(location);
|
||||
|
||||
@override
|
||||
void pushReplacement(BuildContext context) =>
|
||||
context.pushReplacement(location);
|
||||
|
||||
@override
|
||||
void replace(BuildContext context) => context.replace(location);
|
||||
}
|
||||
|
||||
mixin $BookmarkEntryEditRoute on GoRouteData {
|
||||
static BookmarkEntryEditRoute _fromState(GoRouterState state) =>
|
||||
BookmarkEntryEditRoute(
|
||||
bookmarkEntry: state.uri.queryParameters['bookmark-entry']!,
|
||||
);
|
||||
|
||||
BookmarkEntryEditRoute get _self => this as BookmarkEntryEditRoute;
|
||||
|
||||
@override
|
||||
String get location => GoRouteData.$location(
|
||||
'/browser/editEntry',
|
||||
queryParams: {'bookmark-entry': _self.bookmarkEntry},
|
||||
);
|
||||
|
||||
@override
|
||||
void go(BuildContext context) => context.go(location);
|
||||
|
||||
@override
|
||||
Future<T?> push<T>(BuildContext context) => context.push<T>(location);
|
||||
|
||||
@override
|
||||
void pushReplacement(BuildContext context) =>
|
||||
context.pushReplacement(location);
|
||||
|
||||
@override
|
||||
void replace(BuildContext context) => context.replace(location);
|
||||
}
|
||||
|
||||
T? _$convertMapValue<T>(
|
||||
String key,
|
||||
Map<String, String> map,
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
import 'package:copy_with_extension/copy_with_extension.dart';
|
||||
import 'package:fast_equatable/fast_equatable.dart';
|
||||
import 'package:flutter_mozilla_components/flutter_mozilla_components.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'bookmark_item.g.dart';
|
||||
|
||||
sealed class BookmarkItem {
|
||||
abstract final String guid;
|
||||
abstract final String? parentGuid;
|
||||
abstract final String title;
|
||||
abstract final int dateAdded;
|
||||
abstract final int? position;
|
||||
|
||||
const BookmarkItem();
|
||||
|
||||
static BookmarkItem? parseRecursive(BookmarkNode node) {
|
||||
return switch (node.type) {
|
||||
BookmarkNodeType.item => BookmarkEntry(
|
||||
guid: node.guid,
|
||||
parentGuid: node.parentGuid,
|
||||
url: Uri.parse(node.url!),
|
||||
title: node.title ?? node.url!,
|
||||
previewImageUrl: Uri.parse(node.url!),
|
||||
position: node.position,
|
||||
dateAdded: node.dateAdded,
|
||||
),
|
||||
BookmarkNodeType.folder => BookmarkFolder(
|
||||
guid: node.guid,
|
||||
parentGuid: node.parentGuid,
|
||||
title: node.title ?? "Unnamed Folder",
|
||||
position: node.position,
|
||||
dateAdded: node.dateAdded,
|
||||
children: node.children?.map(parseRecursive).nonNulls.toList(),
|
||||
),
|
||||
BookmarkNodeType.separator => null,
|
||||
};
|
||||
}
|
||||
|
||||
factory BookmarkItem.fromJson(Map<String, dynamic> json) {
|
||||
return (json.containsKey('url'))
|
||||
? BookmarkEntry.fromJson(json)
|
||||
: BookmarkFolder.fromJson(json);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson();
|
||||
|
||||
BookmarkItem clone();
|
||||
}
|
||||
|
||||
@CopyWith()
|
||||
@JsonSerializable()
|
||||
class BookmarkEntry extends BookmarkItem with FastEquatable {
|
||||
@override
|
||||
final String guid;
|
||||
@override
|
||||
final String? parentGuid;
|
||||
final Uri url;
|
||||
@override
|
||||
final String title;
|
||||
final Uri previewImageUrl;
|
||||
@override
|
||||
final int? position;
|
||||
@override
|
||||
final int dateAdded;
|
||||
|
||||
BookmarkEntry({
|
||||
required this.guid,
|
||||
required this.parentGuid,
|
||||
required this.url,
|
||||
required this.title,
|
||||
required this.previewImageUrl,
|
||||
required this.position,
|
||||
required this.dateAdded,
|
||||
});
|
||||
|
||||
factory BookmarkEntry.fromJson(Map<String, dynamic> json) =>
|
||||
_$BookmarkEntryFromJson(json);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$BookmarkEntryToJson(this);
|
||||
|
||||
@override
|
||||
BookmarkItem clone() {
|
||||
return copyWith();
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get hashParameters => [
|
||||
guid,
|
||||
parentGuid,
|
||||
url,
|
||||
title,
|
||||
previewImageUrl,
|
||||
position,
|
||||
dateAdded,
|
||||
];
|
||||
}
|
||||
|
||||
@CopyWith()
|
||||
@JsonSerializable()
|
||||
class BookmarkFolder extends BookmarkItem with FastEquatable {
|
||||
@override
|
||||
final String guid;
|
||||
@override
|
||||
final String? parentGuid;
|
||||
@override
|
||||
final String title;
|
||||
@override
|
||||
final int? position;
|
||||
@override
|
||||
final int dateAdded;
|
||||
|
||||
final List<BookmarkItem>? children;
|
||||
|
||||
BookmarkFolder({
|
||||
required this.guid,
|
||||
required this.parentGuid,
|
||||
required String title,
|
||||
required this.position,
|
||||
required this.dateAdded,
|
||||
required this.children,
|
||||
}) : title = bookmarkRootDisplayNames[guid] ?? title;
|
||||
|
||||
factory BookmarkFolder.fromJson(Map<String, dynamic> json) =>
|
||||
_$BookmarkFolderFromJson(json);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$BookmarkFolderToJson(this);
|
||||
|
||||
@override
|
||||
BookmarkItem clone() {
|
||||
return copyWith();
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get hashParameters => [
|
||||
guid,
|
||||
parentGuid,
|
||||
title,
|
||||
position,
|
||||
dateAdded,
|
||||
children,
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,284 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'bookmark_item.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// CopyWithGenerator
|
||||
// **************************************************************************
|
||||
|
||||
abstract class _$BookmarkEntryCWProxy {
|
||||
BookmarkEntry guid(String guid);
|
||||
|
||||
BookmarkEntry parentGuid(String? parentGuid);
|
||||
|
||||
BookmarkEntry url(Uri url);
|
||||
|
||||
BookmarkEntry title(String title);
|
||||
|
||||
BookmarkEntry previewImageUrl(Uri previewImageUrl);
|
||||
|
||||
BookmarkEntry position(int? position);
|
||||
|
||||
BookmarkEntry dateAdded(int dateAdded);
|
||||
|
||||
/// Creates a new instance with the provided field values.
|
||||
/// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `BookmarkEntry(...).copyWith.fieldName(value)`.
|
||||
///
|
||||
/// Example:
|
||||
/// ```dart
|
||||
/// BookmarkEntry(...).copyWith(id: 12, name: "My name")
|
||||
/// ```
|
||||
BookmarkEntry call({
|
||||
String guid,
|
||||
String? parentGuid,
|
||||
Uri url,
|
||||
String title,
|
||||
Uri previewImageUrl,
|
||||
int? position,
|
||||
int dateAdded,
|
||||
});
|
||||
}
|
||||
|
||||
/// Callable proxy for `copyWith` functionality.
|
||||
/// Use as `instanceOfBookmarkEntry.copyWith(...)` or call `instanceOfBookmarkEntry.copyWith.fieldName(value)` for a single field.
|
||||
class _$BookmarkEntryCWProxyImpl implements _$BookmarkEntryCWProxy {
|
||||
const _$BookmarkEntryCWProxyImpl(this._value);
|
||||
|
||||
final BookmarkEntry _value;
|
||||
|
||||
@override
|
||||
BookmarkEntry guid(String guid) => call(guid: guid);
|
||||
|
||||
@override
|
||||
BookmarkEntry parentGuid(String? parentGuid) => call(parentGuid: parentGuid);
|
||||
|
||||
@override
|
||||
BookmarkEntry url(Uri url) => call(url: url);
|
||||
|
||||
@override
|
||||
BookmarkEntry title(String title) => call(title: title);
|
||||
|
||||
@override
|
||||
BookmarkEntry previewImageUrl(Uri previewImageUrl) =>
|
||||
call(previewImageUrl: previewImageUrl);
|
||||
|
||||
@override
|
||||
BookmarkEntry position(int? position) => call(position: position);
|
||||
|
||||
@override
|
||||
BookmarkEntry dateAdded(int dateAdded) => call(dateAdded: dateAdded);
|
||||
|
||||
@override
|
||||
/// Creates a new instance with the provided field values.
|
||||
/// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `BookmarkEntry(...).copyWith.fieldName(value)`.
|
||||
///
|
||||
/// Example:
|
||||
/// ```dart
|
||||
/// BookmarkEntry(...).copyWith(id: 12, name: "My name")
|
||||
/// ```
|
||||
BookmarkEntry call({
|
||||
Object? guid = const $CopyWithPlaceholder(),
|
||||
Object? parentGuid = const $CopyWithPlaceholder(),
|
||||
Object? url = const $CopyWithPlaceholder(),
|
||||
Object? title = const $CopyWithPlaceholder(),
|
||||
Object? previewImageUrl = const $CopyWithPlaceholder(),
|
||||
Object? position = const $CopyWithPlaceholder(),
|
||||
Object? dateAdded = const $CopyWithPlaceholder(),
|
||||
}) {
|
||||
return BookmarkEntry(
|
||||
guid: guid == const $CopyWithPlaceholder() || guid == null
|
||||
? _value.guid
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: guid as String,
|
||||
parentGuid: parentGuid == const $CopyWithPlaceholder()
|
||||
? _value.parentGuid
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: parentGuid as String?,
|
||||
url: url == const $CopyWithPlaceholder() || url == null
|
||||
? _value.url
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: url as Uri,
|
||||
title: title == const $CopyWithPlaceholder() || title == null
|
||||
? _value.title
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: title as String,
|
||||
previewImageUrl:
|
||||
previewImageUrl == const $CopyWithPlaceholder() ||
|
||||
previewImageUrl == null
|
||||
? _value.previewImageUrl
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: previewImageUrl as Uri,
|
||||
position: position == const $CopyWithPlaceholder()
|
||||
? _value.position
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: position as int?,
|
||||
dateAdded: dateAdded == const $CopyWithPlaceholder() || dateAdded == null
|
||||
? _value.dateAdded
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: dateAdded as int,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
extension $BookmarkEntryCopyWith on BookmarkEntry {
|
||||
/// Returns a callable class used to build a new instance with modified fields.
|
||||
/// Example: `instanceOfBookmarkEntry.copyWith(...)` or `instanceOfBookmarkEntry.copyWith.fieldName(...)`.
|
||||
// ignore: library_private_types_in_public_api
|
||||
_$BookmarkEntryCWProxy get copyWith => _$BookmarkEntryCWProxyImpl(this);
|
||||
}
|
||||
|
||||
abstract class _$BookmarkFolderCWProxy {
|
||||
BookmarkFolder guid(String guid);
|
||||
|
||||
BookmarkFolder parentGuid(String? parentGuid);
|
||||
|
||||
BookmarkFolder title(String title);
|
||||
|
||||
BookmarkFolder position(int? position);
|
||||
|
||||
BookmarkFolder dateAdded(int dateAdded);
|
||||
|
||||
BookmarkFolder children(List<BookmarkItem>? children);
|
||||
|
||||
/// Creates a new instance with the provided field values.
|
||||
/// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `BookmarkFolder(...).copyWith.fieldName(value)`.
|
||||
///
|
||||
/// Example:
|
||||
/// ```dart
|
||||
/// BookmarkFolder(...).copyWith(id: 12, name: "My name")
|
||||
/// ```
|
||||
BookmarkFolder call({
|
||||
String guid,
|
||||
String? parentGuid,
|
||||
String title,
|
||||
int? position,
|
||||
int dateAdded,
|
||||
List<BookmarkItem>? children,
|
||||
});
|
||||
}
|
||||
|
||||
/// Callable proxy for `copyWith` functionality.
|
||||
/// Use as `instanceOfBookmarkFolder.copyWith(...)` or call `instanceOfBookmarkFolder.copyWith.fieldName(value)` for a single field.
|
||||
class _$BookmarkFolderCWProxyImpl implements _$BookmarkFolderCWProxy {
|
||||
const _$BookmarkFolderCWProxyImpl(this._value);
|
||||
|
||||
final BookmarkFolder _value;
|
||||
|
||||
@override
|
||||
BookmarkFolder guid(String guid) => call(guid: guid);
|
||||
|
||||
@override
|
||||
BookmarkFolder parentGuid(String? parentGuid) => call(parentGuid: parentGuid);
|
||||
|
||||
@override
|
||||
BookmarkFolder title(String title) => call(title: title);
|
||||
|
||||
@override
|
||||
BookmarkFolder position(int? position) => call(position: position);
|
||||
|
||||
@override
|
||||
BookmarkFolder dateAdded(int dateAdded) => call(dateAdded: dateAdded);
|
||||
|
||||
@override
|
||||
BookmarkFolder children(List<BookmarkItem>? children) =>
|
||||
call(children: children);
|
||||
|
||||
@override
|
||||
/// Creates a new instance with the provided field values.
|
||||
/// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `BookmarkFolder(...).copyWith.fieldName(value)`.
|
||||
///
|
||||
/// Example:
|
||||
/// ```dart
|
||||
/// BookmarkFolder(...).copyWith(id: 12, name: "My name")
|
||||
/// ```
|
||||
BookmarkFolder call({
|
||||
Object? guid = const $CopyWithPlaceholder(),
|
||||
Object? parentGuid = const $CopyWithPlaceholder(),
|
||||
Object? title = const $CopyWithPlaceholder(),
|
||||
Object? position = const $CopyWithPlaceholder(),
|
||||
Object? dateAdded = const $CopyWithPlaceholder(),
|
||||
Object? children = const $CopyWithPlaceholder(),
|
||||
}) {
|
||||
return BookmarkFolder(
|
||||
guid: guid == const $CopyWithPlaceholder() || guid == null
|
||||
? _value.guid
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: guid as String,
|
||||
parentGuid: parentGuid == const $CopyWithPlaceholder()
|
||||
? _value.parentGuid
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: parentGuid as String?,
|
||||
title: title == const $CopyWithPlaceholder() || title == null
|
||||
? _value.title
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: title as String,
|
||||
position: position == const $CopyWithPlaceholder()
|
||||
? _value.position
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: position as int?,
|
||||
dateAdded: dateAdded == const $CopyWithPlaceholder() || dateAdded == null
|
||||
? _value.dateAdded
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: dateAdded as int,
|
||||
children: children == const $CopyWithPlaceholder()
|
||||
? _value.children
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: children as List<BookmarkItem>?,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
extension $BookmarkFolderCopyWith on BookmarkFolder {
|
||||
/// Returns a callable class used to build a new instance with modified fields.
|
||||
/// Example: `instanceOfBookmarkFolder.copyWith(...)` or `instanceOfBookmarkFolder.copyWith.fieldName(...)`.
|
||||
// ignore: library_private_types_in_public_api
|
||||
_$BookmarkFolderCWProxy get copyWith => _$BookmarkFolderCWProxyImpl(this);
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
BookmarkEntry _$BookmarkEntryFromJson(Map<String, dynamic> json) =>
|
||||
BookmarkEntry(
|
||||
guid: json['guid'] as String,
|
||||
parentGuid: json['parentGuid'] as String?,
|
||||
url: Uri.parse(json['url'] as String),
|
||||
title: json['title'] as String,
|
||||
previewImageUrl: Uri.parse(json['previewImageUrl'] as String),
|
||||
position: (json['position'] as num?)?.toInt(),
|
||||
dateAdded: (json['dateAdded'] as num).toInt(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$BookmarkEntryToJson(BookmarkEntry instance) =>
|
||||
<String, dynamic>{
|
||||
'guid': instance.guid,
|
||||
'parentGuid': instance.parentGuid,
|
||||
'url': instance.url.toString(),
|
||||
'title': instance.title,
|
||||
'previewImageUrl': instance.previewImageUrl.toString(),
|
||||
'position': instance.position,
|
||||
'dateAdded': instance.dateAdded,
|
||||
};
|
||||
|
||||
BookmarkFolder _$BookmarkFolderFromJson(Map<String, dynamic> json) =>
|
||||
BookmarkFolder(
|
||||
guid: json['guid'] as String,
|
||||
parentGuid: json['parentGuid'] as String?,
|
||||
title: json['title'] as String,
|
||||
position: (json['position'] as num?)?.toInt(),
|
||||
dateAdded: (json['dateAdded'] as num).toInt(),
|
||||
children: (json['children'] as List<dynamic>?)
|
||||
?.map((e) => BookmarkItem.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$BookmarkFolderToJson(BookmarkFolder instance) =>
|
||||
<String, dynamic>{
|
||||
'guid': instance.guid,
|
||||
'parentGuid': instance.parentGuid,
|
||||
'title': instance.title,
|
||||
'position': instance.position,
|
||||
'dateAdded': instance.dateAdded,
|
||||
'children': instance.children?.map((e) => e.toJson()).toList(),
|
||||
};
|
||||
@@ -0,0 +1,68 @@
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:weblibre/features/geckoview/features/bookmarks/domain/entities/bookmark_item.dart';
|
||||
import 'package:weblibre/features/geckoview/features/bookmarks/domain/repositories/bookmarks.dart';
|
||||
|
||||
part 'bookmarks.g.dart';
|
||||
|
||||
T? _selectChildRecursive<T extends BookmarkItem>(
|
||||
List<BookmarkItem> children,
|
||||
String guid,
|
||||
) {
|
||||
for (final child in children) {
|
||||
if (child.guid == guid && child is T) {
|
||||
return child;
|
||||
}
|
||||
|
||||
if (child case final BookmarkFolder folder) {
|
||||
if (folder.children != null) {
|
||||
final result = _selectChildRecursive<T>(folder.children!, guid);
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
T _cloneAndFilterChildrenType<T extends BookmarkItem>(T node) {
|
||||
if (node is BookmarkFolder) {
|
||||
if (node.children != null) {
|
||||
return node.copyWith.children(
|
||||
node.children
|
||||
?.whereType<T>()
|
||||
.map((e) => _cloneAndFilterChildrenType<T>(e))
|
||||
.toList(),
|
||||
)
|
||||
as T;
|
||||
}
|
||||
}
|
||||
|
||||
return node.clone() as T;
|
||||
}
|
||||
|
||||
@Riverpod()
|
||||
AsyncValue<T?> bookmarks<T extends BookmarkItem>(Ref ref, String entryGuid) {
|
||||
final bookmarksAsync = ref.watch(bookmarksRepositoryProvider);
|
||||
|
||||
return bookmarksAsync.whenData((bookmarkNode) {
|
||||
T? selectedNode;
|
||||
|
||||
if (bookmarkNode != null && bookmarkNode is T) {
|
||||
if (bookmarkNode.guid == entryGuid) {
|
||||
selectedNode = bookmarkNode;
|
||||
} else if (bookmarkNode case final BookmarkFolder folder) {
|
||||
if (folder.children != null) {
|
||||
selectedNode = _selectChildRecursive<T>(folder.children!, entryGuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (selectedNode != null) {
|
||||
return _cloneAndFilterChildrenType<T>(selectedNode);
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'bookmarks.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
|
||||
@ProviderFor(bookmarks)
|
||||
const bookmarksProvider = BookmarksFamily._();
|
||||
|
||||
final class BookmarksProvider<T extends BookmarkItem>
|
||||
extends $FunctionalProvider<AsyncValue<T?>, AsyncValue<T?>, AsyncValue<T?>>
|
||||
with $Provider<AsyncValue<T?>> {
|
||||
const BookmarksProvider._({
|
||||
required BookmarksFamily super.from,
|
||||
required String super.argument,
|
||||
}) : super(
|
||||
retry: null,
|
||||
name: r'bookmarksProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$bookmarksHash();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return r'bookmarksProvider'
|
||||
'<${T}>'
|
||||
'($argument)';
|
||||
}
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$ProviderElement<AsyncValue<T?>> $createElement($ProviderPointer pointer) =>
|
||||
$ProviderElement(pointer);
|
||||
|
||||
@override
|
||||
AsyncValue<T?> create(Ref ref) {
|
||||
final argument = this.argument as String;
|
||||
return bookmarks<T>(ref, argument);
|
||||
}
|
||||
|
||||
$R _captureGenerics<$R>($R Function<T extends BookmarkItem>() cb) {
|
||||
return cb<T>();
|
||||
}
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(AsyncValue<T?> value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<AsyncValue<T?>>(value),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return other is BookmarksProvider &&
|
||||
other.runtimeType == runtimeType &&
|
||||
other.argument == argument;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return Object.hash(runtimeType, argument);
|
||||
}
|
||||
}
|
||||
|
||||
String _$bookmarksHash() => r'dfa19aea04f352b8a6cefe35a0b283c9fddb214f';
|
||||
|
||||
final class BookmarksFamily extends $Family {
|
||||
const BookmarksFamily._()
|
||||
: super(
|
||||
retry: null,
|
||||
name: r'bookmarksProvider',
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
isAutoDispose: true,
|
||||
);
|
||||
|
||||
BookmarksProvider<T> call<T extends BookmarkItem>(String entryGuid) =>
|
||||
BookmarksProvider<T>._(argument: entryGuid, from: this);
|
||||
|
||||
@override
|
||||
String toString() => r'bookmarksProvider';
|
||||
|
||||
/// {@macro riverpod.override_with}
|
||||
Override overrideWith(
|
||||
AsyncValue<T?> Function<T extends BookmarkItem>(Ref ref, String args)
|
||||
create,
|
||||
) => $FamilyOverride(
|
||||
from: this,
|
||||
createElement: (pointer) {
|
||||
final provider = pointer.origin as BookmarksProvider;
|
||||
return provider._captureGenerics(<T extends BookmarkItem>() {
|
||||
provider as BookmarksProvider<T>;
|
||||
final argument = provider.argument as String;
|
||||
return provider
|
||||
.$view(create: (ref) => create(ref, argument))
|
||||
.$createElement(pointer);
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
import 'package:flutter_mozilla_components/flutter_mozilla_components.dart';
|
||||
import 'package:nullability/nullability.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:weblibre/features/geckoview/features/bookmarks/domain/entities/bookmark_item.dart';
|
||||
|
||||
part 'bookmarks.g.dart';
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
class BookmarksRepository extends _$BookmarksRepository {
|
||||
final _service = GeckoBookmarksService();
|
||||
|
||||
Future<void> addBookmark({
|
||||
required String parentGuid,
|
||||
required Uri url,
|
||||
required String title,
|
||||
}) async {
|
||||
await _service.addItem(parentGuid, url, title, null);
|
||||
ref.invalidateSelf();
|
||||
}
|
||||
|
||||
Future<void> addFolder({
|
||||
required String parentGuid,
|
||||
required String title,
|
||||
}) async {
|
||||
await _service.addFolder(parentGuid, title, null);
|
||||
ref.invalidateSelf();
|
||||
}
|
||||
|
||||
Future<void> editBookmark({
|
||||
required String guid,
|
||||
String? title,
|
||||
Uri? url,
|
||||
String? parentGuid,
|
||||
}) async {
|
||||
await _service.updateNode(
|
||||
guid,
|
||||
BookmarkInfo(title: title, url: url?.toString(), parentGuid: parentGuid),
|
||||
);
|
||||
ref.invalidateSelf();
|
||||
}
|
||||
|
||||
Future<void> editFolder({required String guid, required String title}) async {
|
||||
await _service.updateNode(guid, BookmarkInfo(title: title));
|
||||
ref.invalidateSelf();
|
||||
}
|
||||
|
||||
Future<void> delete(String guid) async {
|
||||
await _service.deleteNode(guid);
|
||||
ref.invalidateSelf();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<BookmarkItem?> build() async {
|
||||
final node = await _service.getTree(
|
||||
BookmarkRoot.mobile.id,
|
||||
recursive: true,
|
||||
);
|
||||
return node.mapNotNull(BookmarkItem.parseRecursive);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'bookmarks.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
|
||||
@ProviderFor(BookmarksRepository)
|
||||
const bookmarksRepositoryProvider = BookmarksRepositoryProvider._();
|
||||
|
||||
final class BookmarksRepositoryProvider
|
||||
extends $AsyncNotifierProvider<BookmarksRepository, BookmarkItem?> {
|
||||
const BookmarksRepositoryProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'bookmarksRepositoryProvider',
|
||||
isAutoDispose: false,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$bookmarksRepositoryHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
BookmarksRepository create() => BookmarksRepository();
|
||||
}
|
||||
|
||||
String _$bookmarksRepositoryHash() =>
|
||||
r'b8fa5b5699c053b91fcabd46dc97b7192e32d068';
|
||||
|
||||
abstract class _$BookmarksRepository extends $AsyncNotifier<BookmarkItem?> {
|
||||
FutureOr<BookmarkItem?> build();
|
||||
@$mustCallSuper
|
||||
@override
|
||||
void runBuild() {
|
||||
final created = build();
|
||||
final ref = this.ref as $Ref<AsyncValue<BookmarkItem?>, BookmarkItem?>;
|
||||
final element =
|
||||
ref.element
|
||||
as $ClassProviderElement<
|
||||
AnyNotifier<AsyncValue<BookmarkItem?>, BookmarkItem?>,
|
||||
AsyncValue<BookmarkItem?>,
|
||||
Object?,
|
||||
Object?
|
||||
>;
|
||||
element.handleValue(ref, created);
|
||||
}
|
||||
}
|
||||
+277
@@ -0,0 +1,277 @@
|
||||
import 'package:animated_tree_view/animated_tree_view.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:flutter_material_design_icons/flutter_material_design_icons.dart';
|
||||
import 'package:flutter_mozilla_components/flutter_mozilla_components.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:weblibre/features/geckoview/features/bookmarks/domain/entities/bookmark_item.dart';
|
||||
import 'package:weblibre/features/geckoview/features/bookmarks/domain/providers/bookmarks.dart';
|
||||
import 'package:weblibre/features/geckoview/features/bookmarks/domain/repositories/bookmarks.dart';
|
||||
import 'package:weblibre/presentation/widgets/failure_widget.dart';
|
||||
import 'package:weblibre/utils/form_validators.dart';
|
||||
import 'package:weblibre/utils/uri_parser.dart' as uri_parser;
|
||||
|
||||
class BookmarkEntryEditScreen extends HookConsumerWidget {
|
||||
final BookmarkInfo? initialInfo;
|
||||
final BookmarkEntry? exisitingEntry;
|
||||
|
||||
const BookmarkEntryEditScreen({
|
||||
required this.exisitingEntry,
|
||||
required this.initialInfo,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final formKey = useMemoized(() => GlobalKey<FormState>());
|
||||
|
||||
final folderList = ref.watch(
|
||||
bookmarksProvider<BookmarkFolder>(BookmarkRoot.mobile.id),
|
||||
);
|
||||
|
||||
final nameTextController = useTextEditingController(
|
||||
text: initialInfo?.title ?? exisitingEntry?.title,
|
||||
);
|
||||
final urlTextController = useTextEditingController(
|
||||
text: initialInfo?.url ?? exisitingEntry?.url.toString(),
|
||||
);
|
||||
|
||||
final parentGuid = useState(
|
||||
initialInfo?.parentGuid ??
|
||||
exisitingEntry?.parentGuid ??
|
||||
BookmarkRoot.mobile.id,
|
||||
);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: (exisitingEntry != null)
|
||||
? const Text('Edit Bookmark')
|
||||
: const Text('Create Bookmark'),
|
||||
actions: [
|
||||
IconButton(
|
||||
onPressed: () async {
|
||||
if (formKey.currentState?.validate() ?? false) {
|
||||
final newUrl = uri_parser.tryParseUrl(
|
||||
urlTextController.text,
|
||||
eagerParsing: true,
|
||||
)!;
|
||||
|
||||
if (exisitingEntry != null) {
|
||||
await ref
|
||||
.read(bookmarksRepositoryProvider.notifier)
|
||||
.editBookmark(
|
||||
guid: exisitingEntry!.guid,
|
||||
title:
|
||||
(nameTextController.text != exisitingEntry!.title)
|
||||
? nameTextController.text
|
||||
: null,
|
||||
parentGuid:
|
||||
(parentGuid.value != exisitingEntry!.parentGuid)
|
||||
? parentGuid.value
|
||||
: null,
|
||||
url: (newUrl != exisitingEntry!.url) ? newUrl : null,
|
||||
);
|
||||
|
||||
if (context.mounted) {
|
||||
context.pop();
|
||||
}
|
||||
} else {
|
||||
await ref
|
||||
.read(bookmarksRepositoryProvider.notifier)
|
||||
.addBookmark(
|
||||
parentGuid: parentGuid.value,
|
||||
title: nameTextController.text,
|
||||
url: newUrl,
|
||||
);
|
||||
|
||||
if (context.mounted) {
|
||||
context.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
icon: const Icon(Icons.check),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: SafeArea(
|
||||
child: Form(
|
||||
key: formKey,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12.0),
|
||||
child: ListView(
|
||||
children: [
|
||||
TextFormField(
|
||||
controller: nameTextController,
|
||||
decoration: const InputDecoration(
|
||||
label: Text('Name'),
|
||||
floatingLabelBehavior: FloatingLabelBehavior.always,
|
||||
),
|
||||
minLines: 1,
|
||||
maxLines: 3,
|
||||
validator: validateRequired,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
TextFormField(
|
||||
controller: urlTextController,
|
||||
keyboardType: TextInputType.url,
|
||||
minLines: 1,
|
||||
maxLines: 10,
|
||||
decoration: const InputDecoration(
|
||||
label: Text('URL'),
|
||||
hintText: 'https://example.com/',
|
||||
floatingLabelBehavior: FloatingLabelBehavior.always,
|
||||
),
|
||||
validator: (value) {
|
||||
return validateUrl(
|
||||
value,
|
||||
onlyHttpProtocol: true,
|
||||
eagerParsing: true,
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text('Folder', style: Theme.of(context).textTheme.labelMedium),
|
||||
folderList.when(
|
||||
data: (list) {
|
||||
TreeNode<BookmarkFolder> addChildren(
|
||||
TreeNode<BookmarkFolder>? parent,
|
||||
BookmarkFolder item,
|
||||
) {
|
||||
final node = TreeNode(
|
||||
key: item.guid,
|
||||
data: item,
|
||||
parent: parent,
|
||||
);
|
||||
final targetNode = (parent?..add(node)) ?? node;
|
||||
|
||||
if (item.children != null) {
|
||||
for (final child in item.children!) {
|
||||
addChildren(node, child as BookmarkFolder);
|
||||
}
|
||||
}
|
||||
|
||||
return targetNode;
|
||||
}
|
||||
|
||||
final root = (list != null)
|
||||
? addChildren(null, list)
|
||||
: TreeNode<BookmarkFolder>.root();
|
||||
|
||||
return TreeView.simple(
|
||||
tree: root,
|
||||
shrinkWrap: true,
|
||||
onTreeReady: (controller) {
|
||||
controller.expandAllChildren(root);
|
||||
},
|
||||
expansionIndicatorBuilder: (context, tree) =>
|
||||
ChevronIndicator.upDown(
|
||||
tree: tree,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 16.0,
|
||||
horizontal: 12.0,
|
||||
),
|
||||
),
|
||||
builder: (context, item) {
|
||||
final isSelected = item.data?.guid == parentGuid.value;
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(right: 16.0),
|
||||
child: switch (item.data) {
|
||||
final BookmarkFolder folder => ListTile(
|
||||
selected: isSelected,
|
||||
leading: (item.isExpanded)
|
||||
? const Icon(MdiIcons.folderOpen)
|
||||
: const Icon(MdiIcons.folder),
|
||||
trailing: isSelected
|
||||
? const Icon(Icons.check)
|
||||
: null,
|
||||
title: Text(folder.title),
|
||||
onTap: () {
|
||||
parentGuid.value = folder.guid;
|
||||
},
|
||||
),
|
||||
null => const SizedBox.shrink(),
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
error: (error, stackTrace) => Center(
|
||||
child: FailureWidget(
|
||||
title: 'Failed to load Bookmark Folders',
|
||||
exception: error,
|
||||
onRetry: () {
|
||||
// ignore: unused_result
|
||||
ref.refresh(
|
||||
bookmarksProvider<BookmarkFolder>(
|
||||
BookmarkRoot.mobile.id,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
loading: () => const SizedBox.shrink(),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
if (exisitingEntry != null)
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: OutlinedButton.icon(
|
||||
style: OutlinedButton.styleFrom(
|
||||
side: BorderSide(
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
foregroundColor: Theme.of(context).colorScheme.error,
|
||||
iconColor: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
label: const Text('Delete'),
|
||||
icon: const Icon(MdiIcons.bookmarkRemove),
|
||||
onPressed: () async {
|
||||
final result = await showDialog<bool?>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
icon: const Icon(Icons.warning),
|
||||
title: const Text('Delete Bookmark'),
|
||||
content: const Text(
|
||||
'Are you sure you want to delete this Bookmark?',
|
||||
),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context, false);
|
||||
},
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context, true);
|
||||
},
|
||||
child: const Text('Delete'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
if (result == true) {
|
||||
await ref
|
||||
.read(bookmarksRepositoryProvider.notifier)
|
||||
.delete(exisitingEntry!.guid);
|
||||
|
||||
if (context.mounted) {
|
||||
context.pop();
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
+133
@@ -0,0 +1,133 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:flutter_mozilla_components/flutter_mozilla_components.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:weblibre/features/geckoview/features/bookmarks/domain/entities/bookmark_item.dart';
|
||||
import 'package:weblibre/features/geckoview/features/bookmarks/domain/repositories/bookmarks.dart';
|
||||
import 'package:weblibre/utils/form_validators.dart';
|
||||
|
||||
class BookmarkFolderEditScreen extends HookConsumerWidget {
|
||||
final String? parentGuid;
|
||||
final BookmarkFolder? folder;
|
||||
|
||||
const BookmarkFolderEditScreen({required this.folder, this.parentGuid});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final formKey = useMemoized(() => GlobalKey<FormState>());
|
||||
final nameTextController = useTextEditingController(text: folder?.title);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: (folder != null)
|
||||
? const Text('Edit Folder')
|
||||
: const Text('Create Folder'),
|
||||
actions: [
|
||||
IconButton(
|
||||
onPressed: () async {
|
||||
if (formKey.currentState?.validate() ?? false) {
|
||||
if (folder != null) {
|
||||
await ref
|
||||
.read(bookmarksRepositoryProvider.notifier)
|
||||
.editFolder(
|
||||
guid: folder!.guid,
|
||||
title: nameTextController.text,
|
||||
);
|
||||
|
||||
if (context.mounted) {
|
||||
context.pop();
|
||||
}
|
||||
} else {
|
||||
await ref
|
||||
.read(bookmarksRepositoryProvider.notifier)
|
||||
.addFolder(
|
||||
parentGuid: parentGuid ?? BookmarkRoot.mobile.id,
|
||||
title: nameTextController.text,
|
||||
);
|
||||
|
||||
if (context.mounted) {
|
||||
context.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
icon: const Icon(Icons.check),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Form(
|
||||
key: formKey,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12.0),
|
||||
child: ListView(
|
||||
children: [
|
||||
TextFormField(
|
||||
controller: nameTextController,
|
||||
decoration: const InputDecoration(
|
||||
label: Text('Name'),
|
||||
floatingLabelBehavior: FloatingLabelBehavior.always,
|
||||
),
|
||||
validator: validateRequired,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
if (folder != null)
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: OutlinedButton.icon(
|
||||
style: OutlinedButton.styleFrom(
|
||||
side: BorderSide(
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
foregroundColor: Theme.of(context).colorScheme.error,
|
||||
iconColor: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
label: const Text('Delete'),
|
||||
icon: const Icon(Icons.delete),
|
||||
onPressed: () async {
|
||||
final result = await showDialog<bool?>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
icon: const Icon(Icons.warning),
|
||||
title: const Text('Delete Folder'),
|
||||
content: const Text(
|
||||
'Are you sure you want to delete this Folder including all bookmarks?',
|
||||
),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context, false);
|
||||
},
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context, true);
|
||||
},
|
||||
child: const Text('Delete'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
if (result == true) {
|
||||
await ref
|
||||
.read(bookmarksRepositoryProvider.notifier)
|
||||
.delete(folder!.guid);
|
||||
|
||||
if (context.mounted) {
|
||||
context.pop();
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
+198
@@ -0,0 +1,198 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:animated_tree_view/animated_tree_view.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:flutter_material_design_icons/flutter_material_design_icons.dart';
|
||||
import 'package:flutter_mozilla_components/flutter_mozilla_components.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:weblibre/core/routing/routes.dart';
|
||||
import 'package:weblibre/features/geckoview/features/bookmarks/domain/entities/bookmark_item.dart';
|
||||
import 'package:weblibre/features/geckoview/features/bookmarks/domain/providers/bookmarks.dart';
|
||||
import 'package:weblibre/presentation/hooks/menu_controller.dart';
|
||||
import 'package:weblibre/presentation/widgets/failure_widget.dart';
|
||||
import 'package:weblibre/presentation/widgets/uri_breadcrumb.dart';
|
||||
import 'package:weblibre/presentation/widgets/url_icon.dart';
|
||||
|
||||
class BookmarkListScreen extends HookConsumerWidget {
|
||||
final String entryGuid;
|
||||
|
||||
const BookmarkListScreen({super.key, required this.entryGuid});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final bookmarkList = ref.watch(bookmarksProvider<BookmarkItem>(entryGuid));
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Bookmarks')),
|
||||
body: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 12.0),
|
||||
child: bookmarkList.when(
|
||||
data: (list) {
|
||||
TreeNode<BookmarkItem> addChildren(
|
||||
TreeNode<BookmarkItem>? parent,
|
||||
BookmarkItem item,
|
||||
) {
|
||||
final node = TreeNode(
|
||||
key: item.guid,
|
||||
data: item,
|
||||
parent: parent,
|
||||
);
|
||||
final targetNode = (parent?..add(node)) ?? node;
|
||||
|
||||
if (item is BookmarkFolder && item.children != null) {
|
||||
for (final child in item.children!) {
|
||||
addChildren(node, child);
|
||||
}
|
||||
}
|
||||
|
||||
return targetNode;
|
||||
}
|
||||
|
||||
final root = (list != null)
|
||||
? addChildren(null, list)
|
||||
: TreeNode<BookmarkItem>.root();
|
||||
|
||||
return TreeView.simple(
|
||||
tree: root,
|
||||
onTreeReady: (controller) {
|
||||
controller.expandNode(root);
|
||||
},
|
||||
expansionIndicatorBuilder: (context, tree) =>
|
||||
ChevronIndicator.upDown(
|
||||
tree: tree,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 16.0,
|
||||
horizontal: 12.0,
|
||||
),
|
||||
),
|
||||
builder: (context, item) {
|
||||
return switch (item.data) {
|
||||
final BookmarkEntry bookmark => ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
leading: UrlIcon([bookmark.url], iconSize: 34.0),
|
||||
trailing: IconButton(
|
||||
icon: const Icon(Icons.edit),
|
||||
onPressed: () async {
|
||||
await BookmarkEntryEditRoute(
|
||||
bookmarkEntry: jsonEncode(bookmark.toJson()),
|
||||
).push(context);
|
||||
},
|
||||
),
|
||||
title: Text(bookmark.title),
|
||||
subtitle: UriBreadcrumb(uri: bookmark.url),
|
||||
onTap: () async {
|
||||
final result = await OpenSharedContentRoute(
|
||||
sharedUrl: bookmark.url.toString(),
|
||||
).push<bool>(context);
|
||||
|
||||
if (result == true) {
|
||||
if (context.mounted) {
|
||||
const BrowserRoute().go(context);
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
final BookmarkFolder folder => Padding(
|
||||
padding: const EdgeInsets.only(right: 42.0),
|
||||
child: HookBuilder(
|
||||
builder: (context) {
|
||||
final controller = useMenuController();
|
||||
|
||||
return ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
leading: (item.isExpanded)
|
||||
? const Icon(MdiIcons.folderOpen)
|
||||
: const Icon(MdiIcons.folder),
|
||||
title: Text(folder.title),
|
||||
trailing: MenuAnchor(
|
||||
controller: controller,
|
||||
builder: (context, controller, child) => InkWell(
|
||||
onTap: () {
|
||||
if (controller.isOpen) {
|
||||
controller.close();
|
||||
} else {
|
||||
controller.open();
|
||||
}
|
||||
},
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 8.0,
|
||||
vertical: 15.0,
|
||||
),
|
||||
child: Icon(MdiIcons.dotsVertical),
|
||||
),
|
||||
),
|
||||
menuChildren: [
|
||||
if (!bookmarkRootIds.contains(folder.guid))
|
||||
MenuItemButton(
|
||||
leadingIcon: const Icon(
|
||||
MdiIcons.folderEdit,
|
||||
),
|
||||
child: const Text('Edit'),
|
||||
onPressed: () async {
|
||||
await BookmarkFolderEditRoute(
|
||||
folder: jsonEncode(folder.toJson()),
|
||||
).push(context);
|
||||
},
|
||||
),
|
||||
MenuItemButton(
|
||||
leadingIcon: const Icon(MdiIcons.folderPlus),
|
||||
child: const Text('Add Subfolder'),
|
||||
onPressed: () async {
|
||||
await BookmarkFolderAddRoute(
|
||||
parentGuid: folder.guid,
|
||||
).push(context);
|
||||
},
|
||||
),
|
||||
MenuItemButton(
|
||||
leadingIcon: const Icon(
|
||||
MdiIcons.bookmarkPlus,
|
||||
),
|
||||
child: const Text('Add Bookmark'),
|
||||
onPressed: () async {
|
||||
await BookmarkEntryAddRoute(
|
||||
bookmarkInfo: jsonEncode(
|
||||
BookmarkInfo(
|
||||
parentGuid: folder.guid,
|
||||
).encode(),
|
||||
),
|
||||
).push(context);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
onTap: () async {
|
||||
if (folder.guid != entryGuid) {
|
||||
await BookmarkListRoute(
|
||||
entryGuid: folder.guid,
|
||||
).push(context);
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
null => const Center(child: Text('Empty')),
|
||||
};
|
||||
},
|
||||
);
|
||||
},
|
||||
error: (error, stackTrace) => Center(
|
||||
child: FailureWidget(
|
||||
title: 'Failed to load Bookmarks',
|
||||
exception: error,
|
||||
onRetry: () {
|
||||
// ignore: unused_result
|
||||
ref.refresh(bookmarksProvider<BookmarkItem>(entryGuid));
|
||||
},
|
||||
),
|
||||
),
|
||||
loading: () => const SizedBox.shrink(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -53,7 +53,7 @@ class OpenSharedContent extends HookConsumerWidget {
|
||||
);
|
||||
|
||||
if (context.mounted) {
|
||||
context.pop();
|
||||
context.pop(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+9
@@ -437,6 +437,15 @@ class BrowserBottomAppBar extends HookConsumerWidget {
|
||||
),
|
||||
),
|
||||
const Divider(),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
await BookmarkListRoute(
|
||||
entryGuid: BookmarkRoot.mobile.id,
|
||||
).push(context);
|
||||
},
|
||||
leadingIcon: const Icon(MdiIcons.bookmarkMultiple),
|
||||
child: const Text('Bookmarks'),
|
||||
),
|
||||
MenuItemButton(
|
||||
onPressed: () async {
|
||||
await const BangMenuRoute().push(context);
|
||||
|
||||
@@ -17,12 +17,14 @@
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'dart:convert';
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:flutter_material_design_icons/flutter_material_design_icons.dart';
|
||||
import 'package:flutter_mozilla_components/flutter_mozilla_components.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:nullability/nullability.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
@@ -164,6 +166,22 @@ class TabMenu extends HookConsumerWidget {
|
||||
await ui_helper.launchUrlFeedback(context, tabState.url);
|
||||
},
|
||||
),
|
||||
MenuItemButton(
|
||||
leadingIcon: const Icon(MdiIcons.bookmarkPlus),
|
||||
child: const Text('Add Bookmark'),
|
||||
onPressed: () async {
|
||||
final tabState = ref.read(tabStateProvider(selectedTabId))!;
|
||||
|
||||
await BookmarkEntryAddRoute(
|
||||
bookmarkInfo: jsonEncode(
|
||||
BookmarkInfo(
|
||||
title: tabState.title,
|
||||
url: tabState.url.toString(),
|
||||
).encode(),
|
||||
),
|
||||
).push(context);
|
||||
},
|
||||
),
|
||||
MenuItemButton(
|
||||
leadingIcon: const Icon(MdiIcons.tabPlus),
|
||||
child: const Text('Clone tab'),
|
||||
|
||||
@@ -27,14 +27,14 @@ class ProfileRepository extends _$ProfileRepository {
|
||||
throw Exception('Could not create profile');
|
||||
}
|
||||
|
||||
state = await AsyncValue.guard(_readProfiles);
|
||||
ref.invalidateSelf();
|
||||
|
||||
return profile;
|
||||
}
|
||||
|
||||
Future<void> updateProfileMetadata(Profile profile) async {
|
||||
await filesystem.updateProfileMetadata(profile);
|
||||
state = await AsyncValue.guard(_readProfiles);
|
||||
ref.invalidateSelf();
|
||||
}
|
||||
|
||||
Future<bool> deleteProfile(String id) async {
|
||||
@@ -45,7 +45,7 @@ class ProfileRepository extends _$ProfileRepository {
|
||||
|
||||
await filesystem.getProfileDir(uuid).delete(recursive: true);
|
||||
|
||||
state = await AsyncValue.guard(_readProfiles);
|
||||
ref.invalidateSelf();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ final class ProfileRepositoryProvider
|
||||
ProfileRepository create() => ProfileRepository();
|
||||
}
|
||||
|
||||
String _$profileRepositoryHash() => r'1357d42738d40e8e447ab8879292e81ad7b80b61';
|
||||
String _$profileRepositoryHash() => r'249240ce0e775d4fd9ee3558e6b05326d09d79de';
|
||||
|
||||
abstract class _$ProfileRepository extends $AsyncNotifier<List<Profile>> {
|
||||
FutureOr<List<Profile>> build();
|
||||
|
||||
Reference in New Issue
Block a user