diff --git a/lib/entities/contact.dart b/lib/entities/contact.dart index 98d03e0..2eaeef1 100644 --- a/lib/entities/contact.dart +++ b/lib/entities/contact.dart @@ -1,4 +1,3 @@ - class Contact { String name; String publicKey; @@ -19,78 +18,3 @@ class Contact { }; } } - -// // Synchronize the app state contact list with the internal one -// void sortAndStoreAppStateContactList(List ffasContactList) { -// ffasContactList.sortBy((element) => element["name"] as String); -// FFAppState().update(() { -// FFAppState().ContactList = ffasContactList; -// }); -// } - -// // Called when a new contact is added or an existing one is edited -// Future vcsUpdateContact( -// String id, -// String name, -// String publicKey, -// ) async { -// var api = Veilid.instance; -// try { -// // if we are adding a new contact, make its id -// var newContact = false; -// if (id.isEmpty) { -// id = const Uuid().v4(); -// newContact = true; -// } - -// // Trim name -// name = name.trim(); - -// // Validate name and public key -// if (name.length > 127) { -// return "Name is too long."; -// } -// if (name.isEmpty) { -// return "Name can not be empty"; -// } -// if (!isValidDHTKey(publicKey)) { -// return "Public key is not valid"; -// } - -// // update entry in internal contacts table -// var contactsDb = await api.openTableDB("contacts", 1); -// var contact = Contact(name, publicKey); -// await contactsDb.storeStringJson(0, id, contact); - -// // update app state -// var contactJson = contact.toJson(); -// contactJson['id'] = id; - -// var ffasContactList = FFAppState().ContactList; -// if (newContact) { -// // Add new contact -// ffasContactList.add(contactJson); -// } else { -// // Update existing contact -// ffasContactList.forEachIndexedWhile((i, e) { -// if (e['id'] == id) { -// ffasContactList[i] = contactJson; -// return false; -// } -// return true; -// }); -// } - -// // Sort the contact list -// sortAndStoreAppStateContactList(ffasContactList); -// } catch (e) { -// return e.toString(); -// } - -// return ""; -// } - -// // Called when a contact is to be removed -// Future vcsDeleteContact(String id) async { -// // -// } \ No newline at end of file diff --git a/lib/pages/login.dart b/lib/pages/login.dart index 9c4d409..633bafa 100644 --- a/lib/pages/login.dart +++ b/lib/pages/login.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; +import '../state/auth.dart'; class LoginPage extends ConsumerWidget { const LoginPage({super.key}); @@ -15,15 +16,15 @@ class LoginPage extends ConsumerWidget { crossAxisAlignment: CrossAxisAlignment.center, children: [ const Text("Login Page"), - // ElevatedButton( - // onPressed: () async { - // ref.watch(authNotifierProvider.notifier).login( - // "myEmail", - // "myPassword", - // ); - // }, - // child: const Text("Login"), - // ), + ElevatedButton( + onPressed: () async { + await ref.watch(authNotifierProvider.notifier).login( + "myEmail", + "myPassword", + ); + }, + child: const Text("Login"), + ), ], ), ), diff --git a/lib/router/router_notifier.dart b/lib/router/router_notifier.dart index ede578b..e7ba9c9 100644 --- a/lib/router/router_notifier.dart +++ b/lib/router/router_notifier.dart @@ -21,7 +21,7 @@ import '../state/auth.dart'; class RouterNotifier extends AutoDisposeAsyncNotifier implements Listenable { VoidCallback? routerListener; - bool isAuth = false; // Useful for our global redirect functio + bool isAuth = false; // Useful for our global redirect function @override Future build() async { @@ -43,13 +43,14 @@ class RouterNotifier extends AutoDisposeAsyncNotifier if (this.state.isLoading || this.state.hasError) return null; final isIndex = state.location == IndexPage.path; - if (isIndex) { return isAuth ? HomePage.path : LoginPage.path; } final isLoggingIn = state.location == LoginPage.path; - if (isLoggingIn) return isAuth ? HomePage.path : null; + if (isLoggingIn) { + return isAuth ? HomePage.path : null; + } return isAuth ? null : IndexPage.path; } diff --git a/lib/state/auth.dart b/lib/state/auth.dart index 50b9759..553d59e 100644 --- a/lib/state/auth.dart +++ b/lib/state/auth.dart @@ -53,7 +53,7 @@ class AuthNotifier extends AutoDisposeAsyncNotifier { /// Mock of a successful login attempt, which results come from the network. Future login(String publicKey, String password) async { - state = await AsyncValue.guard(() async { + state = await AsyncValue.guard(() async { return Future.delayed( networkRoundTripTime, () => _dummyUser,