Skip to content

Commit 2353be9

Browse files
authored
Merge pull request #429 from SGI-CAPP-AT2/add-api-url-manually-issue
feat: ccsync url input is added
2 parents 7bb38b1 + 464c33a commit 2353be9

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

lib/api_service.dart

+6-3
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,10 @@ class Tasks {
6666
};
6767
}
6868
}
69-
70-
String baseUrl = 'http://YOUR_IP:8000';
7169
String origin = 'http://localhost:8080';
7270

7371
Future<List<Tasks>> fetchTasks(String uuid, String encryptionSecret) async {
72+
var baseUrl = await CredentialsStorage.getApiUrl();
7473
try {
7574
String url =
7675
'$baseUrl/tasks?email=email&origin=$origin&UUID=$uuid&encryptionSecret=$encryptionSecret';
@@ -157,6 +156,7 @@ Future<void> updateTasksInDatabase(List<Tasks> tasks) async {
157156
}
158157

159158
Future<void> deleteTask(String email, String taskUuid) async {
159+
var baseUrl = await CredentialsStorage.getApiUrl();
160160
var c = await CredentialsStorage.getClientId();
161161
var e = await CredentialsStorage.getEncryptionSecret();
162162
final url = Uri.parse('$baseUrl/delete-task');
@@ -189,6 +189,7 @@ Future<void> deleteTask(String email, String taskUuid) async {
189189
Future<void> completeTask(String email, String taskUuid) async {
190190
var c = await CredentialsStorage.getClientId();
191191
var e = await CredentialsStorage.getEncryptionSecret();
192+
var baseUrl = await CredentialsStorage.getApiUrl();
192193
final url = Uri.parse('$baseUrl/complete-task');
193194
final body = jsonEncode({
194195
'email': email,
@@ -223,6 +224,7 @@ Future<void> completeTask(String email, String taskUuid) async {
223224

224225
Future<void> addTaskAndDeleteFromDatabase(
225226
String description, String project, String due, String priority) async {
227+
var baseUrl = await CredentialsStorage.getApiUrl();
226228
String apiUrl = '$baseUrl/add-task';
227229
var c = await CredentialsStorage.getClientId();
228230
var e = await CredentialsStorage.getEncryptionSecret();
@@ -255,9 +257,10 @@ Future<void> addTaskAndDeleteFromDatabase(
255257

256258
Future<void> modifyTaskOnTaskwarrior(String description, String project,
257259
String due, String priority, String status, String taskuuid) async {
258-
String apiUrl = '$baseUrl/modify-task';
260+
var baseUrl = await CredentialsStorage.getApiUrl();
259261
var c = await CredentialsStorage.getClientId();
260262
var e = await CredentialsStorage.getEncryptionSecret();
263+
String apiUrl = '$baseUrl/modify-task';
261264
debugPrint(c);
262265
debugPrint(e);
263266
final response = await http.post(

lib/app/utils/taskchampion/credentials_storage.dart

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import 'package:shared_preferences/shared_preferences.dart';
33
class CredentialsStorage {
44
static const String _encryptionSecretKey = 'encryptionSecret';
55
static const String _clientIdKey = 'clientId';
6-
6+
static const String _apiUrlKey = 'ccsyncBackendUrl';
77
static Future<String?> getEncryptionSecret() async {
88
SharedPreferences prefs = await SharedPreferences.getInstance();
99
return prefs.getString(_encryptionSecretKey);
@@ -13,4 +13,10 @@ class CredentialsStorage {
1313
SharedPreferences prefs = await SharedPreferences.getInstance();
1414
return prefs.getString(_clientIdKey);
1515
}
16+
17+
static Future<String?> getApiUrl() async {
18+
SharedPreferences prefs = await SharedPreferences.getInstance();
19+
return prefs.getString(_apiUrlKey);
20+
}
21+
1622
}

lib/app/utils/taskchampion/taskchampion.dart

+21
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class ManageTaskChampionCreds extends StatelessWidget {
1313
final TextEditingController _encryptionSecretController =
1414
TextEditingController();
1515
final TextEditingController _clientIdController = TextEditingController();
16+
final TextEditingController _ccsyncBackendUrlController = TextEditingController();
1617

1718
ManageTaskChampionCreds({super.key}) {
1819
_loadCredentials();
@@ -23,12 +24,14 @@ class ManageTaskChampionCreds extends StatelessWidget {
2324
_encryptionSecretController.text =
2425
prefs.getString('encryptionSecret') ?? '';
2526
_clientIdController.text = prefs.getString('clientId') ?? '';
27+
_ccsyncBackendUrlController.text = prefs.getString('championApiUrl') ?? '';
2628
}
2729

2830
Future<void> _saveCredentials(BuildContext context) async {
2931
SharedPreferences prefs = await SharedPreferences.getInstance();
3032
await prefs.setString('encryptionSecret', _encryptionSecretController.text);
3133
await prefs.setString('clientId', _clientIdController.text);
34+
await prefs.setString('championApiUrl', _ccsyncBackendUrlController.text);
3235
ScaffoldMessenger.of(context).showSnackBar(
3336
const SnackBar(content: Text('Credentials saved successfully')),
3437
);
@@ -117,6 +120,24 @@ class ManageTaskChampionCreds extends StatelessWidget {
117120
border: const OutlineInputBorder(),
118121
),
119122
),
123+
const SizedBox(height: 10),
124+
TextField(
125+
style: TextStyle(
126+
color: AppSettings.isDarkMode
127+
? TaskWarriorColors.white
128+
: TaskWarriorColors.black,
129+
),
130+
controller: _ccsyncBackendUrlController,
131+
decoration: InputDecoration(
132+
labelText: 'CCSync Backend URL',
133+
labelStyle: TextStyle(
134+
color: AppSettings.isDarkMode
135+
? TaskWarriorColors.white
136+
: TaskWarriorColors.black,
137+
),
138+
border: const OutlineInputBorder(),
139+
),
140+
),
120141
const SizedBox(height: 20),
121142
ElevatedButton(
122143
onPressed: () => _saveCredentials(context),

0 commit comments

Comments
 (0)