Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ccsync url input is added #429

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
try {
String url =
'$baseUrl/tasks?email=email&origin=$origin&UUID=$uuid&encryptionSecret=$encryptionSecret';
Expand Down Expand Up @@ -157,6 +156,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 @@ -189,6 +189,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 @@ -223,6 +224,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 @@ -255,9 +257,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
Loading