This repository has been archived by the owner on May 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from pvdthings/release/1.0-beta-8
Release 1.0 Beta 8
- Loading branch information
Showing
91 changed files
with
1,639 additions
and
1,303 deletions.
There are no files selected for viewing
This file contains 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 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 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,15 @@ | ||
import 'package:supabase_flutter/supabase_flutter.dart'; | ||
|
||
class UserModel { | ||
final String name; | ||
|
||
const UserModel({required this.name}); | ||
|
||
factory UserModel.from(User? supabaseUser) { | ||
final name = supabaseUser?.userMetadata?['full_name'] ?? | ||
supabaseUser?.email ?? | ||
'Alice'; | ||
|
||
return UserModel(name: name); | ||
} | ||
} |
This file contains 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,21 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:librarian_app/src/features/authentication/data/user.model.dart'; | ||
import 'package:librarian_app/src/features/authentication/services/authentication.service.dart'; | ||
|
||
class UserViewModel extends ChangeNotifier { | ||
final service = AuthenticationService(); | ||
|
||
bool get signedIn => service.hasValidSession; | ||
|
||
UserModel get user => service.currentUser; | ||
|
||
Future<void> signIn() async { | ||
await service.signIn(); | ||
notifyListeners(); | ||
} | ||
|
||
Future<void> signOut() async { | ||
await service.signOut(); | ||
notifyListeners(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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 @@ | ||
export 'signin.page.dart'; |
69 changes: 69 additions & 0 deletions
69
lib/src/features/authentication/pages/signin/signin.page.dart
This file contains 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,69 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:librarian_app/src/features/authentication/data/user.vm.dart'; | ||
import 'package:librarian_app/src/features/authentication/pages/signin/widgets/discord_button.widget.dart'; | ||
import 'package:librarian_app/src/features/dashboard/pages/dashboard.page.dart'; | ||
import 'package:provider/provider.dart'; | ||
|
||
class SignInPage extends StatefulWidget { | ||
const SignInPage({super.key}); | ||
|
||
@override | ||
State<StatefulWidget> createState() { | ||
return _SignInPageState(); | ||
} | ||
} | ||
|
||
class _SignInPageState extends State<SignInPage> { | ||
String? _errorMessage; | ||
|
||
void _navigateToDashboard() { | ||
Navigator.of(context).pushAndRemoveUntil( | ||
MaterialPageRoute(builder: (_) => const DashboardPage()), | ||
(route) => false, | ||
); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
body: Padding( | ||
padding: const EdgeInsets.all(16), | ||
child: Center( | ||
child: Consumer<UserViewModel>( | ||
builder: (context, viewModel, child) { | ||
return Column( | ||
crossAxisAlignment: CrossAxisAlignment.center, | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
Image.asset( | ||
"pvd_things.png", | ||
isAntiAlias: true, | ||
width: 160, | ||
), | ||
const SizedBox(height: 32), | ||
DiscordSigninButton( | ||
signIn: viewModel.signIn, | ||
onSignedIn: _navigateToDashboard, | ||
onError: (error) { | ||
setState(() => _errorMessage = error); | ||
}, | ||
), | ||
if (_errorMessage != null) const SizedBox(height: 16), | ||
if (_errorMessage != null) Text(_errorMessage!), | ||
const SizedBox(height: 32), | ||
const Card( | ||
child: Padding( | ||
padding: EdgeInsets.all(16), | ||
child: Text( | ||
'Only authorized users can sign in.\nPlease ask the PVD Things Digital Team for volunteer access.'), | ||
), | ||
), | ||
], | ||
); | ||
}, | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
lib/src/features/authentication/pages/signin/widgets/discord_button.widget.dart
This file contains 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,43 @@ | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:supabase_flutter/supabase_flutter.dart'; | ||
|
||
class DiscordSigninButton extends StatelessWidget { | ||
final Future<void> Function()? signIn; | ||
final void Function()? onSignedIn; | ||
final void Function(String)? onError; | ||
|
||
const DiscordSigninButton({ | ||
super.key, | ||
this.signIn, | ||
this.onSignedIn, | ||
this.onError, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ElevatedButton.icon( | ||
icon: const Icon(Icons.discord_rounded), | ||
label: const Text('Sign in with Discord'), | ||
onPressed: () async { | ||
if (kDebugMode) { | ||
onSignedIn?.call(); | ||
return; | ||
} | ||
|
||
try { | ||
await signIn?.call(); | ||
onSignedIn?.call(); | ||
} on AuthException catch (error) { | ||
onError?.call(error.toString()); | ||
} catch (error) { | ||
onError?.call("An unexpected error occurred."); | ||
} | ||
}, | ||
style: ElevatedButton.styleFrom( | ||
textStyle: const TextStyle(fontSize: 20), | ||
padding: const EdgeInsets.all(16), | ||
), | ||
); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
lib/src/features/authentication/services/authentication.service.dart
This file contains 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,20 @@ | ||
import 'package:supabase_flutter/supabase_flutter.dart'; | ||
|
||
import '../data/user.model.dart'; | ||
|
||
class AuthenticationService { | ||
static SupabaseClient get _supabase => Supabase.instance.client; | ||
static User? get _currentUser => _supabase.auth.currentUser; | ||
|
||
bool get hasValidSession => _supabase.auth.currentSession != null; | ||
|
||
UserModel get currentUser => UserModel.from(_currentUser); | ||
|
||
Future<void> signIn() async { | ||
await _supabase.auth.signInWithOAuth(Provider.discord); | ||
} | ||
|
||
Future<void> signOut() async { | ||
await _supabase.auth.signOut(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains 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 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
27 changes: 0 additions & 27 deletions
27
lib/src/features/borrowers/views/dashboard/borrowers_desktop_layout.dart
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
017ccf3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
librarian-app – ./
librarian-app-git-main-pvdthings.vercel.app
librarian-app.vercel.app
librarian-app-pvdthings.vercel.app