Phase 2 of Organizr Migration - Front Hall restructure: - Add FrontHallState provider with three modes (dashboard, iframe, settings) - Create QuickLinksPanel widget with categorized links and overflow menus - Add IframeView with platform-aware implementation (web iframe, mobile fallback) - Extract DashboardContent from FrontHallPage - Add QuickLinkSettingsContent placeholder for Phase 4 link editor - Implement QuickLink entity and data layer with Core API datasource - Add default quick links fallback when API unavailable - Update UI_LAYOUT.md with Front Hall panel configurations 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
94 lines
2.6 KiB
Dart
94 lines
2.6 KiB
Dart
import 'package:dio/dio.dart';
|
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
import 'package:tatlock_ui/core/api/api_client.dart';
|
|
import 'package:tatlock_ui/features/front_hall/data/models/quick_link_model.dart';
|
|
import 'package:tatlock_ui/features/front_hall/domain/entities/quick_link.dart';
|
|
|
|
part 'quick_links_datasource.g.dart';
|
|
|
|
/// Data source for quick link operations.
|
|
///
|
|
/// Provides CRUD operations for Front Hall quick links via Core API.
|
|
class QuickLinksDatasource {
|
|
QuickLinksDatasource(this._dio);
|
|
|
|
final Dio _dio;
|
|
|
|
static const _basePath = '/front-hall/quick-links';
|
|
|
|
/// Gets all quick links.
|
|
Future<List<QuickLink>> getQuickLinks() async {
|
|
final response = await _dio.get<List<dynamic>>(_basePath);
|
|
final data = response.data ?? [];
|
|
|
|
return data
|
|
.map((json) => QuickLinkModel.fromJson(json as Map<String, dynamic>))
|
|
.map((model) => model.toEntity())
|
|
.toList();
|
|
}
|
|
|
|
/// Gets a single quick link by ID.
|
|
Future<QuickLink> getQuickLink(String id) async {
|
|
final response = await _dio.get<Map<String, dynamic>>('$_basePath/$id');
|
|
final data = response.data;
|
|
|
|
if (data == null) {
|
|
throw Exception('Quick link not found: $id');
|
|
}
|
|
|
|
return QuickLinkModel.fromJson(data).toEntity();
|
|
}
|
|
|
|
/// Creates a new quick link.
|
|
Future<QuickLink> createQuickLink(QuickLink link) async {
|
|
final model = QuickLinkModel.fromEntity(link);
|
|
final response = await _dio.post<Map<String, dynamic>>(
|
|
_basePath,
|
|
data: model.toJson(),
|
|
);
|
|
final data = response.data;
|
|
|
|
if (data == null) {
|
|
throw Exception('Failed to create quick link');
|
|
}
|
|
|
|
return QuickLinkModel.fromJson(data).toEntity();
|
|
}
|
|
|
|
/// Updates an existing quick link.
|
|
Future<QuickLink> updateQuickLink(QuickLink link) async {
|
|
final model = QuickLinkModel.fromEntity(link);
|
|
final response = await _dio.put<Map<String, dynamic>>(
|
|
'$_basePath/${link.id}',
|
|
data: model.toJson(),
|
|
);
|
|
final data = response.data;
|
|
|
|
if (data == null) {
|
|
throw Exception('Failed to update quick link');
|
|
}
|
|
|
|
return QuickLinkModel.fromJson(data).toEntity();
|
|
}
|
|
|
|
/// Deletes a quick link.
|
|
Future<void> deleteQuickLink(String id) async {
|
|
await _dio.delete<void>('$_basePath/$id');
|
|
}
|
|
|
|
/// Reorders quick links by updating sort orders.
|
|
Future<void> reorderQuickLinks(List<String> orderedIds) async {
|
|
await _dio.put<void>(
|
|
'$_basePath/reorder',
|
|
data: {'ids': orderedIds},
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Provides the quick links datasource.
|
|
@riverpod
|
|
QuickLinksDatasource quickLinksDatasource(Ref ref) {
|
|
final dio = ref.watch(coreApiClientProvider);
|
|
return QuickLinksDatasource(dio);
|
|
}
|