Skip to content
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
26 changes: 16 additions & 10 deletions lib/state/upload_queue_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@ import 'settings_state.dart';
import 'session_state.dart';

class UploadQueueState extends ChangeNotifier {
/// Helper to access the map data provider instance
MapDataProvider get _nodeCache => MapDataProvider();
final MapDataProvider _nodeCache;
final NodeProviderWithCache _nodeProvider;
final List<PendingUpload> _queue = [];
Timer? _uploadTimer;
int _activeUploadCount = 0;

UploadQueueState({
MapDataProvider? nodeCache,
NodeProviderWithCache? nodeProvider,
}) : _nodeCache = nodeCache ?? MapDataProvider(),
_nodeProvider = nodeProvider ?? NodeProviderWithCache.instance;

// Getters
int get pendingCount => _queue.length;
List<PendingUpload> get pendingUploads => List.unmodifiable(_queue);
Expand Down Expand Up @@ -116,7 +122,7 @@ class UploadQueueState extends ChangeNotifier {
_saveQueue();

// Notify node provider to update the map
NodeProviderWithCache.instance.notifyListeners();
_nodeProvider.notifyListeners();
}
}

Expand Down Expand Up @@ -156,7 +162,7 @@ class UploadQueueState extends ChangeNotifier {

_nodeCache.addOrUpdate([tempNode]);
// Notify node provider to update the map
NodeProviderWithCache.instance.notifyListeners();
_nodeProvider.notifyListeners();

notifyListeners();
}
Expand Down Expand Up @@ -247,7 +253,7 @@ class UploadQueueState extends ChangeNotifier {
_nodeCache.addOrUpdate([originalNode, editedNode]);
}
// Notify node provider to update the map
NodeProviderWithCache.instance.notifyListeners();
_nodeProvider.notifyListeners();

notifyListeners();
}
Expand Down Expand Up @@ -279,7 +285,7 @@ class UploadQueueState extends ChangeNotifier {

_nodeCache.addOrUpdate([nodeWithDeletionTag]);
// Notify node provider to update the map
NodeProviderWithCache.instance.notifyListeners();
_nodeProvider.notifyListeners();

notifyListeners();
}
Expand All @@ -294,7 +300,7 @@ class UploadQueueState extends ChangeNotifier {
_saveQueue();

// Notify node provider to update the map
NodeProviderWithCache.instance.notifyListeners();
_nodeProvider.notifyListeners();
notifyListeners();
}

Expand All @@ -306,7 +312,7 @@ class UploadQueueState extends ChangeNotifier {
_saveQueue();

// Notify node provider to update the map
NodeProviderWithCache.instance.notifyListeners();
_nodeProvider.notifyListeners();
notifyListeners();
}

Expand Down Expand Up @@ -722,7 +728,7 @@ class UploadQueueState extends ChangeNotifier {
}

// Notify node provider to update the map
NodeProviderWithCache.instance.notifyListeners();
_nodeProvider.notifyListeners();
}

// Handle successful deletion by removing the node from cache
Expand All @@ -732,7 +738,7 @@ class UploadQueueState extends ChangeNotifier {
_nodeCache.removeNodeById(item.originalNodeId!);

// Notify node provider to update the map
NodeProviderWithCache.instance.notifyListeners();
_nodeProvider.notifyListeners();
}
}

Expand Down
38 changes: 20 additions & 18 deletions lib/widgets/add_node_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ class _AddNodeSheetState extends State<AddNodeSheet> {
super.dispose();
}

void _checkProximityAndCommit(BuildContext context, AppState appState, LocalizationService locService) {
_checkSubmissionGuideAndProceed(context, appState, locService);
void _checkProximityAndCommit() {
_checkSubmissionGuideAndProceed();
}

void _checkSubmissionGuideAndProceed(BuildContext context, AppState appState, LocalizationService locService) async {
void _checkSubmissionGuideAndProceed() async {
// Check if user has seen the submission guide
final hasSeenGuide = await ChangelogService().hasSeenSubmissionGuide();
if (!context.mounted) return;
if (!mounted) return;

if (!hasSeenGuide) {
// Show submission guide dialog first
Expand All @@ -98,7 +98,7 @@ class _AddNodeSheetState extends State<AddNodeSheet> {
barrierDismissible: false,
builder: (context) => const SubmissionGuideDialog(),
);
if (!context.mounted) return;
if (!mounted) return;

// If user canceled the submission guide, don't proceed with submission
if (shouldProceed != true) {
Expand All @@ -107,45 +107,47 @@ class _AddNodeSheetState extends State<AddNodeSheet> {
}

// Now proceed with proximity check
_checkProximityOnly(context, appState, locService);
_checkProximityOnly();
}

void _checkProximityOnly(BuildContext context, AppState appState, LocalizationService locService) {
void _checkProximityOnly() {
// Only check proximity if we have a target location
if (widget.session.target == null) {
_commitWithoutCheck(context, appState, locService);
_commitWithoutCheck();
return;
}

// Check for nearby nodes within the configured distance
final nearbyNodes = MapDataProvider().findNodesWithinDistance(
widget.session.target!,
widget.session.target!,
kNodeProximityWarningDistance,
);

if (nearbyNodes.isNotEmpty) {
// Show proximity warning dialog
showDialog<void>(
context: context,
builder: (context) => ProximityWarningDialog(
builder: (dialogContext) => ProximityWarningDialog(
nearbyNodes: nearbyNodes,
distance: kNodeProximityWarningDistance,
onGoBack: () {
Navigator.of(context).pop(); // Close dialog
Navigator.of(dialogContext).pop(); // Close dialog
},
onSubmitAnyway: () {
Navigator.of(context).pop(); // Close dialog
_commitWithoutCheck(context, appState, locService);
Navigator.of(dialogContext).pop(); // Close dialog
_commitWithoutCheck();
},
),
);
} else {
// No nearby nodes, proceed with commit
_commitWithoutCheck(context, appState, locService);
_commitWithoutCheck();
}
}

void _commitWithoutCheck(BuildContext context, AppState appState, LocalizationService locService) {
void _commitWithoutCheck() {
final appState = context.read<AppState>();
final locService = LocalizationService.instance;
appState.commitSession();
Navigator.pop(context);
ScaffoldMessenger.of(context).showSnackBar(
Expand Down Expand Up @@ -387,7 +389,7 @@ class _AddNodeSheetState extends State<AddNodeSheet> {
final appState = context.watch<AppState>();

void commit() {
_checkProximityAndCommit(context, appState, locService);
_checkProximityAndCommit();
}

void cancel() {
Expand Down
43 changes: 23 additions & 20 deletions lib/widgets/edit_node_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ class _EditNodeSheetState extends State<EditNodeSheet> {
super.dispose();
}

void _checkProximityAndCommit(BuildContext context, AppState appState, LocalizationService locService) {
_checkSubmissionGuideAndProceed(context, appState, locService);
void _checkProximityAndCommit() {
_checkSubmissionGuideAndProceed();
}

void _checkSubmissionGuideAndProceed(BuildContext context, AppState appState, LocalizationService locService) async {
void _checkSubmissionGuideAndProceed() async {
// Check if user has seen the submission guide
final hasSeenGuide = await ChangelogService().hasSeenSubmissionGuide();
if (!context.mounted) return;
if (!mounted) return;

if (!hasSeenGuide) {
// Show submission guide dialog first
Expand All @@ -101,7 +101,7 @@ class _EditNodeSheetState extends State<EditNodeSheet> {
barrierDismissible: false,
builder: (context) => const SubmissionGuideDialog(),
);
if (!context.mounted) return;
if (!mounted) return;

// If user canceled the submission guide, don't proceed with submission
if (shouldProceed != true) {
Expand All @@ -110,40 +110,42 @@ class _EditNodeSheetState extends State<EditNodeSheet> {
}

// Now proceed with proximity check
_checkProximityOnly(context, appState, locService);
_checkProximityOnly();
}

void _checkProximityOnly(BuildContext context, AppState appState, LocalizationService locService) {
void _checkProximityOnly() {
// Check for nearby nodes within the configured distance, excluding the node being edited
final nearbyNodes = MapDataProvider().findNodesWithinDistance(
widget.session.target,
widget.session.target,
kNodeProximityWarningDistance,
excludeNodeId: widget.session.originalNode.id,
);

if (nearbyNodes.isNotEmpty) {
// Show proximity warning dialog
showDialog<void>(
context: context,
builder: (context) => ProximityWarningDialog(
builder: (dialogContext) => ProximityWarningDialog(
nearbyNodes: nearbyNodes,
distance: kNodeProximityWarningDistance,
onGoBack: () {
Navigator.of(context).pop(); // Close dialog
Navigator.of(dialogContext).pop(); // Close dialog
},
onSubmitAnyway: () {
Navigator.of(context).pop(); // Close dialog
_commitWithoutCheck(context, appState, locService);
Navigator.of(dialogContext).pop(); // Close dialog
_commitWithoutCheck();
},
),
);
} else {
// No nearby nodes, proceed with commit
_commitWithoutCheck(context, appState, locService);
_commitWithoutCheck();
}
}

void _commitWithoutCheck(BuildContext context, AppState appState, LocalizationService locService) {
void _commitWithoutCheck() {
final appState = context.read<AppState>();
final locService = LocalizationService.instance;
appState.commitEditSession();
Navigator.pop(context);
ScaffoldMessenger.of(context).showSnackBar(
Expand Down Expand Up @@ -248,15 +250,16 @@ class _EditNodeSheetState extends State<EditNodeSheet> {
}

/// Show dialog explaining why submission is disabled due to no changes
void _showNoChangesDialog(BuildContext context, LocalizationService locService) {
void _showNoChangesDialog() {
final locService = LocalizationService.instance;
showDialog<void>(
context: context,
builder: (context) => AlertDialog(
builder: (dialogContext) => AlertDialog(
title: Text(locService.t('editNode.noChangesTitle')),
content: Text(locService.t('editNode.noChangesMessage')),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
onPressed: () => Navigator.of(dialogContext).pop(),
child: Text(locService.ok),
),
],
Expand Down Expand Up @@ -437,11 +440,11 @@ class _EditNodeSheetState extends State<EditNodeSheet> {
void commit() {
// Check if there are any actual changes to submit
if (!_hasActualChanges(widget.session)) {
_showNoChangesDialog(context, locService);
_showNoChangesDialog();
return;
}

_checkProximityAndCommit(context, appState, locService);
_checkProximityAndCommit();
}

void cancel() {
Expand Down
Loading
Loading