Skip to content

Commit 94447d3

Browse files
committed
feat: ccsync url input is added
Input is now provided so that user can input url to ccsync server
1 parent 2a91fe1 commit 94447d3

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
String url =
7574
'$baseUrl/tasks?email=email&origin=$origin&UUID=$uuid&encryptionSecret=$encryptionSecret';
7675

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

154153
Future<void> deleteTask(String email, String taskUuid) async {
154+
var baseUrl = await CredentialsStorage.getApiUrl();
155155
var c = await CredentialsStorage.getClientId();
156156
var e = await CredentialsStorage.getEncryptionSecret();
157157
final url = Uri.parse('$baseUrl/delete-task');
@@ -184,6 +184,7 @@ Future<void> deleteTask(String email, String taskUuid) async {
184184
Future<void> completeTask(String email, String taskUuid) async {
185185
var c = await CredentialsStorage.getClientId();
186186
var e = await CredentialsStorage.getEncryptionSecret();
187+
var baseUrl = await CredentialsStorage.getApiUrl();
187188
final url = Uri.parse('$baseUrl/complete-task');
188189
final body = jsonEncode({
189190
'email': email,
@@ -218,6 +219,7 @@ Future<void> completeTask(String email, String taskUuid) async {
218219

219220
Future<void> addTaskAndDeleteFromDatabase(
220221
String description, String project, String due, String priority) async {
222+
var baseUrl = await CredentialsStorage.getApiUrl();
221223
String apiUrl = '$baseUrl/add-task';
222224
var c = await CredentialsStorage.getClientId();
223225
var e = await CredentialsStorage.getEncryptionSecret();
@@ -250,9 +252,10 @@ Future<void> addTaskAndDeleteFromDatabase(
250252

251253
Future<void> modifyTaskOnTaskwarrior(String description, String project,
252254
String due, String priority, String status, String taskuuid) async {
253-
String apiUrl = '$baseUrl/modify-task';
255+
var baseUrl = await CredentialsStorage.getApiUrl();
254256
var c = await CredentialsStorage.getClientId();
255257
var e = await CredentialsStorage.getEncryptionSecret();
258+
String apiUrl = '$baseUrl/modify-task';
256259
debugPrint(c);
257260
debugPrint(e);
258261
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)