Skip to content

Commit

Permalink
feat: ccsync url input is added
Browse files Browse the repository at this point in the history
Input is now provided so that user can input url to ccsync server
  • Loading branch information
SGI-CAPP-AT2 committed Jan 8, 2025
1 parent 2a91fe1 commit 94447d3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
9 changes: 6 additions & 3 deletions lib/api_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,10 @@ class Tasks {
};
}
}

String baseUrl = 'http://YOUR_IP:8000';
String origin = 'http://localhost:8080';

Future<List<Tasks>> fetchTasks(String uuid, String encryptionSecret) async {
var baseUrl = await CredentialsStorage.getApiUrl();
String url =
'$baseUrl/tasks?email=email&origin=$origin&UUID=$uuid&encryptionSecret=$encryptionSecret';

Expand Down Expand Up @@ -152,6 +151,7 @@ Future<void> updateTasksInDatabase(List<Tasks> tasks) async {
}

Future<void> 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');
Expand Down Expand Up @@ -184,6 +184,7 @@ Future<void> deleteTask(String email, String taskUuid) async {
Future<void> 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,
Expand Down Expand Up @@ -218,6 +219,7 @@ Future<void> completeTask(String email, String taskUuid) async {

Future<void> 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();
Expand Down Expand Up @@ -250,9 +252,10 @@ Future<void> addTaskAndDeleteFromDatabase(

Future<void> 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(
Expand Down
8 changes: 7 additions & 1 deletion lib/app/utils/taskchampion/credentials_storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String?> getEncryptionSecret() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
return prefs.getString(_encryptionSecretKey);
Expand All @@ -13,4 +13,10 @@ class CredentialsStorage {
SharedPreferences prefs = await SharedPreferences.getInstance();
return prefs.getString(_clientIdKey);
}

static Future<String?> getApiUrl() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
return prefs.getString(_apiUrlKey);
}

}
21 changes: 21 additions & 0 deletions lib/app/utils/taskchampion/taskchampion.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ManageTaskChampionCreds extends StatelessWidget {
final TextEditingController _encryptionSecretController =
TextEditingController();
final TextEditingController _clientIdController = TextEditingController();
final TextEditingController _ccsyncBackendUrlController = TextEditingController();

ManageTaskChampionCreds({super.key}) {
_loadCredentials();
Expand All @@ -23,12 +24,14 @@ class ManageTaskChampionCreds extends StatelessWidget {
_encryptionSecretController.text =
prefs.getString('encryptionSecret') ?? '';
_clientIdController.text = prefs.getString('clientId') ?? '';
_ccsyncBackendUrlController.text = prefs.getString('championApiUrl') ?? '';
}

Future<void> _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')),
);
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 94447d3

Please sign in to comment.