Update share folder UI
This commit is contained in:
parent
d30851c257
commit
0849ef21c1
2 changed files with 50 additions and 14 deletions
|
@ -55,10 +55,29 @@ class CollectionsService {
|
|||
)
|
||||
.then((response) {
|
||||
_logger.info(response.toString());
|
||||
return response.data["emails"] as List<String>;
|
||||
final emails = List<String>();
|
||||
for (final email in response.data["emails"]) {
|
||||
emails.add(email);
|
||||
}
|
||||
return emails;
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> share(int collectionID, String email, String publicKey) {
|
||||
final encryptedKey = CryptoUtil.sealSync(
|
||||
getCollectionKey(collectionID), Sodium.base642bin(publicKey));
|
||||
return Dio().post(
|
||||
Configuration.instance.getHttpEndpoint() + "/collections/share",
|
||||
data: {
|
||||
"collectionID": collectionID,
|
||||
"email": email,
|
||||
"encryptedKey": Sodium.bin2base64(encryptedKey),
|
||||
},
|
||||
options:
|
||||
Options(headers: {"X-Auth-Token": Configuration.instance.getToken()}),
|
||||
);
|
||||
}
|
||||
|
||||
Uint8List getCollectionKey(int collectionID) {
|
||||
if (!_cachedKeys.containsKey(collectionID)) {
|
||||
final collection = _collectionIDToCollection[collectionID];
|
||||
|
|
|
@ -30,18 +30,15 @@ class ShareFolderWidget extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _ShareFolderWidgetState extends State<ShareFolderWidget> {
|
||||
bool _showEntryField = false;
|
||||
String _email;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FutureBuilder<List<String>>(
|
||||
future: widget.collection == null
|
||||
? List<String>()
|
||||
? Future.value(List<String>())
|
||||
: CollectionsService.instance.getSharees(widget.collection.id),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return _getSharingDialog(snapshot.data);
|
||||
return SharingDialog(widget.collection, snapshot.data);
|
||||
} else if (snapshot.hasError) {
|
||||
return Text(snapshot.error.toString());
|
||||
} else {
|
||||
|
@ -50,15 +47,32 @@ class _ShareFolderWidgetState extends State<ShareFolderWidget> {
|
|||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Widget _getSharingDialog(List<String> sharees) {
|
||||
log(sharees.toString());
|
||||
class SharingDialog extends StatefulWidget {
|
||||
final Collection collection;
|
||||
final List<String> sharees;
|
||||
|
||||
SharingDialog(this.collection, this.sharees, {Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_SharingDialogState createState() => _SharingDialogState();
|
||||
}
|
||||
|
||||
class _SharingDialogState extends State<SharingDialog> {
|
||||
bool _showEntryField = false;
|
||||
List<String> _sharees;
|
||||
String _email;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
_sharees = widget.sharees;
|
||||
final children = List<Widget>();
|
||||
if (!_showEntryField &&
|
||||
(widget.collection == null || sharees.length == 0)) {
|
||||
(widget.collection == null || _sharees.length == 0)) {
|
||||
children.add(Text("Click the + button to share this folder."));
|
||||
} else {
|
||||
for (final email in sharees) {
|
||||
for (final email in _sharees) {
|
||||
children.add(EmailItemWidget(email));
|
||||
}
|
||||
}
|
||||
|
@ -164,10 +178,13 @@ class _ShareFolderWidgetState extends State<ShareFolderWidget> {
|
|||
// TODO: Create collection
|
||||
// TODO: Add files to collection
|
||||
}
|
||||
// TODO: Add email to collection
|
||||
setState(() {
|
||||
// sharees.add(email);
|
||||
_showEntryField = false;
|
||||
CollectionsService.instance
|
||||
.share(widget.collection.id, _email, publicKey)
|
||||
.then((value) {
|
||||
setState(() {
|
||||
_sharees.add(_email);
|
||||
_showEntryField = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue