Skip to content
This repository has been archived by the owner on May 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #36 from pvdthings/release/1.0-beta-8
Browse files Browse the repository at this point in the history
Release 1.0 Beta 8
  • Loading branch information
dillonfagan authored Jul 29, 2023
2 parents 90245c0 + b492c0d commit 017ccf3
Show file tree
Hide file tree
Showing 91 changed files with 1,639 additions and 1,303 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ Without a `SUPABASE_URL`, attempting signin will result in a 404 error.

## Project Structure

The app is broken down into features or modules, each containing directories for `data`, `widgets`, and `views`.
The app is broken down into features or modules, each containing directories for `data`, `widgets`, and `pages`.

- `data` contains Models, ViewModels, Repostories, or any other business logic.
- `widgets` contains UI components that have no knowledge of the ViewModel.
- `views` contains UI components that _do_ have knowledge of the ViewModel. Pages are the most common, but there may be smaller views that compose a page.
- `widgets` contains UI components that compose larger widgets or pages.
- `pages` contains UI components that represent pages. Generally wrapped in a `Scaffold` widget.

## Background

Expand Down
15 changes: 5 additions & 10 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import 'package:flutter/material.dart';
import 'package:librarian_app/constants.dart';
import 'package:librarian_app/src/features/borrowers/data/borrowers_view_model.dart';
import 'package:librarian_app/src/features/inventory/data/inventory_view_model.dart';
import 'package:librarian_app/src/features/loans/data/loans_view_model.dart';
import 'package:librarian_app/src/features/authentication/data/user_view_model.dart';
import 'package:librarian_app/src/features/splash/views/splash_page.dart';
import 'package:librarian_app/src/features/borrowers/data/borrowers.vm.dart';
import 'package:librarian_app/src/features/inventory/data/inventory.vm.dart';
import 'package:librarian_app/src/features/loans/data/loans.vm.dart';
import 'package:librarian_app/src/features/authentication/data/user.vm.dart';
import 'package:librarian_app/src/features/splash/pages/splash.page.dart';
import 'package:provider/provider.dart';
import 'package:supabase_flutter/supabase_flutter.dart' as supabase;

import 'src/features/loans/data/things_view_model.dart';

Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();

Expand All @@ -29,9 +27,6 @@ Future<void> main() async {
ChangeNotifierProvider<BorrowersViewModel>(
create: (context) => BorrowersViewModel(),
),
ChangeNotifierProvider<ThingsViewModel>(
create: (context) => ThingsViewModel(),
),
ChangeNotifierProvider<InventoryViewModel>(
create: (context) => InventoryViewModel(),
),
Expand Down
15 changes: 15 additions & 0 deletions lib/src/features/authentication/data/user.model.dart
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);
}
}
21 changes: 21 additions & 0 deletions lib/src/features/authentication/data/user.vm.dart
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();
}
}
24 changes: 0 additions & 24 deletions lib/src/features/authentication/data/user_view_model.dart

This file was deleted.

1 change: 1 addition & 0 deletions lib/src/features/authentication/pages/signin/index.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'signin.page.dart';
69 changes: 69 additions & 0 deletions lib/src/features/authentication/pages/signin/signin.page.dart
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.'),
),
),
],
);
},
),
),
),
);
}
}
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),
),
);
}
}
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();
}
}
83 changes: 0 additions & 83 deletions lib/src/features/authentication/views/signin_page.dart

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:librarian_app/src/features/common/data/lending_api.dart';

import 'borrower_model.dart';
import 'borrower.model.dart';
import 'borrowers_mapper.dart';

class BorrowersViewModel extends ChangeNotifier {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/features/borrowers/data/borrowers_mapper.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'borrower_model.dart';
import 'borrower.model.dart';

class BorrowersMapper {
static Iterable<BorrowerModel> map(Iterable<dynamic> data) {
Expand Down

This file was deleted.

Loading

1 comment on commit 017ccf3

@vercel
Copy link

@vercel vercel bot commented on 017ccf3 Jul 29, 2023

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

Please sign in to comment.