fix: onboarding
This commit is contained in:
@@ -678,20 +678,7 @@ final userSettingsProvider = FutureProvider<UserSettings>((ref) async {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Server Banners provider
|
|
||||||
final serverBannersProvider = FutureProvider<List<Map<String, dynamic>>>((
|
|
||||||
ref,
|
|
||||||
) async {
|
|
||||||
final api = ref.watch(apiServiceProvider);
|
|
||||||
if (api == null) return [];
|
|
||||||
|
|
||||||
try {
|
|
||||||
return await api.getBanners();
|
|
||||||
} catch (e) {
|
|
||||||
foundation.debugPrint('DEBUG: Error fetching banners: $e');
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Conversation Suggestions provider
|
// Conversation Suggestions provider
|
||||||
final conversationSuggestionsProvider = FutureProvider<List<String>>((
|
final conversationSuggestionsProvider = FutureProvider<List<String>>((
|
||||||
|
|||||||
@@ -952,16 +952,7 @@ class ApiService {
|
|||||||
await _dio.post('/api/v1/users/user/settings', data: settings);
|
await _dio.post('/api/v1/users/user/settings', data: settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Server Banners
|
|
||||||
Future<List<Map<String, dynamic>>> getBanners() async {
|
|
||||||
debugPrint('DEBUG: Fetching server banners');
|
|
||||||
final response = await _dio.get('/api/v1/configs/banners');
|
|
||||||
final data = response.data;
|
|
||||||
if (data is List) {
|
|
||||||
return data.cast<Map<String, dynamic>>();
|
|
||||||
}
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Suggestions
|
// Suggestions
|
||||||
Future<List<String>> getSuggestions() async {
|
Future<List<String>> getSuggestions() async {
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ import '../../../shared/services/brand_service.dart';
|
|||||||
import '../../../shared/theme/theme_extensions.dart';
|
import '../../../shared/theme/theme_extensions.dart';
|
||||||
import '../../../shared/widgets/conduit_components.dart';
|
import '../../../shared/widgets/conduit_components.dart';
|
||||||
import '../../../core/auth/auth_state_manager.dart';
|
import '../../../core/auth/auth_state_manager.dart';
|
||||||
import '../../onboarding/views/onboarding_sheet.dart';
|
|
||||||
import '../providers/unified_auth_providers.dart';
|
|
||||||
|
|
||||||
class AuthenticationPage extends ConsumerStatefulWidget {
|
class AuthenticationPage extends ConsumerStatefulWidget {
|
||||||
final ServerConfig serverConfig;
|
final ServerConfig serverConfig;
|
||||||
@@ -109,73 +109,9 @@ class _AuthenticationPageState extends ConsumerState<AuthenticationPage> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _initializeBackgroundResources(WidgetRef ref) {
|
|
||||||
// Initialize resources in the background without blocking UI
|
|
||||||
Future.microtask(() async {
|
|
||||||
try {
|
|
||||||
// Get the API service
|
|
||||||
final api = ref.read(apiServiceProvider);
|
|
||||||
if (api == null) {
|
|
||||||
debugPrint(
|
|
||||||
'DEBUG: API service not available for background initialization',
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Explicitly get the current auth token and set it on the API service
|
|
||||||
final authToken = ref.read(authTokenProvider3);
|
|
||||||
if (authToken != null && authToken.isNotEmpty) {
|
|
||||||
api.updateAuthToken(authToken);
|
|
||||||
debugPrint('DEBUG: Background - Set auth token on API service');
|
|
||||||
} else {
|
|
||||||
debugPrint('DEBUG: Background - No auth token available yet');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize the token updater for future updates
|
|
||||||
ref.read(apiTokenUpdaterProvider);
|
|
||||||
|
|
||||||
// Load models and set default in background
|
|
||||||
await ref.read(defaultModelProvider.future);
|
|
||||||
debugPrint('DEBUG: Background initialization completed');
|
|
||||||
|
|
||||||
// Onboarding: show once if not seen
|
|
||||||
final storage = ref.read(optimizedStorageServiceProvider);
|
|
||||||
final seen = await storage.getOnboardingSeen();
|
|
||||||
if (!seen && mounted) {
|
|
||||||
await Future.delayed(const Duration(milliseconds: 300));
|
|
||||||
if (!mounted) return;
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
|
||||||
final navContext = NavigationService.navigatorKey.currentContext;
|
|
||||||
if (!mounted || navContext == null) return;
|
|
||||||
_showOnboarding(navContext);
|
|
||||||
await storage.setOnboardingSeen(true);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
debugPrint('DEBUG: Background initialization failed: $e');
|
|
||||||
// Don't throw - this is background initialization
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void _showOnboarding(BuildContext context) {
|
|
||||||
showModalBottomSheet(
|
|
||||||
context: context,
|
|
||||||
backgroundColor: Colors.transparent,
|
|
||||||
isScrollControlled: true,
|
|
||||||
builder: (context) => Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: context.conduitTheme.surfaceBackground,
|
|
||||||
borderRadius: const BorderRadius.vertical(
|
|
||||||
top: Radius.circular(AppBorderRadius.modal),
|
|
||||||
),
|
|
||||||
boxShadow: ConduitShadows.modal,
|
|
||||||
),
|
|
||||||
child: const OnboardingSheet(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
String _formatLoginError(String error) {
|
String _formatLoginError(String error) {
|
||||||
if (error.contains('401') || error.contains('Unauthorized')) {
|
if (error.contains('401') || error.contains('Unauthorized')) {
|
||||||
@@ -197,8 +133,7 @@ class _AuthenticationPageState extends ConsumerState<AuthenticationPage> {
|
|||||||
if (mounted && next.isAuthenticated && previous?.isAuthenticated != true) {
|
if (mounted && next.isAuthenticated && previous?.isAuthenticated != true) {
|
||||||
debugPrint('DEBUG: Authentication successful, initializing background resources');
|
debugPrint('DEBUG: Authentication successful, initializing background resources');
|
||||||
|
|
||||||
// Initialize background resources
|
|
||||||
_initializeBackgroundResources(ref);
|
|
||||||
|
|
||||||
debugPrint('DEBUG: Navigating to chat page');
|
debugPrint('DEBUG: Navigating to chat page');
|
||||||
// Navigate directly to chat page on successful authentication
|
// Navigate directly to chat page on successful authentication
|
||||||
|
|||||||
@@ -1303,31 +1303,7 @@ class _ChatPageState extends ConsumerState<ChatPage> {
|
|||||||
children: [
|
children: [
|
||||||
Column(
|
Column(
|
||||||
children: [
|
children: [
|
||||||
// Server banners
|
|
||||||
Consumer(
|
|
||||||
builder: (context, ref, child) {
|
|
||||||
final banners = ref.watch(serverBannersProvider);
|
|
||||||
return banners.when(
|
|
||||||
data: (bannerList) => bannerList.isNotEmpty
|
|
||||||
? Container(
|
|
||||||
color: theme.colorScheme.primaryContainer
|
|
||||||
.withValues(alpha: Alpha.badgeBackground),
|
|
||||||
child: Column(
|
|
||||||
children: bannerList
|
|
||||||
.take(1)
|
|
||||||
.map(
|
|
||||||
(banner) =>
|
|
||||||
_buildChatBanner(context, banner),
|
|
||||||
)
|
|
||||||
.toList(),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: const SizedBox.shrink(),
|
|
||||||
loading: () => const SizedBox.shrink(),
|
|
||||||
error: (_, _) => const SizedBox.shrink(),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
|
|
||||||
// Messages Area with pull-to-refresh
|
// Messages Area with pull-to-refresh
|
||||||
Expanded(
|
Expanded(
|
||||||
@@ -2479,56 +2455,5 @@ class _SelectableMessageWrapper extends StatelessWidget {
|
|||||||
|
|
||||||
// Extension on _ChatPageState for utility methods
|
// Extension on _ChatPageState for utility methods
|
||||||
extension on _ChatPageState {
|
extension on _ChatPageState {
|
||||||
Widget _buildChatBanner(BuildContext context, Map<String, dynamic> banner) {
|
|
||||||
final theme = Theme.of(context);
|
|
||||||
|
|
||||||
final type = banner['type'] as String? ?? 'info';
|
|
||||||
final content = banner['content'] as String? ?? '';
|
|
||||||
|
|
||||||
if (content.isEmpty) return const SizedBox.shrink();
|
|
||||||
|
|
||||||
Color backgroundColor;
|
|
||||||
Color textColor;
|
|
||||||
IconData icon;
|
|
||||||
|
|
||||||
switch (type) {
|
|
||||||
case 'warning':
|
|
||||||
backgroundColor = context.conduitTheme.warning.withValues(alpha: 0.2);
|
|
||||||
textColor = context.conduitTheme.warning;
|
|
||||||
icon = Platform.isIOS
|
|
||||||
? CupertinoIcons.exclamationmark_triangle
|
|
||||||
: Icons.warning;
|
|
||||||
break;
|
|
||||||
case 'error':
|
|
||||||
backgroundColor = theme.colorScheme.errorContainer;
|
|
||||||
textColor = theme.colorScheme.onErrorContainer;
|
|
||||||
icon = Platform.isIOS ? CupertinoIcons.xmark_circle : Icons.error;
|
|
||||||
break;
|
|
||||||
default: // info
|
|
||||||
backgroundColor = theme.colorScheme.primaryContainer;
|
|
||||||
textColor = theme.colorScheme.onPrimaryContainer;
|
|
||||||
icon = Platform.isIOS ? CupertinoIcons.info_circle : Icons.info;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Container(
|
|
||||||
width: double.infinity,
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
||||||
color: backgroundColor,
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Icon(icon, color: textColor, size: 16),
|
|
||||||
const SizedBox(width: Spacing.sm),
|
|
||||||
Expanded(
|
|
||||||
child: Text(
|
|
||||||
content,
|
|
||||||
style: theme.textTheme.bodySmall?.copyWith(
|
|
||||||
color: textColor,
|
|
||||||
fontWeight: FontWeight.w500,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -213,12 +213,15 @@ class _ConduitAppState extends ConsumerState<ConduitApp> {
|
|||||||
// Onboarding: show once if not seen
|
// Onboarding: show once if not seen
|
||||||
final storage = ref.read(optimizedStorageServiceProvider);
|
final storage = ref.read(optimizedStorageServiceProvider);
|
||||||
final seen = await storage.getOnboardingSeen();
|
final seen = await storage.getOnboardingSeen();
|
||||||
|
|
||||||
if (!seen && mounted) {
|
if (!seen && mounted) {
|
||||||
await Future.delayed(const Duration(milliseconds: 300));
|
await Future.delayed(const Duration(milliseconds: 300));
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||||
final navContext = NavigationService.navigatorKey.currentContext;
|
final navContext = NavigationService.navigatorKey.currentContext;
|
||||||
if (!mounted || navContext == null) return;
|
if (!mounted || navContext == null) return;
|
||||||
|
|
||||||
_showOnboarding(navContext);
|
_showOnboarding(navContext);
|
||||||
await storage.setOnboardingSeen(true);
|
await storage.setOnboardingSeen(true);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user