Repository navigation
feat: projects list #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
| import 'package:gitlab_api/gitlab_api.dart'; | ||
|
|
||
| import 'auth_controller.dart'; | ||
| import 'auth_providers.dart'; | ||
|
|
||
| /// A GitLabClient bound to the signed-in account, or null when signed out. | ||
| /// | ||
| /// Rebuilds when the account changes, so switching or signing out replaces the | ||
| /// client rather than mutating one in flight — a request cannot end up | ||
| /// authenticated as a previous account. | ||
| final gitLabClientProvider = FutureProvider<GitLabClient?>((ref) async { | ||
| final account = ref.watch(currentAccountProvider); | ||
| if (account == null) { | ||
| return null; | ||
| } | ||
| final token = await ref.watch(authRepositoryProvider).tokenFor(account); | ||
| if (token == null) { | ||
| return null; | ||
| } | ||
| final client = GitLabClient(baseUrl: account.instanceUrl, token: token); | ||
| ref.onDispose(client.close); | ||
| return client; | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
apps/labfox/lib/features/projects/data/projects_repository.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import 'package:gitlab_api/gitlab_api.dart'; | ||
| import 'package:gitlab_models/gitlab_models.dart'; | ||
|
|
||
| /// Loads projects for the signed-in account. | ||
| /// | ||
| /// A thin wrapper over the client for this slice: it exists so the controller | ||
| /// never builds a client or knows about pagination headers. Caching (Drift) | ||
| /// lands with the offline work later. | ||
| class ProjectsRepository { | ||
| ProjectsRepository(this._client); | ||
|
|
||
| final GitLabClient _client; | ||
|
|
||
| Future<List<Project>> list() async { | ||
| final page = await _client.projects.list(); | ||
| return page.items; | ||
| } | ||
| } |
41 changes: 41 additions & 0 deletions
41
apps/labfox/lib/features/projects/presentation/controllers/projects_controller.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
| import 'package:gitlab_models/gitlab_models.dart'; | ||
|
|
||
| import '../../../../core/auth/gitlab_client_provider.dart'; | ||
| import '../../data/projects_repository.dart'; | ||
|
|
||
| final projectsRepositoryProvider = FutureProvider<ProjectsRepository?>(( | ||
| ref, | ||
| ) async { | ||
| final client = await ref.watch(gitLabClientProvider.future); | ||
| return client == null ? null : ProjectsRepository(client); | ||
| }); | ||
|
|
||
| /// Loads the signed-in account's projects. | ||
| class ProjectsController extends AsyncNotifier<List<Project>> { | ||
| @override | ||
| Future<List<Project>> build() async { | ||
| final repository = await ref.watch(projectsRepositoryProvider.future); | ||
| if (repository == null) { | ||
| // Signed out: no projects to show. The router keeps this screen behind | ||
| // authentication, so this is a defensive empty rather than an expected | ||
| // state. | ||
| return const []; | ||
| } | ||
| return repository.list(); | ||
| } | ||
|
|
||
| /// Re-fetches, surfacing loading to the UI for pull-to-refresh. | ||
| Future<void> refresh() async { | ||
| state = const AsyncLoading(); | ||
| state = await AsyncValue.guard(() async { | ||
| final repository = await ref.read(projectsRepositoryProvider.future); | ||
| return repository == null ? <Project>[] : repository.list(); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| final projectsControllerProvider = | ||
| AsyncNotifierProvider<ProjectsController, List<Project>>( | ||
| ProjectsController.new, | ||
| ); |
83 changes: 83 additions & 0 deletions
83
apps/labfox/lib/features/projects/presentation/projects_screen.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| import 'package:design_system/design_system.dart'; | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
| import 'package:gitlab_models/gitlab_models.dart'; | ||
|
|
||
| import '../../../l10n/app_localizations.dart'; | ||
| import 'controllers/projects_controller.dart'; | ||
|
|
||
| /// The signed-in account's projects. | ||
| class ProjectsScreen extends ConsumerWidget { | ||
| const ProjectsScreen({super.key}); | ||
|
|
||
| @override | ||
| Widget build(BuildContext context, WidgetRef ref) { | ||
| final l10n = AppLocalizations.of(context); | ||
| final projects = ref.watch(projectsControllerProvider); | ||
|
|
||
| return Scaffold( | ||
| appBar: AppBar(title: Text(l10n.projectsTitle)), | ||
| body: projects.when( | ||
| loading: () => const Center(child: CircularProgressIndicator()), | ||
| error: (error, _) => _ProjectsError( | ||
| message: l10n.projectsError, | ||
| onRetry: () => | ||
| ref.read(projectsControllerProvider.notifier).refresh(), | ||
| ), | ||
| data: (items) { | ||
| if (items.isEmpty) { | ||
| return Center( | ||
| child: Padding( | ||
| padding: const EdgeInsets.all(LabFoxSpacing.lg), | ||
| child: Text(l10n.projectsEmpty, textAlign: TextAlign.center), | ||
| ), | ||
| ); | ||
| } | ||
| return RefreshIndicator( | ||
| onRefresh: () => | ||
| ref.read(projectsControllerProvider.notifier).refresh(), | ||
| child: ListView.separated( | ||
| itemCount: items.length, | ||
| separatorBuilder: (context, index) => const Divider(height: 1), | ||
| itemBuilder: (context, index) => _tile(items[index]), | ||
| ), | ||
| ); | ||
| }, | ||
| ), | ||
|
sjungwon03 marked this conversation as resolved.
Resolved
|
||
| ); | ||
| } | ||
|
|
||
| Widget _tile(Project project) { | ||
| return ProjectTile( | ||
| name: project.name, | ||
| path: project.pathWithNamespace, | ||
| description: project.description, | ||
| starCount: project.starCount, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| class _ProjectsError extends StatelessWidget { | ||
| const _ProjectsError({required this.message, required this.onRetry}); | ||
|
|
||
| final String message; | ||
| final VoidCallback onRetry; | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| final l10n = AppLocalizations.of(context); | ||
| return Center( | ||
| child: Padding( | ||
| padding: const EdgeInsets.all(LabFoxSpacing.lg), | ||
| child: Column( | ||
| mainAxisSize: MainAxisSize.min, | ||
| children: [ | ||
| Text(message, textAlign: TextAlign.center), | ||
| const SizedBox(height: LabFoxSpacing.md), | ||
| FilledButton(onPressed: onRetry, child: Text(l10n.retry)), | ||
| ], | ||
| ), | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.