From 8ba96c68de7af2a073fda4a80776039ca1ee5d41 Mon Sep 17 00:00:00 2001 From: Abhishek Shroff Date: Sun, 4 May 2025 21:58:19 +0530 Subject: [PATCH] [client] Use name as id for publinks --- .../action_resource_publink_create.dart | 20 +++++++++---------- .../lib/ui/explorer/create_publink_view.dart | 18 ++++++++--------- .../lib/ui/explorer/resource_info_view.dart | 2 +- client/lib/ui/sync/action_view.dart | 7 +++---- 4 files changed, 23 insertions(+), 24 deletions(-) diff --git a/client/lib/libphylum/actions/action_resource_publink_create.dart b/client/lib/libphylum/actions/action_resource_publink_create.dart index 0feb2b3b..0766aa23 100644 --- a/client/lib/libphylum/actions/action_resource_publink_create.dart +++ b/client/lib/libphylum/actions/action_resource_publink_create.dart @@ -18,7 +18,7 @@ class ResourcePublinkCreateAction extends ResourceAction with JsonApiAction { @override Map? get requestBody => { - 'name': publinkName, + 'id': publinkId, if (password.isNotEmpty) 'password': password, if (expires != null) 'expires': expires!.toIso8601String(), if (accessLimit != 0) 'access_limit': accessLimit, @@ -31,20 +31,20 @@ class ResourcePublinkCreateAction extends ResourceAction with JsonApiAction { List get localChanges => []; @override - String get description => 'Creating Public Share: $publinkName'; + String get description => 'Creating Public Share: $publinkId'; @override Map get props => { 'resourceId': resourceId, - 'publinkName': _publinkName, + 'publinkId': _publinkId, 'password': password, 'expires': expires?.millisecondsSinceEpoch, 'accessLimit': accessLimit, 'timestamp': timestamp.millisecondsSinceEpoch, }; - String _publinkName; - String get publinkName => _publinkName; + String _publinkId; + String get publinkId => _publinkId; final String password; final DateTime? expires; final int accessLimit; @@ -52,19 +52,19 @@ class ResourcePublinkCreateAction extends ResourceAction with JsonApiAction { ResourcePublinkCreateAction({ required super.resourceId, - required String publinkName, + required String publinkId, required this.password, required DateTime? expires, required this.accessLimit, DateTime? timestamp, - }) : _publinkName = publinkName, + }) : _publinkId = publinkId, expires = expires?.toUtc(), timestamp = timestamp ?? DateTime.now(); factory ResourcePublinkCreateAction.fromMap(Map map) { return ResourcePublinkCreateAction( resourceId: map['resourceId'], - publinkName: map['publinkName'], + publinkId: map['publinkId'], password: map['password'], expires: map['expires'] == null ? null : DateTime.fromMillisecondsSinceEpoch(map['expires']), accessLimit: map['accessLimit'], @@ -78,10 +78,10 @@ class ResourcePublinkCreateAction extends ResourceAction with JsonApiAction { (action is ResourceCreateAction || action is ResourcePublinkCreateAction) && action.resourceId == resourceId; - Future updatePublinkName(String publinkName) { + Future updatePublinkId(String publinkId) { return account.actionQueue.updateActions( (action) => action == this, - (action) => (action as ResourcePublinkCreateAction)._publinkName = publinkName, + (action) => (action as ResourcePublinkCreateAction)._publinkId = publinkId, ); } } diff --git a/client/lib/ui/explorer/create_publink_view.dart b/client/lib/ui/explorer/create_publink_view.dart index 56c5fdd3..2ef73226 100644 --- a/client/lib/ui/explorer/create_publink_view.dart +++ b/client/lib/ui/explorer/create_publink_view.dart @@ -3,13 +3,13 @@ import 'package:flutter/services.dart'; import 'package:phylum/util/time.dart'; import 'package:provider/provider.dart'; -final TextInputFormatter validNameFormatter = FilteringTextInputFormatter.allow(RegExp(r'[a-zA-Z0-9_\-]')); +final TextInputFormatter validIdFormatter = FilteringTextInputFormatter.allow(RegExp(r'[a-zA-Z0-9_\-]')); class PublinkInfo with ChangeNotifier { - String _name = ''; - String get name => _name.trim(); - set name(String value) { - _name = value; + String _id = ''; + String get id => _id.trim(); + set id(String value) { + _id = value; notifyListeners(); } @@ -68,7 +68,7 @@ class CreatePublinkView extends StatefulWidget { child: Text('Cancel'), ), ElevatedButton( - onPressed: context.select((info) => info.name.isNotEmpty) + onPressed: context.select((info) => info.id.isNotEmpty) ? () => Navigator.of(context).pop(context.read()) : null, child: Text('OK'), @@ -98,12 +98,12 @@ class _CreatePublinkViewState extends State { ListTile( leading: const Icon(Icons.public), title: TextField( - decoration: InputDecoration(label: Text('Name')), - inputFormatters: [validNameFormatter], + decoration: InputDecoration(label: Text('ID')), + inputFormatters: [validIdFormatter], enableSuggestions: false, autocorrect: false, autofocus: true, - onChanged: (value) => context.read().name = value, + onChanged: (value) => context.read().id = value, ), ), ListTile( diff --git a/client/lib/ui/explorer/resource_info_view.dart b/client/lib/ui/explorer/resource_info_view.dart index 0b053e3d..1ab1cdb0 100644 --- a/client/lib/ui/explorer/resource_info_view.dart +++ b/client/lib/ui/explorer/resource_info_view.dart @@ -119,7 +119,7 @@ class ResourceInfoView extends StatelessWidget { if (info == null) return; account.addAction(ResourcePublinkCreateAction( resourceId: resource.id, - publinkName: info.name, + publinkId: info.id, password: info.password, expires: info.expiration, accessLimit: info.accessLimit, diff --git a/client/lib/ui/sync/action_view.dart b/client/lib/ui/sync/action_view.dart index 355822e8..48bd9680 100644 --- a/client/lib/ui/sync/action_view.dart +++ b/client/lib/ui/sync/action_view.dart @@ -100,14 +100,13 @@ class ActionView extends StatelessWidget { tooltip: 'Rename', onPressed: () async { if (action is! ResourcePublinkCreateAction) return; - final preset = action.publinkName; final name = await showInputDialog(context, - title: 'Edit Name', - preset: preset, + title: 'Edit ID', + preset: action.publinkId, capitalization: TextCapitalization.words, validate: (name) => name.trim().isNotEmpty); if (name == null || !context.mounted) return; - action.updatePublinkName(name); + action.updatePublinkId(name); }, ), IconButton(