feat: move history to admin page
This commit is contained in:
+67
-33
@@ -1,3 +1,4 @@
|
|||||||
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||||
@@ -19,6 +20,67 @@ import '../utils/app_update_util.dart';
|
|||||||
|
|
||||||
final RouteObserver<PageRoute> routeObserver = RouteObserver<PageRoute>();
|
final RouteObserver<PageRoute> routeObserver = RouteObserver<PageRoute>();
|
||||||
|
|
||||||
|
String? _redirectApp({
|
||||||
|
required PinLockViewModel pinLockViewModel,
|
||||||
|
required AdminPinViewModel adminPinViewModel,
|
||||||
|
required GoRouterState state,
|
||||||
|
}) {
|
||||||
|
if (!pinLockViewModel.hasLoaded || !adminPinViewModel.hasLoaded) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final location = state.uri.path;
|
||||||
|
final goingToLock = location == '/lock';
|
||||||
|
final goingToAdminLock = location == '/admin/lock';
|
||||||
|
final mustBeOnLock = _mustBeOnLock(pinLockViewModel);
|
||||||
|
|
||||||
|
if (mustBeOnLock && !goingToLock) return '/lock';
|
||||||
|
if (!mustBeOnLock && goingToLock) return '/bar';
|
||||||
|
|
||||||
|
final isAdminArea = _isAdminArea(location);
|
||||||
|
final isDebugShortcutArea = _isDebugShortcutArea(location);
|
||||||
|
|
||||||
|
if (isAdminArea &&
|
||||||
|
!isDebugShortcutArea &&
|
||||||
|
!goingToAdminLock &&
|
||||||
|
!adminPinViewModel.isUnlocked) {
|
||||||
|
return '/admin/lock';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (goingToAdminLock && adminPinViewModel.isUnlocked) return '/admin';
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool _mustBeOnLock(PinLockViewModel pinLockViewModel) {
|
||||||
|
final needsPinSetup =
|
||||||
|
!pinLockViewModel.isPinSet && pinLockViewModel.pinRequired;
|
||||||
|
final isLocked =
|
||||||
|
pinLockViewModel.isPinSet &&
|
||||||
|
!pinLockViewModel.isUnlocked &&
|
||||||
|
pinLockViewModel.pinRequired;
|
||||||
|
|
||||||
|
return needsPinSetup || isLocked;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool _isAdminArea(String location) {
|
||||||
|
return location == '/admin' ||
|
||||||
|
location.startsWith('/admin/') ||
|
||||||
|
location == '/products' ||
|
||||||
|
location.startsWith('/products/') ||
|
||||||
|
location == '/history' ||
|
||||||
|
location.startsWith('/history/');
|
||||||
|
}
|
||||||
|
|
||||||
|
bool _isDebugShortcutArea(String location) {
|
||||||
|
if (!kDebugMode) return false;
|
||||||
|
|
||||||
|
return location == '/products' ||
|
||||||
|
location.startsWith('/products/') ||
|
||||||
|
location == '/history' ||
|
||||||
|
location.startsWith('/history/');
|
||||||
|
}
|
||||||
|
|
||||||
GoRouter createAppRouter(
|
GoRouter createAppRouter(
|
||||||
PinLockViewModel pinLockViewModel, {
|
PinLockViewModel pinLockViewModel, {
|
||||||
required AdminPinViewModel adminPinViewModel,
|
required AdminPinViewModel adminPinViewModel,
|
||||||
@@ -27,39 +89,11 @@ GoRouter createAppRouter(
|
|||||||
initialLocation: '/bar',
|
initialLocation: '/bar',
|
||||||
observers: [routeObserver, SentryNavigatorObserver()],
|
observers: [routeObserver, SentryNavigatorObserver()],
|
||||||
refreshListenable: Listenable.merge([pinLockViewModel, adminPinViewModel]),
|
refreshListenable: Listenable.merge([pinLockViewModel, adminPinViewModel]),
|
||||||
redirect: (context, state) {
|
redirect: (_, state) => _redirectApp(
|
||||||
if (!pinLockViewModel.hasLoaded || !adminPinViewModel.hasLoaded) {
|
pinLockViewModel: pinLockViewModel,
|
||||||
return null;
|
adminPinViewModel: adminPinViewModel,
|
||||||
}
|
state: state,
|
||||||
|
),
|
||||||
final needsPinSetup =
|
|
||||||
!pinLockViewModel.isPinSet && pinLockViewModel.pinRequired;
|
|
||||||
final isLocked =
|
|
||||||
pinLockViewModel.isPinSet &&
|
|
||||||
!pinLockViewModel.isUnlocked &&
|
|
||||||
pinLockViewModel.pinRequired;
|
|
||||||
final mustBeOnLock = needsPinSetup || isLocked;
|
|
||||||
|
|
||||||
final location = state.uri.path;
|
|
||||||
final goingToLock = location == '/lock';
|
|
||||||
final goingToAdminLock = location == '/admin/lock';
|
|
||||||
final isAdminArea =
|
|
||||||
location == '/admin' ||
|
|
||||||
location.startsWith('/admin/') ||
|
|
||||||
location == '/products' ||
|
|
||||||
location.startsWith('/products/');
|
|
||||||
|
|
||||||
if (mustBeOnLock && !goingToLock) return '/lock';
|
|
||||||
if (!mustBeOnLock && goingToLock) return '/bar';
|
|
||||||
|
|
||||||
if (isAdminArea && !goingToAdminLock && !adminPinViewModel.isUnlocked) {
|
|
||||||
return '/admin/lock';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (goingToAdminLock && adminPinViewModel.isUnlocked) return '/admin';
|
|
||||||
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
routes: [
|
routes: [
|
||||||
GoRoute(path: '/', redirect: (context, state) => '/bar'),
|
GoRoute(path: '/', redirect: (context, state) => '/bar'),
|
||||||
GoRoute(
|
GoRoute(
|
||||||
|
|||||||
@@ -54,6 +54,12 @@ class AdminScreenView extends StatelessWidget {
|
|||||||
subtitle: l10n.manageProducts,
|
subtitle: l10n.manageProducts,
|
||||||
onTap: () => context.push('/products'),
|
onTap: () => context.push('/products'),
|
||||||
),
|
),
|
||||||
|
_AdminTile(
|
||||||
|
icon: Icons.history_rounded,
|
||||||
|
title: l10n.tabHistory,
|
||||||
|
subtitle: l10n.closedTabs,
|
||||||
|
onTap: () => context.push('/history'),
|
||||||
|
),
|
||||||
_AdminTile(
|
_AdminTile(
|
||||||
icon: Icons.file_upload_outlined,
|
icon: Icons.file_upload_outlined,
|
||||||
title: l10n.importData,
|
title: l10n.importData,
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:kooltab2/viewmodels/admin_pin_view_model.dart';
|
import 'package:kooltab2/viewmodels/admin_pin_view_model.dart';
|
||||||
@@ -57,12 +58,28 @@ class _BarScreenViewState extends State<BarScreenView> {
|
|||||||
onPressed: () => context.push('/admin'),
|
onPressed: () => context.push('/admin'),
|
||||||
icon: const Icon(Icons.admin_panel_settings_outlined),
|
icon: const Icon(Icons.admin_panel_settings_outlined),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 6),
|
if (kDebugMode) ...[
|
||||||
IconButton(
|
const SizedBox(width: 6),
|
||||||
tooltip: l10n.tabHistory,
|
IconButton(
|
||||||
onPressed: () => context.push('/history'),
|
tooltip: l10n.manageProducts,
|
||||||
icon: const Icon(Icons.history_rounded),
|
style: IconButton.styleFrom(
|
||||||
),
|
backgroundColor: Colors.yellow,
|
||||||
|
foregroundColor: Colors.black,
|
||||||
|
),
|
||||||
|
onPressed: () => context.push('/products'),
|
||||||
|
icon: const Icon(Icons.inventory_2_outlined),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 6),
|
||||||
|
IconButton(
|
||||||
|
tooltip: l10n.tabHistory,
|
||||||
|
style: IconButton.styleFrom(
|
||||||
|
backgroundColor: Colors.yellow,
|
||||||
|
foregroundColor: Colors.black,
|
||||||
|
),
|
||||||
|
onPressed: () => context.push('/history'),
|
||||||
|
icon: const Icon(Icons.history_rounded),
|
||||||
|
),
|
||||||
|
],
|
||||||
const SizedBox(width: 6),
|
const SizedBox(width: 6),
|
||||||
IconButton(
|
IconButton(
|
||||||
tooltip: l10n.refresh,
|
tooltip: l10n.refresh,
|
||||||
|
|||||||
Reference in New Issue
Block a user