From 94447d35bfce7f033222629a738740f62b3d23e7 Mon Sep 17 00:00:00 2001 From: Shubham Ingale Date: Wed, 8 Jan 2025 19:48:49 +0530 Subject: [PATCH] feat: ccsync url input is added Input is now provided so that user can input url to ccsync server --- lib/api_service.dart | 9 +++++--- .../taskchampion/credentials_storage.dart | 8 ++++++- lib/app/utils/taskchampion/taskchampion.dart | 21 +++++++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/lib/api_service.dart b/lib/api_service.dart index d69e6a24..fdad9f80 100644 --- a/lib/api_service.dart +++ b/lib/api_service.dart @@ -66,11 +66,10 @@ class Tasks { }; } } - -String baseUrl = 'http://YOUR_IP:8000'; String origin = 'http://localhost:8080'; Future> fetchTasks(String uuid, String encryptionSecret) async { + var baseUrl = await CredentialsStorage.getApiUrl(); String url = '$baseUrl/tasks?email=email&origin=$origin&UUID=$uuid&encryptionSecret=$encryptionSecret'; @@ -152,6 +151,7 @@ Future updateTasksInDatabase(List tasks) async { } Future deleteTask(String email, String taskUuid) async { + var baseUrl = await CredentialsStorage.getApiUrl(); var c = await CredentialsStorage.getClientId(); var e = await CredentialsStorage.getEncryptionSecret(); final url = Uri.parse('$baseUrl/delete-task'); @@ -184,6 +184,7 @@ Future deleteTask(String email, String taskUuid) async { Future completeTask(String email, String taskUuid) async { var c = await CredentialsStorage.getClientId(); var e = await CredentialsStorage.getEncryptionSecret(); + var baseUrl = await CredentialsStorage.getApiUrl(); final url = Uri.parse('$baseUrl/complete-task'); final body = jsonEncode({ 'email': email, @@ -218,6 +219,7 @@ Future completeTask(String email, String taskUuid) async { Future addTaskAndDeleteFromDatabase( String description, String project, String due, String priority) async { + var baseUrl = await CredentialsStorage.getApiUrl(); String apiUrl = '$baseUrl/add-task'; var c = await CredentialsStorage.getClientId(); var e = await CredentialsStorage.getEncryptionSecret(); @@ -250,9 +252,10 @@ Future addTaskAndDeleteFromDatabase( Future modifyTaskOnTaskwarrior(String description, String project, String due, String priority, String status, String taskuuid) async { - String apiUrl = '$baseUrl/modify-task'; + var baseUrl = await CredentialsStorage.getApiUrl(); var c = await CredentialsStorage.getClientId(); var e = await CredentialsStorage.getEncryptionSecret(); + String apiUrl = '$baseUrl/modify-task'; debugPrint(c); debugPrint(e); final response = await http.post( diff --git a/lib/app/utils/taskchampion/credentials_storage.dart b/lib/app/utils/taskchampion/credentials_storage.dart index 3e449963..bc0b0e83 100644 --- a/lib/app/utils/taskchampion/credentials_storage.dart +++ b/lib/app/utils/taskchampion/credentials_storage.dart @@ -3,7 +3,7 @@ import 'package:shared_preferences/shared_preferences.dart'; class CredentialsStorage { static const String _encryptionSecretKey = 'encryptionSecret'; static const String _clientIdKey = 'clientId'; - + static const String _apiUrlKey = 'ccsyncBackendUrl'; static Future getEncryptionSecret() async { SharedPreferences prefs = await SharedPreferences.getInstance(); return prefs.getString(_encryptionSecretKey); @@ -13,4 +13,10 @@ class CredentialsStorage { SharedPreferences prefs = await SharedPreferences.getInstance(); return prefs.getString(_clientIdKey); } + + static Future getApiUrl() async { + SharedPreferences prefs = await SharedPreferences.getInstance(); + return prefs.getString(_apiUrlKey); + } + } diff --git a/lib/app/utils/taskchampion/taskchampion.dart b/lib/app/utils/taskchampion/taskchampion.dart index f9e0488e..ceec86ba 100644 --- a/lib/app/utils/taskchampion/taskchampion.dart +++ b/lib/app/utils/taskchampion/taskchampion.dart @@ -13,6 +13,7 @@ class ManageTaskChampionCreds extends StatelessWidget { final TextEditingController _encryptionSecretController = TextEditingController(); final TextEditingController _clientIdController = TextEditingController(); + final TextEditingController _ccsyncBackendUrlController = TextEditingController(); ManageTaskChampionCreds({super.key}) { _loadCredentials(); @@ -23,12 +24,14 @@ class ManageTaskChampionCreds extends StatelessWidget { _encryptionSecretController.text = prefs.getString('encryptionSecret') ?? ''; _clientIdController.text = prefs.getString('clientId') ?? ''; + _ccsyncBackendUrlController.text = prefs.getString('championApiUrl') ?? ''; } Future _saveCredentials(BuildContext context) async { SharedPreferences prefs = await SharedPreferences.getInstance(); await prefs.setString('encryptionSecret', _encryptionSecretController.text); await prefs.setString('clientId', _clientIdController.text); + await prefs.setString('championApiUrl', _ccsyncBackendUrlController.text); ScaffoldMessenger.of(context).showSnackBar( const SnackBar(content: Text('Credentials saved successfully')), ); @@ -117,6 +120,24 @@ class ManageTaskChampionCreds extends StatelessWidget { border: const OutlineInputBorder(), ), ), + const SizedBox(height: 10), + TextField( + style: TextStyle( + color: AppSettings.isDarkMode + ? TaskWarriorColors.white + : TaskWarriorColors.black, + ), + controller: _ccsyncBackendUrlController, + decoration: InputDecoration( + labelText: 'CCSync Backend URL', + labelStyle: TextStyle( + color: AppSettings.isDarkMode + ? TaskWarriorColors.white + : TaskWarriorColors.black, + ), + border: const OutlineInputBorder(), + ), + ), const SizedBox(height: 20), ElevatedButton( onPressed: () => _saveCredentials(context),