Skip to content

Commit

Permalink
feat: swipe navigation (#101)
Browse files Browse the repository at this point in the history
* feat: swipe navigation

* fix: redirect to login widget after succesful register
  • Loading branch information
invertedEcho authored Aug 4, 2024
1 parent 810780b commit bf036f8
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 81 deletions.
2 changes: 1 addition & 1 deletion backend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ async function bootstrap() {
app.enableCors();
await app.listen(3000, '0.0.0.0');
const appUrl = await app.getUrl();
console.log(`WG-App Backend is running on: ${appUrl}`);
console.log(`Flatshare Backend is running on: ${appUrl}`);
}
bootstrap();
108 changes: 57 additions & 51 deletions frontend/lib/authenticated_navigation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class AuthenticatedNavigation extends StatefulWidget {
}

class _AuthenticatedNavigationState extends State<AuthenticatedNavigation> {
final PageController _pageController = PageController(initialPage: 0);
int currentPageIndex = 0;
int? userGroupId;

Expand Down Expand Up @@ -119,59 +120,64 @@ class _AuthenticatedNavigationState extends State<AuthenticatedNavigation> {
});
}
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: userProvider.userGroup?.name != null
? Text(userProvider.userGroup!.name)
: null,
actions: [
PopupMenuButton(itemBuilder: (BuildContext context) {
return [
PopupMenuItem(
onTap: handleLogout,
child: const Row(children: [
Icon(Icons.logout),
SizedBox(
width: 10,
),
Text("Logout"),
])),
PopupMenuItem(
onTap: handleOpenGenerateInviteCode,
child: const Row(
children: [
Icon(Icons.password),
appBar: AppBar(
centerTitle: true,
title: userProvider.userGroup?.name != null
? Text(userProvider.userGroup!.name)
: null,
actions: [
PopupMenuButton(itemBuilder: (BuildContext context) {
return [
PopupMenuItem(
onTap: handleLogout,
child: const Row(children: [
Icon(Icons.logout),
SizedBox(
width: 10,
),
Text("Invite new user to your group")
],
))
];
})
],
),
floatingActionButton: userProvider.userGroup?.id != null
? FloatingActionButton(
backgroundColor: Colors.blueAccent,
foregroundColor: Colors.white,
onPressed: () => Navigator.of(context).push(
MaterialPageRoute(builder: (context) => const CreateTask())),
child: Icon(Icons.add),
)
: null,
bottomNavigationBar: NavigationBar(
onDestinationSelected: (int index) {
setState(() {
currentPageIndex = index;
});
},
indicatorColor: Colors.blueAccent,
selectedIndex: currentPageIndex,
destinations: getNavigationDestinations(userGroupId),
),
body:
getWidgets(userGroupId, widget.userGroupInviteCode)[currentPageIndex],
);
Text("Logout"),
])),
PopupMenuItem(
onTap: handleOpenGenerateInviteCode,
child: const Row(
children: [
Icon(Icons.password),
SizedBox(
width: 10,
),
Text("Invite new user to your group")
],
))
];
})
],
),
floatingActionButton: userProvider.userGroup?.id != null
? FloatingActionButton(
backgroundColor: Colors.blueAccent,
foregroundColor: Colors.white,
onPressed: () => Navigator.of(context).push(MaterialPageRoute(
builder: (context) => const CreateTask())),
child: Icon(Icons.add),
)
: null,
bottomNavigationBar: NavigationBar(
onDestinationSelected: (int index) {
_pageController.animateToPage(index,
duration: const Duration(milliseconds: 150),
curve: Curves.linear);
},
indicatorColor: Colors.blueAccent,
selectedIndex: currentPageIndex,
destinations: getNavigationDestinations(userGroupId),
),
body: PageView(
controller: _pageController,
onPageChanged: (int index) {
setState(() {
currentPageIndex = index;
});
},
children: getWidgets(userGroupId, widget.userGroupInviteCode)));
}
}
2 changes: 1 addition & 1 deletion frontend/lib/fetch/auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Future<String> login(String email, String password) async {
case 401:
throw Exception("Incorrect credentials");
default:
throw Exception("Failed to login");
throw Exception("Failed to login: ${response.statusCode}");
}
}

Expand Down
64 changes: 36 additions & 28 deletions frontend/lib/unauthenticated_navigation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,49 @@ class UnauthenticatedNavigation extends StatefulWidget {
}

class _UnauthenticatedNavigationState extends State<UnauthenticatedNavigation> {
final PageController _pageController = PageController(initialPage: 0);
int currentPageIndex = 0;

@override
Widget build(BuildContext context) {
return Scaffold(
bottomNavigationBar: NavigationBar(
onDestinationSelected: (int index) {
setState(() {
currentPageIndex = index;
});
},
indicatorColor: Colors.blueAccent,
selectedIndex: currentPageIndex,
destinations: const <Widget>[
NavigationDestination(
icon: Icon(Icons.app_registration),
label: 'Register',
),
NavigationDestination(
icon: Icon(Icons.login),
label: 'Login',
),
],
),
body: <Widget>[
RegisterForm(
onRegister: () {
bottomNavigationBar: NavigationBar(
onDestinationSelected: (int index) {
_pageController.animateToPage(index,
duration: const Duration(milliseconds: 150),
curve: Curves.linear);
},
indicatorColor: Colors.blueAccent,
selectedIndex: currentPageIndex,
destinations: const <Widget>[
NavigationDestination(
icon: Icon(Icons.app_registration),
label: 'Register',
),
NavigationDestination(
icon: Icon(Icons.login),
label: 'Login',
),
],
),
body: PageView(
controller: _pageController,
onPageChanged: (int index) {
setState(() {
currentPageIndex = 1;
currentPageIndex = index;
});
},
maybeInviteCode: widget.maybeInviteCode,
),
const LoginForm(),
][currentPageIndex],
);
children: [
RegisterForm(
onRegister: () {
_pageController.animateToPage(1,
duration: const Duration(milliseconds: 150),
curve: Curves.linear);
},
maybeInviteCode: widget.maybeInviteCode,
),
const LoginForm(),
],
));
}
}

0 comments on commit bf036f8

Please sign in to comment.