Skip to content

Commit

Permalink
add debounce to select path on generate invite
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagoalvesdulce committed Jun 16, 2023
1 parent 0c0c65b commit cf8e9cb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
18 changes: 1 addition & 17 deletions bruig/flutterui/bruig/lib/components/chats_list.dart
Expand Up @@ -9,6 +9,7 @@ import 'package:bruig/components/empty_widget.dart';
import 'package:bruig/components/gc_context_menu.dart';
import 'package:bruig/components/chat/types.dart';
import 'package:bruig/util.dart';
import 'package:bruig/components/addressbook/addressbook.dart';

class _ChatHeadingW extends StatefulWidget {
final ChatModel chat;
Expand Down Expand Up @@ -141,19 +142,6 @@ Future<void> generateInvite(BuildContext context) async {
Navigator.of(context, rootNavigator: true).pushNamed('/generateInvite');
}

void loadInvite(BuildContext context) async {
// Decode the invite and send to the user verification screen.
var filePickRes = await FilePicker.platform.pickFiles();
if (filePickRes == null) return;
var filePath = filePickRes.files.first.path;
if (filePath == null) return;
filePath = filePath.trim();
if (filePath == "") return;
var invite = await Golib.decodeInvite(filePath);
Navigator.of(context, rootNavigator: true)
.pushNamed('/verifyInvite', arguments: invite);
}

Future<void> fetchInvite(BuildContext context) async {
Navigator.of(context, rootNavigator: true).pushNamed('/fetchInvite');
}
Expand Down Expand Up @@ -209,10 +197,6 @@ class _ChatsListState extends State<_ChatsList> {

@override
Widget build(BuildContext context) {
void createGC() async {
Navigator.of(context, rootNavigator: true).pushNamed('/newGC');
}

void showAddressBook() async {
client.showAddressBookScreen();
}
Expand Down
26 changes: 19 additions & 7 deletions bruig/flutterui/bruig/lib/screens/generate_invite.dart
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:bruig/components/accounts_dropdown.dart';
import 'package:bruig/components/copyable.dart';
import 'package:bruig/components/dcr_input.dart';
Expand Down Expand Up @@ -25,6 +27,7 @@ class _GenerateInviteScreenState extends State<GenerateInviteScreen> {
bool hasExtraAccounts = false;
bool loading = false;
GeneratedKXInvite? generated;
Timer? _debounce;

void checkExtraAccounts() async {
var accts = await Golib.listAccounts();
Expand All @@ -39,14 +42,23 @@ class _GenerateInviteScreenState extends State<GenerateInviteScreen> {
checkExtraAccounts();
}

@override
void dispose() {
super.dispose();
_debounce?.cancel();
}

void selectPath() async {
var filePath = await FilePicker.platform.saveFile(
dialogTitle: "Select invitation file location",
fileName: "invite.bin",
);
if (filePath == null) return;
setState(() {
path = filePath;
if (_debounce?.isActive ?? false) _debounce!.cancel();
_debounce = Timer(const Duration(milliseconds: 500), () async {
var filePath = await FilePicker.platform.saveFile(
dialogTitle: "Select invitation file location",
fileName: "invite.bin",
);
if (filePath == null) return;
setState(() {
path = filePath;
});
});
}

Expand Down

0 comments on commit cf8e9cb

Please sign in to comment.