Skip to content
This repository has been archived by the owner on Dec 21, 2024. It is now read-only.

Commit

Permalink
added formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
lewislarsen committed Aug 13, 2024
1 parent b919f1f commit 8f5e039
Show file tree
Hide file tree
Showing 32 changed files with 1,054 additions and 604 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/flutter_format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Flutter Format

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.x'
channel: 'stable'
- name: Install dependencies
run: flutter pub get
- name: Verify formatting
run: dart format --output=none --set-exit-if-changed .
2 changes: 1 addition & 1 deletion lib/auth_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ class AuthManager {
_token = null;
await _secureStorage.delete(key: 'auth_token');
}
}
}
2 changes: 1 addition & 1 deletion lib/backup_destination_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ class BackupDestination {
'updated_at': updatedAt.toIso8601String(),
};
}
}
}
32 changes: 21 additions & 11 deletions lib/backup_destination_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ class BackupDestinationProvider with ChangeNotifier {
final jsonResponse = json.decode(response.body);
if (jsonResponse['data'] is List) {
final newDestinations = (jsonResponse['data'] as List)
.map<BackupDestination>((destJson) => BackupDestination.fromJson(destJson))
.map<BackupDestination>(
(destJson) => BackupDestination.fromJson(destJson))
.toList();

if (page == 1) {
Expand All @@ -69,7 +70,8 @@ class BackupDestinationProvider with ChangeNotifier {
}
} else if (response.statusCode == 429) {
// Handle rate limit exceeded
final retryAfter = int.tryParse(response.headers['retry-after'] ?? '') ?? 60;
final retryAfter =
int.tryParse(response.headers['retry-after'] ?? '') ?? 60;
await Future.delayed(Duration(seconds: retryAfter));
return fetchDestinations(page: page, perPage: perPage);
} else {
Expand Down Expand Up @@ -112,7 +114,8 @@ class BackupDestinationProvider with ChangeNotifier {
return BackupDestination.fromJson(jsonResponse['data']);
} else if (response.statusCode == 429) {
// Handle rate limit exceeded
final retryAfter = int.tryParse(response.headers['retry-after'] ?? '') ?? 60;
final retryAfter =
int.tryParse(response.headers['retry-after'] ?? '') ?? 60;
await Future.delayed(Duration(seconds: retryAfter));
return getDestination(id);
} else {
Expand All @@ -126,7 +129,8 @@ class BackupDestinationProvider with ChangeNotifier {
}
}

Future<BackupDestination?> createDestination(Map<String, dynamic> destinationData) async {
Future<BackupDestination?> createDestination(
Map<String, dynamic> destinationData) async {
if (!authManager.isLoggedIn) {
throw Exception('Not logged in');
}
Expand All @@ -152,7 +156,8 @@ class BackupDestinationProvider with ChangeNotifier {
return newDestination;
} else if (response.statusCode == 429) {
// Handle rate limit exceeded
final retryAfter = int.tryParse(response.headers['retry-after'] ?? '') ?? 60;
final retryAfter =
int.tryParse(response.headers['retry-after'] ?? '') ?? 60;
await Future.delayed(Duration(seconds: retryAfter));
return createDestination(destinationData);
} else {
Expand All @@ -166,7 +171,8 @@ class BackupDestinationProvider with ChangeNotifier {
}
}

Future<BackupDestination?> updateDestination(int id, Map<String, dynamic> destinationData) async {
Future<BackupDestination?> updateDestination(
int id, Map<String, dynamic> destinationData) async {
if (!authManager.isLoggedIn) {
throw Exception('Not logged in');
}
Expand All @@ -186,7 +192,8 @@ class BackupDestinationProvider with ChangeNotifier {

if (response.statusCode == 200) {
final jsonResponse = json.decode(response.body);
final updatedDestination = BackupDestination.fromJson(jsonResponse['data']);
final updatedDestination =
BackupDestination.fromJson(jsonResponse['data']);
final index = _destinations.indexWhere((dest) => dest.id == id);
if (index != -1) {
_destinations[index] = updatedDestination;
Expand All @@ -195,7 +202,8 @@ class BackupDestinationProvider with ChangeNotifier {
return updatedDestination;
} else if (response.statusCode == 429) {
// Handle rate limit exceeded
final retryAfter = int.tryParse(response.headers['retry-after'] ?? '') ?? 60;
final retryAfter =
int.tryParse(response.headers['retry-after'] ?? '') ?? 60;
await Future.delayed(Duration(seconds: retryAfter));
return updateDestination(id, destinationData);
} else {
Expand Down Expand Up @@ -232,7 +240,8 @@ class BackupDestinationProvider with ChangeNotifier {
return true;
} else if (response.statusCode == 429) {
// Handle rate limit exceeded
final retryAfter = int.tryParse(response.headers['retry-after'] ?? '') ?? 60;
final retryAfter =
int.tryParse(response.headers['retry-after'] ?? '') ?? 60;
await Future.delayed(Duration(seconds: retryAfter));
return deleteDestination(id);
} else {
Expand Down Expand Up @@ -261,7 +270,8 @@ class BackupDestinationProvider with ChangeNotifier {

bool _canMakeRequest() {
final now = DateTime.now();
_requestTimestamps.removeWhere((timestamp) => now.difference(timestamp) > _rateLimitWindow);
_requestTimestamps.removeWhere(
(timestamp) => now.difference(timestamp) > _rateLimitWindow);
return _requestTimestamps.length < _maxRequestsPerMinute;
}

Expand All @@ -278,4 +288,4 @@ class BackupDestinationProvider with ChangeNotifier {
_requestTimestamps.removeAt(0);
}
}
}
}
55 changes: 36 additions & 19 deletions lib/backup_destinations_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class _BackupDestinationsPageState extends State<BackupDestinationsPage> {
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) {
Provider.of<BackupDestinationProvider>(context, listen: false).fetchDestinations();
Provider.of<BackupDestinationProvider>(context, listen: false)
.fetchDestinations();
});
}

Expand All @@ -35,9 +36,12 @@ class _BackupDestinationsPageState extends State<BackupDestinationsPage> {
});
}

List<BackupDestination> _filterDestinations(List<BackupDestination> destinations) {
List<BackupDestination> _filterDestinations(
List<BackupDestination> destinations) {
return destinations.where((destination) {
return destination.label.toLowerCase().contains(_searchQuery.toLowerCase());
return destination.label
.toLowerCase()
.contains(_searchQuery.toLowerCase());
}).toList();
}

Expand Down Expand Up @@ -85,13 +89,14 @@ class _BackupDestinationsPageState extends State<BackupDestinationsPage> {
style: TextStyle(color: theme.colorScheme.onSurface),
decoration: InputDecoration(
hintText: 'Search by label...',
hintStyle: TextStyle(color: theme.colorScheme.onSurface.withOpacity(0.6)),
hintStyle:
TextStyle(color: theme.colorScheme.onSurface.withOpacity(0.6)),
prefixIcon: Icon(Icons.search, color: theme.colorScheme.primary),
suffixIcon: _searchQuery.isNotEmpty
? IconButton(
icon: Icon(Icons.clear, color: theme.colorScheme.primary),
onPressed: _clearSearch,
)
icon: Icon(Icons.clear, color: theme.colorScheme.primary),
onPressed: _clearSearch,
)
: null,
filled: true,
fillColor: theme.colorScheme.surface,
Expand All @@ -117,7 +122,8 @@ class _BackupDestinationsPageState extends State<BackupDestinationsPage> {
return _buildEmptyWidget();
}

final filteredDestinations = _filterDestinations(backupDestinationProvider.destinations);
final filteredDestinations =
_filterDestinations(backupDestinationProvider.destinations);

return RefreshIndicator(
onRefresh: () => backupDestinationProvider.fetchDestinations(),
Expand All @@ -130,7 +136,8 @@ class _BackupDestinationsPageState extends State<BackupDestinationsPage> {
return BackupDestinationListItem(
destination: destination,
onEdit: () => _showEditDestinationDialog(context, destination),
onDelete: () => _showDeleteConfirmationDialog(context, destination),
onDelete: () =>
_showDeleteConfirmationDialog(context, destination),
);
},
),
Expand Down Expand Up @@ -192,7 +199,8 @@ class _BackupDestinationsPageState extends State<BackupDestinationsPage> {
);
}

void _showEditDestinationDialog(BuildContext context, BackupDestination destination) {
void _showEditDestinationDialog(
BuildContext context, BackupDestination destination) {
showDialog(
context: context,
builder: (BuildContext context) {
Expand All @@ -207,13 +215,15 @@ class _BackupDestinationsPageState extends State<BackupDestinationsPage> {
);
}

void _showDeleteConfirmationDialog(BuildContext context, BackupDestination destination) {
void _showDeleteConfirmationDialog(
BuildContext context, BackupDestination destination) {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Delete Backup Destination'),
content: Text('Are you sure you want to delete "${destination.label}"?'),
content:
Text('Are you sure you want to delete "${destination.label}"?'),
actions: <Widget>[
TextButton(
child: Text('Cancel'),
Expand Down Expand Up @@ -256,11 +266,13 @@ class BackupDestinationListItem extends StatelessWidget {
leading: _buildDestinationIcon(context),
title: Text(
destination.label,
style: theme.textTheme.titleMedium?.copyWith(color: theme.colorScheme.onBackground),
style: theme.textTheme.titleMedium
?.copyWith(color: theme.colorScheme.onBackground),
),
subtitle: Text(
destination.typeHuman,
style: theme.textTheme.bodySmall?.copyWith(color: theme.colorScheme.onBackground.withOpacity(0.7)),
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onBackground.withOpacity(0.7)),
),
trailing: Row(
mainAxisSize: MainAxisSize.min,
Expand Down Expand Up @@ -316,7 +328,8 @@ class BackupDestinationDialog extends StatefulWidget {
BackupDestinationDialog({this.destination, required this.onSave});

@override
_BackupDestinationDialogState createState() => _BackupDestinationDialogState();
_BackupDestinationDialogState createState() =>
_BackupDestinationDialogState();
}

class _BackupDestinationDialogState extends State<BackupDestinationDialog> {
Expand All @@ -342,7 +355,9 @@ class _BackupDestinationDialogState extends State<BackupDestinationDialog> {
@override
Widget build(BuildContext context) {
return AlertDialog(
title: Text(widget.destination == null ? 'Add Backup Destination' : 'Edit Backup Destination'),
title: Text(widget.destination == null
? 'Add Backup Destination'
: 'Edit Backup Destination'),
content: Form(
key: _formKey,
child: SingleChildScrollView(
Expand Down Expand Up @@ -408,7 +423,8 @@ class _BackupDestinationDialogState extends State<BackupDestinationDialog> {
initialValue: _s3Endpoint,
decoration: InputDecoration(labelText: 'S3 Endpoint'),
validator: (value) {
if (_type == 'custom_s3' && (value == null || value.isEmpty)) {
if (_type == 'custom_s3' &&
(value == null || value.isEmpty)) {
return 'Please enter an S3 endpoint';
}
return null;
Expand Down Expand Up @@ -436,7 +452,8 @@ class _BackupDestinationDialogState extends State<BackupDestinationDialog> {
userId: widget.destination?.userId ?? 0,
label: _label,
type: _type,
typeHuman: _type, // This should be properly mapped in a real scenario
typeHuman:
_type, // This should be properly mapped in a real scenario
s3BucketName: _s3BucketName,
pathStyleEndpoint: _pathStyleEndpoint,
s3Region: _s3Region,
Expand All @@ -452,4 +469,4 @@ class _BackupDestinationDialogState extends State<BackupDestinationDialog> {
],
);
}
}
}
2 changes: 1 addition & 1 deletion lib/backup_task_log_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ class BackupTaskLogEntry {
'created_at': createdAt.toIso8601String(),
};
}
}
}
23 changes: 15 additions & 8 deletions lib/backup_task_log_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class BackupTaskLogProvider with ChangeNotifier {

BackupTaskLogProvider({required this.authManager});

Future<bool> fetchLogs({int page = 1, int perPage = 10, String? search}) async {
Future<bool> fetchLogs(
{int page = 1, int perPage = 10, String? search}) async {
if (!authManager.isLoggedIn) {
throw Exception('Not logged in');
}
Expand Down Expand Up @@ -52,7 +53,8 @@ class BackupTaskLogProvider with ChangeNotifier {
final jsonResponse = json.decode(response.body);
if (jsonResponse['data'] is List) {
final newLogs = (jsonResponse['data'] as List)
.map<BackupTaskLogEntry>((logJson) => BackupTaskLogEntry.fromJson(logJson))
.map<BackupTaskLogEntry>(
(logJson) => BackupTaskLogEntry.fromJson(logJson))
.toList();

if (page == 1) {
Expand All @@ -72,7 +74,8 @@ class BackupTaskLogProvider with ChangeNotifier {
}
} else if (response.statusCode == 429) {
// Handle rate limit exceeded
final retryAfter = int.tryParse(response.headers['retry-after'] ?? '') ?? 60;
final retryAfter =
int.tryParse(response.headers['retry-after'] ?? '') ?? 60;
await Future.delayed(Duration(seconds: retryAfter));
return fetchLogs(page: page, perPage: perPage, search: search);
} else {
Expand All @@ -88,7 +91,8 @@ class BackupTaskLogProvider with ChangeNotifier {

Future<bool> loadMoreLogs({int perPage = 10}) async {
if (_hasMoreLogs) {
return await fetchLogs(page: _currentPage + 1, perPage: perPage, search: _searchQuery);
return await fetchLogs(
page: _currentPage + 1, perPage: perPage, search: _searchQuery);
}
return false;
}
Expand Down Expand Up @@ -120,7 +124,8 @@ class BackupTaskLogProvider with ChangeNotifier {
return BackupTaskLogEntry.fromJson(jsonResponse['data']);
} else if (response.statusCode == 429) {
// Handle rate limit exceeded
final retryAfter = int.tryParse(response.headers['retry-after'] ?? '') ?? 60;
final retryAfter =
int.tryParse(response.headers['retry-after'] ?? '') ?? 60;
await Future.delayed(Duration(seconds: retryAfter));
return getLog(id);
} else {
Expand Down Expand Up @@ -157,7 +162,8 @@ class BackupTaskLogProvider with ChangeNotifier {
return true;
} else if (response.statusCode == 429) {
// Handle rate limit exceeded
final retryAfter = int.tryParse(response.headers['retry-after'] ?? '') ?? 60;
final retryAfter =
int.tryParse(response.headers['retry-after'] ?? '') ?? 60;
await Future.delayed(Duration(seconds: retryAfter));
return deleteLog(id);
} else {
Expand Down Expand Up @@ -187,7 +193,8 @@ class BackupTaskLogProvider with ChangeNotifier {

bool _canMakeRequest() {
final now = DateTime.now();
_requestTimestamps.removeWhere((timestamp) => now.difference(timestamp) > _rateLimitWindow);
_requestTimestamps.removeWhere(
(timestamp) => now.difference(timestamp) > _rateLimitWindow);
return _requestTimestamps.length < _maxRequestsPerMinute;
}

Expand All @@ -204,4 +211,4 @@ class BackupTaskLogProvider with ChangeNotifier {
_requestTimestamps.removeAt(0);
}
}
}
}
5 changes: 3 additions & 2 deletions lib/backup_task_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ class Timestamps {
createdAt: DateTime.parse(json['created_at']),
updatedAt: DateTime.parse(json['updated_at']),
lastRunLocalTime: json['last_run_local_time'],
pausedAt: json['paused_at'] != null ? DateTime.parse(json['paused_at']) : null,
pausedAt:
json['paused_at'] != null ? DateTime.parse(json['paused_at']) : null,
);
}
}
}
Loading

0 comments on commit 8f5e039

Please sign in to comment.