feat: deploy infrastructure + disk/drive, calendar, presentation, workspaces, onboarding, demo user
This commit is contained in:
@@ -0,0 +1,198 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import '../../core/api/client.dart';
|
||||
import '../../core/api/endpoints.dart';
|
||||
import '../../core/theme/app_theme.dart';
|
||||
import '../../models/auth.dart';
|
||||
import '../../providers/auth_provider.dart';
|
||||
|
||||
class CalendarIntegrationScreen extends ConsumerStatefulWidget {
|
||||
const CalendarIntegrationScreen({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<CalendarIntegrationScreen> createState() =>
|
||||
_CalendarIntegrationScreenState();
|
||||
}
|
||||
|
||||
class _CalendarIntegrationScreenState
|
||||
extends ConsumerState<CalendarIntegrationScreen> {
|
||||
List<dynamic> _providers = [];
|
||||
Map<String, dynamic>? _status;
|
||||
bool _isLoading = true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadData();
|
||||
}
|
||||
|
||||
Future<void> _loadData() async {
|
||||
setState(() => _isLoading = true);
|
||||
try {
|
||||
final api = ref.read(apiClientProvider);
|
||||
final providersResp = await api.get(Endpoints.calendarProviders);
|
||||
final statusResp = await api.get(Endpoints.calendarStatus);
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_providers = providersResp.data as List<dynamic>? ?? [];
|
||||
_status = statusResp.data as Map<String, dynamic>?;
|
||||
});
|
||||
}
|
||||
} catch (_) {}
|
||||
if (mounted) setState(() => _isLoading = false);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final user = ref.watch(authProvider).user;
|
||||
final isConnected = user?.calendarProvider != null;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Интеграция календаря')),
|
||||
body: _isLoading
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
if (isConnected) ...[
|
||||
Card(
|
||||
color: VoIdeaColors.success.withOpacity(0.05),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.check_circle,
|
||||
color: VoIdeaColors.success),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text('Календарь подключён',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w600)),
|
||||
Text(
|
||||
'Провайдер: ${user!.calendarProvider}',
|
||||
style: const TextStyle(fontSize: 12),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: _disconnectCalendar,
|
||||
child: const Text('Отключить',
|
||||
style: TextStyle(
|
||||
color: VoIdeaColors.error)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
] else
|
||||
Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
children: [
|
||||
const Icon(Icons.calendar_month,
|
||||
size: 48, color: VoIdeaColors.primary),
|
||||
const SizedBox(height: 16),
|
||||
const Text(
|
||||
'Подключите календарь для автоматического создания событий из идей',
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
...(_providers.map((p) {
|
||||
final name = p['name'] as String? ?? '';
|
||||
final icon = name == 'google'
|
||||
? Icons.g_mobiledata
|
||||
: name == 'yandex'
|
||||
? Icons.cloud
|
||||
: Icons.calendar_today;
|
||||
return Padding(
|
||||
padding:
|
||||
const EdgeInsets.only(bottom: 8),
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: () =>
|
||||
_connectProvider(name),
|
||||
icon: Icon(icon),
|
||||
label: Text(_providerLabel(name)),
|
||||
),
|
||||
);
|
||||
})),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
if (_status != null) ...[
|
||||
const SizedBox(height: 16),
|
||||
Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text('Статус календаря',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w600)),
|
||||
const SizedBox(height: 8),
|
||||
...(_status!.entries.map((e) => Padding(
|
||||
padding:
|
||||
const EdgeInsets.only(bottom: 4),
|
||||
child: Row(
|
||||
children: [
|
||||
Text('${e.key}: ',
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
color:
|
||||
VoIdeaColors.muted)),
|
||||
Text('${e.value}',
|
||||
style:
|
||||
const TextStyle(fontSize: 13)),
|
||||
],
|
||||
),
|
||||
))),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _providerLabel(String name) {
|
||||
switch (name) {
|
||||
case 'google':
|
||||
return 'Google Calendar';
|
||||
case 'yandex':
|
||||
return 'Яндекс Календарь';
|
||||
case 'apple':
|
||||
return 'Apple Календарь';
|
||||
default:
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _connectProvider(String provider) async {
|
||||
try {
|
||||
final api = ref.read(apiClientProvider);
|
||||
final response =
|
||||
await api.get('${Endpoints.calendarProviders}/$provider');
|
||||
final url = response.data['url'] as String?;
|
||||
if (url != null && await canLaunchUrl(Uri.parse(url))) {
|
||||
await launchUrl(Uri.parse(url), mode: LaunchMode.externalApplication);
|
||||
}
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
Future<void> _disconnectCalendar() async {
|
||||
try {
|
||||
final api = ref.read(apiClientProvider);
|
||||
await api.post(Endpoints.calendarDisconnect);
|
||||
if (mounted) _loadData();
|
||||
} catch (_) {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import '../../providers/disk_provider.dart';
|
||||
import '../../core/theme/app_theme.dart';
|
||||
|
||||
class DiskIntegrationScreen extends ConsumerStatefulWidget {
|
||||
const DiskIntegrationScreen({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<DiskIntegrationScreen> createState() =>
|
||||
_DiskIntegrationScreenState();
|
||||
}
|
||||
|
||||
class _DiskIntegrationScreenState extends ConsumerState<DiskIntegrationScreen> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
Future.microtask(() => ref.read(diskProvider.notifier).load());
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final state = ref.watch(diskProvider);
|
||||
final notifier = ref.read(diskProvider.notifier);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Облачные диски')),
|
||||
body: state.isLoading
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
children: [
|
||||
const Icon(Icons.cloud, size: 48,
|
||||
color: VoIdeaColors.primary),
|
||||
const SizedBox(height: 12),
|
||||
const Text(
|
||||
'Подключите облачный диск для сохранения презентаций и экспорта',
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
...state.availableProviders.map((provider) {
|
||||
final connected = state.isConnected(provider);
|
||||
final info = connected
|
||||
? state.connectedProviders.firstWhere(
|
||||
(p) => p['provider'] == provider,
|
||||
orElse: () => {},
|
||||
)
|
||||
: null;
|
||||
final icon = _providerIcon(provider);
|
||||
final label = _providerLabel(provider);
|
||||
|
||||
return Card(
|
||||
margin: const EdgeInsets.only(bottom: 8),
|
||||
child: ListTile(
|
||||
leading: CircleAvatar(
|
||||
backgroundColor: connected
|
||||
? VoIdeaColors.success.withOpacity(0.1)
|
||||
: VoIdeaColors.muted.withOpacity(0.1),
|
||||
child: Icon(icon,
|
||||
color: connected
|
||||
? VoIdeaColors.success
|
||||
: VoIdeaColors.muted),
|
||||
),
|
||||
title: Text(label),
|
||||
subtitle: connected
|
||||
? Text(
|
||||
info?['email'] ?? 'Подключён',
|
||||
style: const TextStyle(fontSize: 12),
|
||||
)
|
||||
: const Text('Не подключён',
|
||||
style: TextStyle(fontSize: 12)),
|
||||
trailing: connected
|
||||
? TextButton(
|
||||
onPressed: () =>
|
||||
_confirmDisconnect(context, notifier, provider),
|
||||
child: const Text('Отключить',
|
||||
style: TextStyle(color: VoIdeaColors.error)),
|
||||
)
|
||||
: ElevatedButton(
|
||||
onPressed: () => _connect(context, notifier, provider),
|
||||
child: const Text('Подключить'),
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
IconData _providerIcon(String provider) {
|
||||
switch (provider) {
|
||||
case 'google':
|
||||
return Icons.g_mobiledata;
|
||||
case 'yandex':
|
||||
return Icons.cloud;
|
||||
case 'apple':
|
||||
return Icons.apple;
|
||||
default:
|
||||
return Icons.drive_file_rename_outline;
|
||||
}
|
||||
}
|
||||
|
||||
String _providerLabel(String provider) {
|
||||
switch (provider) {
|
||||
case 'google':
|
||||
return 'Google Диск';
|
||||
case 'yandex':
|
||||
return 'Яндекс Диск';
|
||||
case 'apple':
|
||||
return 'iCloud';
|
||||
default:
|
||||
return provider;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _connect(
|
||||
BuildContext context, DiskNotifier notifier, String provider) async {
|
||||
final url = await notifier.getOAuthUrl(provider);
|
||||
if (url != null && await canLaunchUrl(Uri.parse(url))) {
|
||||
await launchUrl(Uri.parse(url), mode: LaunchMode.externalApplication);
|
||||
// After OAuth callback, app returns with code in URL
|
||||
// For simplicity, show a dialog to paste the code
|
||||
if (mounted) _showCodeDialog(context, notifier, provider);
|
||||
}
|
||||
}
|
||||
|
||||
void _showCodeDialog(
|
||||
BuildContext context, DiskNotifier notifier, String provider) {
|
||||
final controller = TextEditingController();
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: Text('Подключить ${_providerLabel(provider)}'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text('После авторизации вставьте код из URL-параметра'),
|
||||
const SizedBox(height: 12),
|
||||
TextField(
|
||||
controller: controller,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Код авторизации',
|
||||
hintText: 'Вставьте code из URL',
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(ctx),
|
||||
child: const Text('Отмена'),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
if (controller.text.isNotEmpty) {
|
||||
await notifier.connect(provider, controller.text.trim());
|
||||
if (ctx.mounted) Navigator.pop(ctx);
|
||||
}
|
||||
},
|
||||
child: const Text('Подключить'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _confirmDisconnect(
|
||||
BuildContext context, DiskNotifier notifier, String provider) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: Text('Отключить ${_providerLabel(provider)}?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(ctx),
|
||||
child: const Text('Отмена'),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
notifier.disconnect(provider);
|
||||
Navigator.pop(ctx);
|
||||
},
|
||||
child: const Text('Отключить'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user