Skip to content

Commit

Permalink
honey, i forgot to add the signout button
Browse files Browse the repository at this point in the history
  • Loading branch information
anima-regem committed Nov 10, 2024
1 parent a5ffbb2 commit 83fb9cd
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 8 deletions.
3 changes: 2 additions & 1 deletion lib/screens/auth_screen.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// lib/screens/auth_screen.dart
import 'package:flutter/material.dart';
import 'package:hugeicons/hugeicons.dart';
import '../services/auth_service.dart';

class AuthScreen extends StatefulWidget {
Expand Down Expand Up @@ -64,7 +65,7 @@ class _AuthScreenState extends State<AuthScreen> {

// Google Sign In Button
OutlinedButton.icon(
icon: Icon(Icons.g_mobiledata),
icon: Icon(HugeIcons.strokeRoundedGoogle),
label: _isLoading
? SizedBox(
height: 20,
Expand Down
58 changes: 51 additions & 7 deletions lib/screens/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import 'package:flutter/services.dart';
enum LinkSection {
all,
important,
archive;
archive,
signout;

String get title {
switch (this) {
Expand All @@ -23,6 +24,8 @@ enum LinkSection {
return 'Important';
case LinkSection.archive:
return 'Archive';
case LinkSection.signout:
return 'Sign Out';
}
}

Expand All @@ -34,6 +37,8 @@ enum LinkSection {
return Icons.star;
case LinkSection.archive:
return Icons.archive;
case LinkSection.signout:
return Icons.logout;
}
}
}
Expand All @@ -47,7 +52,6 @@ class _HomeScreenState extends State<HomeScreen> {
final AuthService _authService = AuthService();
LinkSection _currentSection = LinkSection.all;
final DatabaseService _dbService = DatabaseService();

final TextEditingController _linkController = TextEditingController();
bool _isImportant = false;

Expand All @@ -60,6 +64,10 @@ class _HomeScreenState extends State<HomeScreen> {
}
}

Future<void> _signOut() async {
await _authService.signOut();
}

Future<void> _showMetadataDialog(BuildContext context, LinkItem link) async {
showDialog(
context: context,
Expand Down Expand Up @@ -498,6 +506,7 @@ class _HomeScreenState extends State<HomeScreen> {
allLinks.where((link) => link.isPermanent).toList(),
LinkSection.archive =>
allLinks.where((link) => link.isArchived).toList(),
LinkSection.signout => [],
};

return Column(
Expand Down Expand Up @@ -975,11 +984,46 @@ class _HomeScreenState extends State<HomeScreen> {
),
),
bottomNavigationBar: NavigationBar(
selectedIndex: LinkSection.values.indexOf(_currentSection),
onDestinationSelected: (index) {
setState(() {
_currentSection = LinkSection.values[index];
});
selectedIndex: _currentSection == LinkSection.signout
? LinkSection.values
.indexOf(LinkSection.all) // Always show 'all' as selected
: LinkSection.values.indexOf(_currentSection),
onDestinationSelected: (index) async {
final selectedSection = LinkSection.values[index];

if (selectedSection == LinkSection.signout) {
// Show confirmation dialog
final bool? confirm = await showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
title: const Text('Sign Out'),
content: const Text('Are you sure you want to sign out?'),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(false),
child: const Text('Cancel'),
),
ElevatedButton(
onPressed: () => Navigator.of(context).pop(true),
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context).primaryColor,
),
child: const Text('Sign Out'),
),
],
),
);

if (confirm == true) {
await _authService.signOut();
// No need to update _currentSection since the auth state change
// will trigger a rebuild showing the sign-in screen
}
} else {
setState(() {
_currentSection = selectedSection;
});
}
},
destinations: LinkSection.values.map((section) {
return NavigationDestination(
Expand Down

0 comments on commit 83fb9cd

Please sign in to comment.