From 1deacc6cc61b98edde887838cbf9018b513e2753 Mon Sep 17 00:00:00 2001 From: VIVEK <133876017+nope3472@users.noreply.github.com> Date: Wed, 12 Feb 2025 15:18:53 +0530 Subject: [PATCH 01/11] Resolved Issue #562 --- OUTPUT/apidash-data.hive | 0 OUTPUT/apidash-data.lock | 0 OUTPUT/apidash-environments.hive | 0 OUTPUT/apidash-environments.lock | 0 OUTPUT/apidash-history-lazy.hive | 0 OUTPUT/apidash-history-lazy.lock | 0 OUTPUT/apidash-history-meta.hive | 0 OUTPUT/apidash-history-meta.lock | 0 .../history_widgets/his_sidebar_header.dart | 61 ++++++++++++++++--- lib/services/hive_services.dart | 21 ++++++- .../lib/services/http_client_manager.dart | 2 +- .../lib/services/http_service.dart | 2 +- 12 files changed, 76 insertions(+), 10 deletions(-) create mode 100644 OUTPUT/apidash-data.hive create mode 100644 OUTPUT/apidash-data.lock create mode 100644 OUTPUT/apidash-environments.hive create mode 100644 OUTPUT/apidash-environments.lock create mode 100644 OUTPUT/apidash-history-lazy.hive create mode 100644 OUTPUT/apidash-history-lazy.lock create mode 100644 OUTPUT/apidash-history-meta.hive create mode 100644 OUTPUT/apidash-history-meta.lock diff --git a/OUTPUT/apidash-data.hive b/OUTPUT/apidash-data.hive new file mode 100644 index 00000000..e69de29b diff --git a/OUTPUT/apidash-data.lock b/OUTPUT/apidash-data.lock new file mode 100644 index 00000000..e69de29b diff --git a/OUTPUT/apidash-environments.hive b/OUTPUT/apidash-environments.hive new file mode 100644 index 00000000..e69de29b diff --git a/OUTPUT/apidash-environments.lock b/OUTPUT/apidash-environments.lock new file mode 100644 index 00000000..e69de29b diff --git a/OUTPUT/apidash-history-lazy.hive b/OUTPUT/apidash-history-lazy.hive new file mode 100644 index 00000000..e69de29b diff --git a/OUTPUT/apidash-history-lazy.lock b/OUTPUT/apidash-history-lazy.lock new file mode 100644 index 00000000..e69de29b diff --git a/OUTPUT/apidash-history-meta.hive b/OUTPUT/apidash-history-meta.hive new file mode 100644 index 00000000..e69de29b diff --git a/OUTPUT/apidash-history-meta.lock b/OUTPUT/apidash-history-meta.lock new file mode 100644 index 00000000..e69de29b diff --git a/lib/screens/history/history_widgets/his_sidebar_header.dart b/lib/screens/history/history_widgets/his_sidebar_header.dart index ad6fb1da..2fd07fef 100644 --- a/lib/screens/history/history_widgets/his_sidebar_header.dart +++ b/lib/screens/history/history_widgets/his_sidebar_header.dart @@ -23,14 +23,61 @@ class HistorySidebarHeader extends ConsumerWidget { ), const Spacer(), ADIconButton( - icon: Icons.delete_forever, - iconSize: kButtonIconSizeLarge, - tooltip: "Clear History", - color: Theme.of(context).brightness == Brightness.dark - ? kColorDarkDanger - : kColorLightDanger, - onPressed: () => hiveHandler.clearAllHistory(), + icon: Icons.delete_forever, + iconSize: kButtonIconSizeLarge, + tooltip: "Clear History", + color: Theme.of(context).brightness == Brightness.dark + ? kColorDarkDanger + : kColorLightDanger, + onPressed: () { + showDialog( + context: context, + builder: (context) => AlertDialog( + title: const Text('Clear History'), + content: const Text('Are you sure you want to clear all history? This action cannot be undone.'), + actions: [ + TextButton( + onPressed: () => Navigator.pop(context), + child: const Text('Cancel'), ), + TextButton( + onPressed: () async { + try { + await hiveHandler.clearAllHistory(ref); // ✅ Pass `ref` here + + if (context.mounted) { + Navigator.pop(context); + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + content: Text('History cleared successfully'), + duration: Duration(seconds: 2), + ), + ); + } + } catch (e) { + if (context.mounted) { + Navigator.pop(context); + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + content: Text('Error clearing history'), + backgroundColor: Colors.red, + duration: Duration(seconds: 2), + ), + ); + } + } + }, + style: TextButton.styleFrom( + foregroundColor: Theme.of(context).colorScheme.error, + ), + child: const Text('Clear'), + ), + ], + ), + ); + }, +), + ADIconButton( icon: Icons.manage_history_rounded, iconSize: kButtonIconSizeLarge, diff --git a/lib/services/hive_services.dart b/lib/services/hive_services.dart index 5ca47607..6388b008 100644 --- a/lib/services/hive_services.dart +++ b/lib/services/hive_services.dart @@ -1,4 +1,6 @@ +import 'package:apidash/providers/history_providers.dart'; import 'package:flutter/foundation.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:hive_flutter/hive_flutter.dart'; const String kDataBox = "apidash-data"; @@ -140,10 +142,27 @@ class HiveHandler { Future deleteHistoryRequest(String id) => historyLazyBox.delete(id); - Future clearAllHistory() async { +Future clearAllHistory(WidgetRef ref) async { + try { + await historyMetaBox.put(kHistoryBoxIds, null); await historyMetaBox.clear(); await historyLazyBox.clear(); + + // ✅ Now ref is passed correctly + ref.read(selectedHistoryIdStateProvider.notifier).state = null; + ref.read(selectedRequestGroupIdStateProvider.notifier).state = null; + ref.read(selectedHistoryRequestModelProvider.notifier).state = null; + ref.read(historySequenceProvider.notifier).state = null; + ref.read(historyMetaStateNotifier.notifier).state = null; + + } catch (e) { + debugPrint("ERROR CLEARING HISTORY: $e"); + rethrow; } +} + + + Future clear() async { await dataBox.clear(); diff --git a/packages/apidash_core/lib/services/http_client_manager.dart b/packages/apidash_core/lib/services/http_client_manager.dart index bec23214..d4fd4ca5 100644 --- a/packages/apidash_core/lib/services/http_client_manager.dart +++ b/packages/apidash_core/lib/services/http_client_manager.dart @@ -59,4 +59,4 @@ class HttpClientManager { bool hasActiveClient(String requestId) { return _clients.containsKey(requestId); } -} +} \ No newline at end of file diff --git a/packages/apidash_core/lib/services/http_service.dart b/packages/apidash_core/lib/services/http_service.dart index 0bbc0501..cad9018b 100644 --- a/packages/apidash_core/lib/services/http_service.dart +++ b/packages/apidash_core/lib/services/http_service.dart @@ -133,4 +133,4 @@ Future<(HttpResponse?, Duration?, String?)> request( } else { return (null, null, uriRec.$2); } -} +} \ No newline at end of file From 3995d7f17af85389f09b8920c8aef4a024d5768e Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Sun, 16 Feb 2025 11:32:35 +0530 Subject: [PATCH 02/11] Remove workspace files --- OUTPUT/apidash-data.hive | 0 OUTPUT/apidash-data.lock | 0 OUTPUT/apidash-environments.hive | 0 OUTPUT/apidash-environments.lock | 0 OUTPUT/apidash-history-lazy.hive | 0 OUTPUT/apidash-history-lazy.lock | 0 OUTPUT/apidash-history-meta.hive | 0 OUTPUT/apidash-history-meta.lock | 0 8 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 OUTPUT/apidash-data.hive delete mode 100644 OUTPUT/apidash-data.lock delete mode 100644 OUTPUT/apidash-environments.hive delete mode 100644 OUTPUT/apidash-environments.lock delete mode 100644 OUTPUT/apidash-history-lazy.hive delete mode 100644 OUTPUT/apidash-history-lazy.lock delete mode 100644 OUTPUT/apidash-history-meta.hive delete mode 100644 OUTPUT/apidash-history-meta.lock diff --git a/OUTPUT/apidash-data.hive b/OUTPUT/apidash-data.hive deleted file mode 100644 index e69de29b..00000000 diff --git a/OUTPUT/apidash-data.lock b/OUTPUT/apidash-data.lock deleted file mode 100644 index e69de29b..00000000 diff --git a/OUTPUT/apidash-environments.hive b/OUTPUT/apidash-environments.hive deleted file mode 100644 index e69de29b..00000000 diff --git a/OUTPUT/apidash-environments.lock b/OUTPUT/apidash-environments.lock deleted file mode 100644 index e69de29b..00000000 diff --git a/OUTPUT/apidash-history-lazy.hive b/OUTPUT/apidash-history-lazy.hive deleted file mode 100644 index e69de29b..00000000 diff --git a/OUTPUT/apidash-history-lazy.lock b/OUTPUT/apidash-history-lazy.lock deleted file mode 100644 index e69de29b..00000000 diff --git a/OUTPUT/apidash-history-meta.hive b/OUTPUT/apidash-history-meta.hive deleted file mode 100644 index e69de29b..00000000 diff --git a/OUTPUT/apidash-history-meta.lock b/OUTPUT/apidash-history-meta.lock deleted file mode 100644 index e69de29b..00000000 From 705febbfdf591e6dd0efb7bda8d5e64ac03a1c50 Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Sun, 16 Feb 2025 11:34:38 +0530 Subject: [PATCH 03/11] Update hive_services.dart --- lib/services/hive_services.dart | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/lib/services/hive_services.dart b/lib/services/hive_services.dart index 6388b008..a2a82087 100644 --- a/lib/services/hive_services.dart +++ b/lib/services/hive_services.dart @@ -142,27 +142,10 @@ class HiveHandler { Future deleteHistoryRequest(String id) => historyLazyBox.delete(id); -Future clearAllHistory(WidgetRef ref) async { - try { - await historyMetaBox.put(kHistoryBoxIds, null); + Future clearAllHistory() async { await historyMetaBox.clear(); await historyLazyBox.clear(); - - // ✅ Now ref is passed correctly - ref.read(selectedHistoryIdStateProvider.notifier).state = null; - ref.read(selectedRequestGroupIdStateProvider.notifier).state = null; - ref.read(selectedHistoryRequestModelProvider.notifier).state = null; - ref.read(historySequenceProvider.notifier).state = null; - ref.read(historyMetaStateNotifier.notifier).state = null; - - } catch (e) { - debugPrint("ERROR CLEARING HISTORY: $e"); - rethrow; } -} - - - Future clear() async { await dataBox.clear(); From 754b363fc91ac3489fe80a0c7d975bbaece72176 Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Sun, 16 Feb 2025 11:35:58 +0530 Subject: [PATCH 04/11] Reverts --- lib/services/hive_services.dart | 2 -- packages/apidash_core/lib/services/http_client_manager.dart | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/services/hive_services.dart b/lib/services/hive_services.dart index a2a82087..5ca47607 100644 --- a/lib/services/hive_services.dart +++ b/lib/services/hive_services.dart @@ -1,6 +1,4 @@ -import 'package:apidash/providers/history_providers.dart'; import 'package:flutter/foundation.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:hive_flutter/hive_flutter.dart'; const String kDataBox = "apidash-data"; diff --git a/packages/apidash_core/lib/services/http_client_manager.dart b/packages/apidash_core/lib/services/http_client_manager.dart index d4fd4ca5..bec23214 100644 --- a/packages/apidash_core/lib/services/http_client_manager.dart +++ b/packages/apidash_core/lib/services/http_client_manager.dart @@ -59,4 +59,4 @@ class HttpClientManager { bool hasActiveClient(String requestId) { return _clients.containsKey(requestId); } -} \ No newline at end of file +} From c63647f1f725342d1063da9559c5c1ed47c69e50 Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Sun, 16 Feb 2025 11:39:50 +0530 Subject: [PATCH 05/11] Update http_service.dart --- packages/apidash_core/lib/services/http_service.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/apidash_core/lib/services/http_service.dart b/packages/apidash_core/lib/services/http_service.dart index af9e3700..ad06a21d 100644 --- a/packages/apidash_core/lib/services/http_service.dart +++ b/packages/apidash_core/lib/services/http_service.dart @@ -139,4 +139,3 @@ Future<(HttpResponse?, Duration?, String?)> sendHttpRequest( void cancelHttpRequest(String? requestId) { httpClientManager.cancelRequest(requestId); } - From 302332a715782119ca2a5b92feb2f0afdc9087b3 Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Sun, 16 Feb 2025 11:40:48 +0530 Subject: [PATCH 06/11] Update his_sidebar_header.dart --- .../history_widgets/his_sidebar_header.dart | 98 +++++++++---------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/lib/screens/history/history_widgets/his_sidebar_header.dart b/lib/screens/history/history_widgets/his_sidebar_header.dart index 54e653d9..439245b1 100644 --- a/lib/screens/history/history_widgets/his_sidebar_header.dart +++ b/lib/screens/history/history_widgets/his_sidebar_header.dart @@ -28,57 +28,57 @@ class HistorySidebarHeader extends ConsumerWidget { color: Theme.of(context).brightness == Brightness.dark ? kColorDarkDanger : kColorLightDanger, - onPressed: () { - showDialog( - context: context, - builder: (context) => AlertDialog( - title: const Text('Clear History'), - content: const Text('Are you sure you want to clear all history? This action cannot be undone.'), - actions: [ - TextButton( - onPressed: () => Navigator.pop(context), - child: const Text('Cancel'), - ), - TextButton( - onPressed: () async { - try { - await ref - .read(historyMetaStateNotifier.notifier) - .clearAllHistory(); - - if (context.mounted) { - Navigator.pop(context); - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar( - content: Text('History cleared successfully'), - duration: Duration(seconds: 2), + onPressed: () { + showDialog( + context: context, + builder: (context) => AlertDialog( + title: const Text('Clear History'), + content: const Text( + 'Are you sure you want to clear all history? This action cannot be undone.'), + actions: [ + TextButton( + onPressed: () => Navigator.pop(context), + child: const Text('Cancel'), ), - ); - } - } catch (e) { - if (context.mounted) { - Navigator.pop(context); - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar( - content: Text('Error clearing history'), - backgroundColor: Colors.red, - duration: Duration(seconds: 2), - ), - ); - } - } - }, - style: TextButton.styleFrom( - foregroundColor: Theme.of(context).colorScheme.error, - ), - child: const Text('Clear'), - ), - ], - ), - ); - }, -), + TextButton( + onPressed: () async { + try { + await ref + .read(historyMetaStateNotifier.notifier) + .clearAllHistory(); + if (context.mounted) { + Navigator.pop(context); + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + content: Text('History cleared successfully'), + duration: Duration(seconds: 2), + ), + ); + } + } catch (e) { + if (context.mounted) { + Navigator.pop(context); + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + content: Text('Error clearing history'), + backgroundColor: Colors.red, + duration: Duration(seconds: 2), + ), + ); + } + } + }, + style: TextButton.styleFrom( + foregroundColor: Theme.of(context).colorScheme.error, + ), + child: const Text('Clear'), + ), + ], + ), + ); + }, + ), ADIconButton( icon: Icons.manage_history_rounded, iconSize: kButtonIconSizeLarge, From 0ddecf21639f264b9aeebcfeb4ddc6de526e2e58 Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Sun, 16 Feb 2025 13:18:48 +0530 Subject: [PATCH 07/11] Add constants --- lib/consts.dart | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/consts.dart b/lib/consts.dart index d03980f9..92f05c2b 100644 --- a/lib/consts.dart +++ b/lib/consts.dart @@ -473,3 +473,9 @@ const kMsgNoContent = "No content"; const kMsgUnknowContentType = "Unknown Response Content-Type"; // Workspace Selector const kMsgSelectWorkspace = "Create your workspace"; +// History Page +const kTitleClearHistory = 'Clear History'; +const kMsgClearHistory = + 'Clearing History is permanent. Do you want to continue?'; +const kMsgClearHistorySuccess = 'History cleared successfully'; +const kMsgClearHistoryError = 'Error clearing history'; From f7699f2f0f6e2786b4e20a6fe4e2d9f5a8e9c2c5 Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Sun, 16 Feb 2025 13:19:11 +0530 Subject: [PATCH 08/11] Add OkCancelDialog widget --- lib/widgets/dialog_ok_cancel.dart | 47 +++++++++++++++++++++++++++++++ lib/widgets/widgets.dart | 1 + 2 files changed, 48 insertions(+) create mode 100644 lib/widgets/dialog_ok_cancel.dart diff --git a/lib/widgets/dialog_ok_cancel.dart b/lib/widgets/dialog_ok_cancel.dart new file mode 100644 index 00000000..45a918ed --- /dev/null +++ b/lib/widgets/dialog_ok_cancel.dart @@ -0,0 +1,47 @@ +import 'package:apidash/consts.dart'; +import 'package:apidash_design_system/apidash_design_system.dart'; +import 'package:flutter/material.dart'; + +showOkCancelDialog( + BuildContext context, { + String? dialogTitle, + String? content, + String? buttonLabelOk, + VoidCallback? onClickOk, + String? buttonLabelCancel, + VoidCallback? onClickCancel, +}) { + showDialog( + context: context, + builder: (context) { + return AlertDialog( + title: Text(dialogTitle ?? ""), + titleTextStyle: Theme.of(context).textTheme.titleLarge, + content: Container( + padding: kPt20, + width: 300, + child: Text(content ?? ""), + ), + actions: [ + TextButton( + onPressed: () { + onClickCancel?.call(); + if (context.mounted) { + Navigator.pop(context); + } + }, + child: Text(buttonLabelCancel ?? kLabelCancel), + ), + TextButton( + onPressed: () { + onClickOk?.call(); + if (context.mounted) { + Navigator.pop(context); + } + }, + child: Text(buttonLabelOk ?? kLabelOk), + ), + ], + ); + }); +} diff --git a/lib/widgets/widgets.dart b/lib/widgets/widgets.dart index 59b61f54..f6427604 100644 --- a/lib/widgets/widgets.dart +++ b/lib/widgets/widgets.dart @@ -16,6 +16,7 @@ export 'codegen_previewer.dart'; export 'dialog_about.dart'; export 'dialog_history_retention.dart'; export 'dialog_import.dart'; +export 'dialog_ok_cancel.dart'; export 'dialog_rename.dart'; export 'dialog_text.dart'; export 'drag_and_drop_area.dart'; From a841e571d3d230eef6383ee8942304a63eca9a8c Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Sun, 16 Feb 2025 13:19:20 +0530 Subject: [PATCH 09/11] Update snackbar.dart --- packages/apidash_design_system/lib/widgets/snackbar.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/apidash_design_system/lib/widgets/snackbar.dart b/packages/apidash_design_system/lib/widgets/snackbar.dart index d85d65d6..434d7473 100644 --- a/packages/apidash_design_system/lib/widgets/snackbar.dart +++ b/packages/apidash_design_system/lib/widgets/snackbar.dart @@ -3,9 +3,11 @@ import 'package:flutter/material.dart'; SnackBar getSnackBar( String text, { bool small = true, + Color? color, }) { return SnackBar( width: small ? 300 : 500, + backgroundColor: color, behavior: SnackBarBehavior.floating, content: Text( text, From 99ab77c227485b1d625b7aafbb0a3a43df03b883 Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Sun, 16 Feb 2025 13:19:58 +0530 Subject: [PATCH 10/11] Update onPressed dialog box --- .../history_widgets/his_sidebar_header.dart | 71 +++++++------------ 1 file changed, 24 insertions(+), 47 deletions(-) diff --git a/lib/screens/history/history_widgets/his_sidebar_header.dart b/lib/screens/history/history_widgets/his_sidebar_header.dart index 439245b1..862ec97f 100644 --- a/lib/screens/history/history_widgets/his_sidebar_header.dart +++ b/lib/screens/history/history_widgets/his_sidebar_header.dart @@ -11,6 +11,7 @@ class HistorySidebarHeader extends ConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { final mobileScaffoldKey = ref.read(mobileScaffoldKeyStateProvider); + final sm = ScaffoldMessenger.of(context); return Padding( padding: kPe4, child: Row( @@ -29,53 +30,29 @@ class HistorySidebarHeader extends ConsumerWidget { ? kColorDarkDanger : kColorLightDanger, onPressed: () { - showDialog( - context: context, - builder: (context) => AlertDialog( - title: const Text('Clear History'), - content: const Text( - 'Are you sure you want to clear all history? This action cannot be undone.'), - actions: [ - TextButton( - onPressed: () => Navigator.pop(context), - child: const Text('Cancel'), - ), - TextButton( - onPressed: () async { - try { - await ref - .read(historyMetaStateNotifier.notifier) - .clearAllHistory(); - - if (context.mounted) { - Navigator.pop(context); - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar( - content: Text('History cleared successfully'), - duration: Duration(seconds: 2), - ), - ); - } - } catch (e) { - if (context.mounted) { - Navigator.pop(context); - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar( - content: Text('Error clearing history'), - backgroundColor: Colors.red, - duration: Duration(seconds: 2), - ), - ); - } - } - }, - style: TextButton.styleFrom( - foregroundColor: Theme.of(context).colorScheme.error, - ), - child: const Text('Clear'), - ), - ], - ), + showOkCancelDialog( + context, + dialogTitle: kTitleClearHistory, + content: kMsgClearHistory, + onClickOk: () async { + sm.hideCurrentSnackBar(); + try { + await ref + .read(historyMetaStateNotifier.notifier) + .clearAllHistory(); + sm.showSnackBar(getSnackBar( + kMsgClearHistorySuccess, + small: false, + )); + } catch (e) { + debugPrint("Clear History Stack: $e"); + sm.showSnackBar(getSnackBar( + kMsgClearHistoryError, + small: false, + color: kColorRed, + )); + } + }, ); }, ), From cd847886f099856f80a4e391568e01dbf986a807 Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Sun, 16 Feb 2025 13:28:54 +0530 Subject: [PATCH 11/11] Update his_sidebar_header.dart --- lib/screens/history/history_widgets/his_sidebar_header.dart | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/screens/history/history_widgets/his_sidebar_header.dart b/lib/screens/history/history_widgets/his_sidebar_header.dart index 862ec97f..24dd2153 100644 --- a/lib/screens/history/history_widgets/his_sidebar_header.dart +++ b/lib/screens/history/history_widgets/his_sidebar_header.dart @@ -42,13 +42,11 @@ class HistorySidebarHeader extends ConsumerWidget { .clearAllHistory(); sm.showSnackBar(getSnackBar( kMsgClearHistorySuccess, - small: false, )); } catch (e) { debugPrint("Clear History Stack: $e"); sm.showSnackBar(getSnackBar( kMsgClearHistoryError, - small: false, color: kColorRed, )); }