From 4ed46929f86acd5dbf8ef7e84e7f2f4fe88539ea Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Thu, 23 Mar 2023 10:19:14 +0100 Subject: [PATCH] Moved main room screen into room folder --- lib/main.dart | 22 +++++++++------------- lib/screens/{room.dart => room/main.dart} | 21 ++++++++++++++++----- 2 files changed, 25 insertions(+), 18 deletions(-) rename lib/screens/{room.dart => room/main.dart} (90%) diff --git a/lib/main.dart b/lib/main.dart index 19f48ca..0526886 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -2,10 +2,9 @@ import 'package:flutter/material.dart'; import 'package:outbag_app/backend/user.dart'; import 'package:outbag_app/screens/room/join.dart'; import 'package:outbag_app/screens/room/new.dart'; -import 'package:outbag_app/screens/room/shopping_list.dart'; import './screens/home.dart'; import './screens/welcome.dart'; -import './screens/room.dart'; +import './screens/room/main.dart'; import './screens/auth.dart'; import './backend/request.dart'; import 'package:routemaster/routemaster.dart'; @@ -28,8 +27,7 @@ final routesLoggedIn = RouteMap(routes: { final server = info.pathParameters['server'] ?? ""; final tag = info.pathParameters['tag'] ?? ""; - return MaterialPage( - child: RoomPage(server, tag)); + return MaterialPage(child: RoomPage(server, tag)); }, }, onUnknownRoute: (_) => const Redirect('/')); @@ -55,9 +53,9 @@ class _OutbagAppState extends State { void initState() { super.initState(); - // TODO: try to login user, + // try to obtain user account information // with existing details - + // NOTE: also functions as a way to verify ther data (() async { User credentials; try { @@ -71,15 +69,13 @@ class _OutbagAppState extends State { return; } try { - final resp = await postUnauthorized( + final resp = await postWithCreadentials( target: credentials.server, - path: 'signin', - body: { - 'name': credentials.username, - 'server': credentials.server.tag, - 'accountKey': credentials.password - }); + path: 'getMyAccount', + credentials: credentials, + body: {}); if (resp.res == Result.ok) { + print(resp.body); setState(() { isAuthorized = true; }); diff --git a/lib/screens/room.dart b/lib/screens/room/main.dart similarity index 90% rename from lib/screens/room.dart rename to lib/screens/room/main.dart index 09c9379..46079d6 100644 --- a/lib/screens/room.dart +++ b/lib/screens/room/main.dart @@ -27,9 +27,12 @@ class _RoomPageState extends State { // fetch room information void fetchInfo() async { + bool foundData = false; + try { final diskRoom = await Room.fromDisk(serverTag: widget.server, id: widget.tag); + foundData = true; setState(() { room = diskRoom; }); @@ -53,12 +56,23 @@ class _RoomPageState extends State { if (resp.res == Result.ok) { final info = RoomInfo.fromJSON(resp.body['data']); final room = Room.fromJSON(resp.body['data']); + + room.toDisk(); + foundData = true; + setState(() { this.info = info; - this.room = room; }); } } catch (_) {} + + if (!foundData) { + // no room data available + // TODO: close room + // or show snackbar + // BUG: there is currently no way of implementing this, + // because there is no context available here + } } @override @@ -82,10 +96,7 @@ class _RoomPageState extends State { // (if a background listener is implemented at some point, // checking if this room changed might improve performance) try { - final r = await Room.fromDisk( - serverTag: widget.server, - id: widget.tag - ); + final r = await Room.fromDisk(serverTag: widget.server, id: widget.tag); setState(() { room = r; });