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
1 change: 1 addition & 0 deletions lib/actions/actions.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'save_action.dart';
41 changes: 41 additions & 0 deletions lib/actions/save_action.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:apidash/providers/providers.dart';
import 'package:apidash/utils/utils.dart';

/// Intent for the save action triggered by keyboard shortcut
class SaveIntent extends Intent {
const SaveIntent();
}

/// Action that handles the save operation when triggered by keyboard shortcut
class SaveAction extends Action<SaveIntent> {
SaveAction({
required this.ref,
required this.context,
});

final WidgetRef ref;
final BuildContext context;

@override
Future<void> invoke(SaveIntent intent) async {
// Check if there are unsaved changes
final hasUnsavedChanges = ref.read(hasUnsavedChangesProvider);
if (!hasUnsavedChanges) {
return;
}

// Check if save is already in progress
final savingData = ref.read(saveDataStateProvider);
if (savingData) {
return;
}

// Perform the save operation
await saveAndShowDialog(context, onSave: () async {
await ref.read(collectionStateNotifierProvider.notifier).saveData();
await ref.read(environmentsStateNotifierProvider.notifier).saveEnvironments();
});
}
}
276 changes: 146 additions & 130 deletions lib/screens/dashboard.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import 'package:apidash_design_system/apidash_design_system.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:apidash/providers/providers.dart';
import 'package:apidash/widgets/widgets.dart';
import 'package:apidash/consts.dart';
import 'package:apidash/dashbot/dashbot.dart';
import 'package:apidash/actions/actions.dart';
import 'common_widgets/common_widgets.dart';
import 'envvar/environment_page.dart';
import 'home_page/home_page.dart';
Expand All @@ -24,151 +26,165 @@ class Dashboard extends ConsumerWidget {
.watch(dashbotWindowNotifierProvider.select((value) => value.isActive));
final isDashBotPopped = ref
.watch(dashbotWindowNotifierProvider.select((value) => value.isPopped));
return Scaffold(
body: SafeArea(
child: Row(
children: <Widget>[
Column(
children: [
SizedBox(
height: kIsMacOS ? 32.0 : 16.0,
width: 64,
),

return Shortcuts(
shortcuts: <LogicalKeySet, Intent>{
LogicalKeySet(
kIsMacOS ? LogicalKeyboardKey.meta : LogicalKeyboardKey.control,
LogicalKeyboardKey.keyS,
): const SaveIntent(),
},
child: Actions(
actions: <Type, Action<Intent>>{
SaveIntent: SaveAction(ref: ref, context: context),
},
child: Scaffold(
body: SafeArea(
child: Row(
children: <Widget>[
Column(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(
isSelected: railIdx == 0,
onPressed: () {
ref.read(navRailIndexStateProvider.notifier).state = 0;
},
icon: const Icon(Icons.auto_awesome_mosaic_outlined),
selectedIcon: const Icon(Icons.auto_awesome_mosaic),
),
Text(
'Requests',
style: Theme.of(context).textTheme.labelSmall,
),
kVSpacer10,
IconButton(
isSelected: railIdx == 1,
onPressed: () {
ref.read(navRailIndexStateProvider.notifier).state = 1;
},
icon: const Icon(Icons.laptop_windows_outlined),
selectedIcon: const Icon(Icons.laptop_windows),
),
Text(
'Variables',
style: Theme.of(context).textTheme.labelSmall,
SizedBox(
height: kIsMacOS ? 32.0 : 16.0,
width: 64,
),
kVSpacer10,
IconButton(
isSelected: railIdx == 2,
onPressed: () {
ref.read(navRailIndexStateProvider.notifier).state = 2;
},
icon: const Icon(Icons.history_outlined),
selectedIcon: const Icon(Icons.history_rounded),
),
Text(
'History',
style: Theme.of(context).textTheme.labelSmall,
Column(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(
isSelected: railIdx == 0,
onPressed: () {
ref.read(navRailIndexStateProvider.notifier).state = 0;
},
icon: const Icon(Icons.auto_awesome_mosaic_outlined),
selectedIcon: const Icon(Icons.auto_awesome_mosaic),
),
Text(
'Requests',
style: Theme.of(context).textTheme.labelSmall,
),
kVSpacer10,
IconButton(
isSelected: railIdx == 1,
onPressed: () {
ref.read(navRailIndexStateProvider.notifier).state = 1;
},
icon: const Icon(Icons.laptop_windows_outlined),
selectedIcon: const Icon(Icons.laptop_windows),
),
Text(
'Variables',
style: Theme.of(context).textTheme.labelSmall,
),
kVSpacer10,
IconButton(
isSelected: railIdx == 2,
onPressed: () {
ref.read(navRailIndexStateProvider.notifier).state = 2;
},
icon: const Icon(Icons.history_outlined),
selectedIcon: const Icon(Icons.history_rounded),
),
Text(
'History',
style: Theme.of(context).textTheme.labelSmall,
),
kVSpacer10,
Badge(
backgroundColor: Theme.of(context).colorScheme.error,
isLabelVisible:
ref.watch(showTerminalBadgeProvider) && railIdx != 3,
child: IconButton(
isSelected: railIdx == 3,
onPressed: () {
ref.read(navRailIndexStateProvider.notifier).state =
3;
ref.read(showTerminalBadgeProvider.notifier).state =
false;
},
icon: const Icon(Icons.terminal_outlined),
selectedIcon: const Icon(Icons.terminal),
),
),
Text(
'Logs',
style: Theme.of(context).textTheme.labelSmall,
),
],
),
kVSpacer10,
Badge(
backgroundColor: Theme.of(context).colorScheme.error,
isLabelVisible:
ref.watch(showTerminalBadgeProvider) && railIdx != 3,
child: IconButton(
isSelected: railIdx == 3,
onPressed: () {
ref.read(navRailIndexStateProvider.notifier).state =
3;
ref.read(showTerminalBadgeProvider.notifier).state =
false;
},
icon: const Icon(Icons.terminal_outlined),
selectedIcon: const Icon(Icons.terminal),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Padding(
padding: const EdgeInsets.only(bottom: 16.0),
child: NavbarButton(
railIdx: railIdx,
selectedIcon: Icons.help,
icon: Icons.help_outline,
label: 'About',
showLabel: false,
isCompact: true,
onTap: () {
showAboutAppDialog(context);
},
),
),
Padding(
padding: const EdgeInsets.only(bottom: 16.0),
child: NavbarButton(
railIdx: railIdx,
buttonIdx: 4,
selectedIcon: Icons.settings,
icon: Icons.settings_outlined,
label: 'Settings',
showLabel: false,
isCompact: true,
),
),
],
),
),
Text(
'Logs',
style: Theme.of(context).textTheme.labelSmall,
),
],
),
VerticalDivider(
thickness: 1,
width: 1,
color: Theme.of(context).colorScheme.surfaceContainerHigh,
),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Padding(
padding: const EdgeInsets.only(bottom: 16.0),
child: NavbarButton(
railIdx: railIdx,
selectedIcon: Icons.help,
icon: Icons.help_outline,
label: 'About',
showLabel: false,
isCompact: true,
onTap: () {
showAboutAppDialog(context);
},
),
),
Padding(
padding: const EdgeInsets.only(bottom: 16.0),
child: NavbarButton(
railIdx: railIdx,
buttonIdx: 4,
selectedIcon: Icons.settings,
icon: Icons.settings_outlined,
label: 'Settings',
showLabel: false,
isCompact: true,
),
),
child: IndexedStack(
alignment: AlignmentDirectional.topCenter,
index: railIdx,
children: const [
HomePage(),
EnvironmentPage(),
HistoryPage(),
TerminalPage(),
SettingsPage(),
],
),
),
)
],
),
VerticalDivider(
thickness: 1,
width: 1,
color: Theme.of(context).colorScheme.surfaceContainerHigh,
),
Expanded(
child: IndexedStack(
alignment: AlignmentDirectional.topCenter,
index: railIdx,
children: const [
HomePage(),
EnvironmentPage(),
HistoryPage(),
TerminalPage(),
SettingsPage(),
],
),
)
],
),
floatingActionButton: isDashBotEnabled &&
!isDashBotActive &&
isDashBotPopped
? FloatingActionButton(
backgroundColor: Theme.of(context).colorScheme.primaryContainer,
onPressed: () => showDashbotWindow(context, ref),
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: 6.0,
horizontal: 10,
),
child: DashbotIcons.getDashbotIcon1(),
),
)
: null,
),
),
floatingActionButton: isDashBotEnabled &&
!isDashBotActive &&
isDashBotPopped
? FloatingActionButton(
backgroundColor: Theme.of(context).colorScheme.primaryContainer,
onPressed: () => showDashbotWindow(context, ref),
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: 6.0,
horizontal: 10,
),
child: DashbotIcons.getDashbotIcon1(),
),
)
: null,
);
}
}
Loading