From 40ba6a869d6dfe97dbf19dc4a99a1af3568d6d4b Mon Sep 17 00:00:00 2001 From: Jeroen Schweitzer Date: Mon, 5 Jan 2026 15:00:47 +0100 Subject: [PATCH] fix: apply default room preference on app load MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Root `/` now redirects to user's preferred default room - Front Hall moved to `/front-hall` route (was `/`) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- CHANGELOG.md | 7 +++++++ lib/routing/app_router.dart | 31 +++++++++++++++++++++++++++++-- pubspec.yaml | 2 +- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 00d0fc1..bb60d0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.3.1] - 2026-01-05 + +### Fixed +- Default room preference now applies on app load + - Root `/` redirects to user's preferred default room + - Front Hall moved to `/front-hall` route (was `/`) + ## [1.3.0] - 2026-01-05 ### Added diff --git a/lib/routing/app_router.dart b/lib/routing/app_router.dart index 54cfc03..ad09d68 100644 --- a/lib/routing/app_router.dart +++ b/lib/routing/app_router.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; +import 'package:tatlock_ui/core/auth/auth_provider.dart'; import 'package:tatlock_ui/features/control_room/router.dart'; import 'package:tatlock_ui/features/front_hall/presentation/pages/front_hall_page.dart'; import 'package:tatlock_ui/features/security/router.dart'; @@ -19,18 +20,44 @@ Page noTransitionPage(BuildContext context, GoRouterState state, Widget ch /// Route paths as constants. abstract class AppRoutes { - static const frontHall = '/'; + static const root = '/'; + static const frontHall = '/front-hall'; static const parlor = '/parlor'; static const settings = '/settings'; } +/// Maps defaultRoom preference value to route path. +String _routeForDefaultRoom(String? defaultRoom) { + return switch (defaultRoom) { + 'control-room' => ControlRoomRoutes.containers, + 'security' => SecurityRoutes.users, + 'parlor' => AppRoutes.parlor, + _ => AppRoutes.frontHall, + }; +} + /// Provides the GoRouter instance. @riverpod GoRouter appRouter(Ref ref) { + final authState = ref.watch(authProvider); + return GoRouter( - initialLocation: AppRoutes.frontHall, + initialLocation: AppRoutes.root, debugLogDiagnostics: true, + redirect: (context, state) { + // Redirect from root to user's default room preference + if (state.matchedLocation == AppRoutes.root) { + final defaultRoom = authState.value?.preferences?.defaultRoom; + return _routeForDefaultRoom(defaultRoom); + } + return null; + }, routes: [ + // Root redirects to default room (handled by redirect callback above) + GoRoute( + path: AppRoutes.root, + redirect: (context, state) => AppRoutes.frontHall, + ), // Main app routes (inside shell with app scaffold) ShellRoute( builder: (context, state, child) => AppScaffold(child: child), diff --git a/pubspec.yaml b/pubspec.yaml index 8f2fd8e..b5315a7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.3.0+1 +version: 1.3.1+1 environment: sdk: ^3.10.4