Skip to content

Commit

Permalink
TW-1780: Open screen can connect with Twake Workplace when add anothe…
Browse files Browse the repository at this point in the history
…r account
  • Loading branch information
nqhhdev committed May 21, 2024
1 parent 4eb4c09 commit 98e78f0
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 17 deletions.
13 changes: 3 additions & 10 deletions lib/config/go_routes/go_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,9 @@ abstract class AppRoutes {
redirect: loggedOutRedirect,
pageBuilder: (context, state) => defaultPageBuilder(
context,
const HomeserverPicker(),
TwakeWelcome(
arg: state.extra as TwakeWelcomeArg?,
),
),
routes: [
GoRoute(
Expand All @@ -386,21 +388,12 @@ abstract class AppRoutes {
),
redirect: loggedOutRedirect,
),
GoRoute(
path: 'twakeWelcome',
pageBuilder: (context, state) => defaultPageBuilder(
context,
const TwakeWelcome(),
),
redirect: loggedInRedirect,
),
GoRoute(
path: 'homeserverpicker',
pageBuilder: (context, state) => defaultPageBuilder(
context,
const HomeserverPicker(),
),
redirect: loggedInRedirect,
),
],
),
Expand Down
38 changes: 34 additions & 4 deletions lib/pages/twake_welcome/twake_welcome.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ import 'package:fluffychat/config/app_config.dart';
import 'package:equatable/equatable.dart';
import 'package:fluffychat/presentation/mixins/connect_page_mixin.dart';
import 'package:fluffychat/pages/twake_welcome/twake_welcome_view.dart';
import 'package:fluffychat/utils/client_manager.dart';
import 'package:fluffychat/utils/twake_snackbar.dart';
import 'package:fluffychat/widgets/matrix.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:flutter_web_auth_2/flutter_web_auth_2.dart';
import 'package:go_router/go_router.dart';
import 'package:matrix/matrix.dart';
Expand Down Expand Up @@ -38,7 +41,7 @@ class TwakeWelcome extends StatefulWidget {
class TwakeWelcomeController extends State<TwakeWelcome> with ConnectPageMixin {
void goToHomeserverPicker() {
if (widget.arg?.isAddAnotherAccount == true) {
context.push('/rooms/addhomeserver');
context.push('/rooms/addaccount/homeserverpicker');
} else {
context.push('/home/homeserverpicker');
}
Expand All @@ -58,8 +61,10 @@ class TwakeWelcomeController extends State<TwakeWelcome> with ConnectPageMixin {

MatrixState get matrix => Matrix.of(context);

void onClickSignIn() {
void onClickSignIn() async {
Logs().d("TwakeIdController::onClickSignIn: Login Url - $loginUrl");
final homeserverExisted = await _homeserverExisted();
if (homeserverExisted) return;
_redirectRegistrationUrl(loginUrl);
}

Expand All @@ -79,15 +84,40 @@ class TwakeWelcomeController extends State<TwakeWelcome> with ConnectPageMixin {
handleTokenFromRegistrationSite(matrix: matrix, uri: uri);
}

void onClickCreateTwakeId() {
void onClickCreateTwakeId() async {
Logs().d(
"TwakeIdController::onClickCreateTwakeId: Signup Url - $signupUrl",
);
final homeserverExisted = await _homeserverExisted();
if (homeserverExisted) return;
_redirectRegistrationUrl(signupUrl);
}

Future<bool> _homeserverExisted() async {
if (widget.arg?.isAddAnotherAccount == false) return false;
final allHomeserverLoggedIn = (await ClientManager.getClients())
.map((client) => client.homeserver.toString())
.toList();
Logs().i('All homeservers: $allHomeserverLoggedIn');
final homeserverExists = allHomeserverLoggedIn.any(
(homeserver) => "$homeserver/".contains(AppConfig.homeserver),
);

if (homeserverExists &&
!AppConfig.supportMultipleAccountsInTheSameHomeserver) {
TwakeSnackBar.show(
context,
L10n.of(context)!.isSingleAccountOnHomeserver,
);
return true;
}
return false;
}

@override
Widget build(BuildContext context) {
return TwakeWelcomeView(controller: this);
return TwakeWelcomeView(
controller: this,
);
}
}
13 changes: 13 additions & 0 deletions lib/pages/twake_welcome/twake_welcome_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/pages/twake_welcome/twake_welcome.dart';
import 'package:fluffychat/pages/twake_welcome/twake_welcome_view_style.dart';
import 'package:fluffychat/resource/image_paths.dart';
import 'package:fluffychat/widgets/twake_components/twake_icon_button.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:go_router/go_router.dart';
import 'package:linagora_design_flutter/linagora_design_flutter.dart';

class TwakeWelcomeView extends StatelessWidget {
Expand All @@ -15,6 +17,17 @@ class TwakeWelcomeView extends StatelessWidget {
@override
Widget build(BuildContext context) {
return TwakeWelcomeScreen(
appBar: controller.widget.arg?.isAddAnotherAccount == true
? AppBar(
backgroundColor: Colors.transparent,
leading: TwakeIconButton(
icon: Icons.arrow_back,
onTap: () => context.pop(),
tooltip: L10n.of(context)!.back,
),
elevation: 0,
)
: null,
focusColor: Colors.transparent,
hoverColor: Colors.transparent,
highlightColor: Colors.transparent,
Expand Down
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1533,8 +1533,8 @@ packages:
dependency: "direct main"
description:
path: "."
ref: master
resolved-ref: "7ed486ea00f7e91254555a4a828ff3a625b4e1ae"
ref: add-app-bar-for-twake-welcome
resolved-ref: "495ca81748fdf90faf426c0ed11a922b7d1ca60b"
url: "[email protected]:linagora/linagora-design-flutter.git"
source: git
version: "0.0.1"
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies:
linagora_design_flutter:
git:
url: [email protected]:linagora/linagora-design-flutter.git
ref: master
ref: add-app-bar-for-twake-welcome
flutter_matrix_html:
git:
url: https://github.com/linagora/flutter_matrix_html.git
Expand Down

0 comments on commit 98e78f0

Please sign in to comment.