refactor(auth): migrate to unified auth providers and simplify user retrieval
This commit is contained in:
@@ -12,6 +12,7 @@ import '../../../shared/widgets/responsive_drawer_layout.dart';
|
|||||||
import '../../navigation/widgets/chats_drawer.dart';
|
import '../../navigation/widgets/chats_drawer.dart';
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import '../../../core/providers/app_providers.dart';
|
import '../../../core/providers/app_providers.dart';
|
||||||
|
import '../../auth/providers/unified_auth_providers.dart';
|
||||||
import '../providers/chat_providers.dart';
|
import '../providers/chat_providers.dart';
|
||||||
import '../../../core/utils/debug_logger.dart';
|
import '../../../core/utils/debug_logger.dart';
|
||||||
import '../../../core/utils/user_display_name.dart';
|
import '../../../core/utils/user_display_name.dart';
|
||||||
@@ -1122,12 +1123,12 @@ class _ChatPageState extends ConsumerState<ChatPage> {
|
|||||||
|
|
||||||
Widget _buildEmptyState(ThemeData theme) {
|
Widget _buildEmptyState(ThemeData theme) {
|
||||||
final l10n = AppLocalizations.of(context)!;
|
final l10n = AppLocalizations.of(context)!;
|
||||||
final currentUserAsync = ref.watch(currentUserProvider);
|
final authUser = ref.watch(currentUserProvider2);
|
||||||
final userFromProfile = currentUserAsync.maybeWhen(
|
final asyncUser = ref.watch(currentUserProvider);
|
||||||
data: (user) => user,
|
final user = asyncUser.maybeWhen(
|
||||||
orElse: () => null,
|
data: (value) => value ?? authUser,
|
||||||
|
orElse: () => authUser,
|
||||||
);
|
);
|
||||||
final user = userFromProfile;
|
|
||||||
String? greetingName;
|
String? greetingName;
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
final derived = deriveUserDisplayName(user, fallback: '').trim();
|
final derived = deriveUserDisplayName(user, fallback: '').trim();
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
|
|
||||||
import '../../../core/providers/app_providers.dart';
|
import '../../../core/providers/app_providers.dart';
|
||||||
|
import '../../auth/providers/unified_auth_providers.dart';
|
||||||
import '../../../shared/theme/theme_extensions.dart';
|
import '../../../shared/theme/theme_extensions.dart';
|
||||||
import '../../chat/providers/chat_providers.dart' as chat;
|
import '../../chat/providers/chat_providers.dart' as chat;
|
||||||
// import '../../files/views/files_page.dart';
|
// import '../../files/views/files_page.dart';
|
||||||
@@ -1477,12 +1478,7 @@ class _ChatsDrawerState extends ConsumerState<ChatsDrawer> {
|
|||||||
Widget _buildBottomSection(BuildContext context) {
|
Widget _buildBottomSection(BuildContext context) {
|
||||||
final theme = context.conduitTheme;
|
final theme = context.conduitTheme;
|
||||||
final sidebarTheme = context.sidebarTheme;
|
final sidebarTheme = context.sidebarTheme;
|
||||||
final currentUserAsync = ref.watch(currentUserProvider);
|
final user = ref.watch(currentUserProvider2);
|
||||||
final userFromProfile = currentUserAsync.maybeWhen(
|
|
||||||
data: (u) => u,
|
|
||||||
orElse: () => null,
|
|
||||||
);
|
|
||||||
final user = userFromProfile;
|
|
||||||
final api = ref.watch(apiServiceProvider);
|
final api = ref.watch(apiServiceProvider);
|
||||||
|
|
||||||
String initialFor(String name) {
|
String initialFor(String name) {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|||||||
import 'package:flutter_animate/flutter_animate.dart';
|
import 'package:flutter_animate/flutter_animate.dart';
|
||||||
import 'package:conduit/l10n/app_localizations.dart';
|
import 'package:conduit/l10n/app_localizations.dart';
|
||||||
|
|
||||||
import '../../../core/providers/app_providers.dart';
|
import '../../auth/providers/unified_auth_providers.dart';
|
||||||
import '../../../core/utils/user_display_name.dart';
|
import '../../../core/utils/user_display_name.dart';
|
||||||
import '../../../shared/theme/theme_extensions.dart';
|
import '../../../shared/theme/theme_extensions.dart';
|
||||||
import '../../../shared/widgets/sheet_handle.dart';
|
import '../../../shared/widgets/sheet_handle.dart';
|
||||||
@@ -67,12 +67,7 @@ class _OnboardingSheetState extends ConsumerState<OnboardingSheet> {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final height = MediaQuery.of(context).size.height;
|
final height = MediaQuery.of(context).size.height;
|
||||||
final l10n = AppLocalizations.of(context)!;
|
final l10n = AppLocalizations.of(context)!;
|
||||||
final currentUserAsync = ref.watch(currentUserProvider);
|
final user = ref.watch(currentUserProvider2);
|
||||||
final userFromProfile = currentUserAsync.maybeWhen(
|
|
||||||
data: (user) => user,
|
|
||||||
orElse: () => null,
|
|
||||||
);
|
|
||||||
final user = userFromProfile;
|
|
||||||
final greetingName = deriveUserDisplayName(user);
|
final greetingName = deriveUserDisplayName(user);
|
||||||
final pages = _buildPages(l10n, greetingName);
|
final pages = _buildPages(l10n, greetingName);
|
||||||
final pageCount = pages.length;
|
final pageCount = pages.length;
|
||||||
|
|||||||
@@ -41,40 +41,23 @@ class ProfilePage extends ConsumerWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
final user = ref.watch(currentUserProvider);
|
final user = ref.watch(currentUserProvider2);
|
||||||
|
final isAuthLoading = ref.watch(isAuthLoadingProvider2);
|
||||||
final api = ref.watch(apiServiceProvider);
|
final api = ref.watch(apiServiceProvider);
|
||||||
|
|
||||||
return ErrorBoundary(
|
Widget body;
|
||||||
child: user.when(
|
if (isAuthLoading && user == null) {
|
||||||
data: (userData) => _buildScaffold(
|
body = _buildCenteredState(
|
||||||
context,
|
context,
|
||||||
body: _buildProfileBody(context, ref, userData, api),
|
ImprovedLoadingState(
|
||||||
|
message: AppLocalizations.of(context)!.loadingProfile,
|
||||||
),
|
),
|
||||||
loading: () => _buildScaffold(
|
);
|
||||||
context,
|
} else {
|
||||||
body: _buildCenteredState(
|
body = _buildProfileBody(context, ref, user, api);
|
||||||
context,
|
}
|
||||||
ImprovedLoadingState(
|
|
||||||
message: AppLocalizations.of(context)!.loadingProfile,
|
return ErrorBoundary(child: _buildScaffold(context, body: body));
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
error: (error, stack) => _buildScaffold(
|
|
||||||
context,
|
|
||||||
body: _buildCenteredState(
|
|
||||||
context,
|
|
||||||
ImprovedEmptyState(
|
|
||||||
title: AppLocalizations.of(context)!.unableToLoadProfile,
|
|
||||||
subtitle: AppLocalizations.of(context)!.pleaseCheckConnection,
|
|
||||||
icon: UiUtils.platformIcon(
|
|
||||||
ios: CupertinoIcons.exclamationmark_triangle,
|
|
||||||
android: Icons.error_outline,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Scaffold _buildScaffold(BuildContext context, {required Widget body}) {
|
Scaffold _buildScaffold(BuildContext context, {required Widget body}) {
|
||||||
|
|||||||
Reference in New Issue
Block a user