Skip to content

Commit

Permalink
Merge pull request #56 from UwUClub/Fix-front-notifiers
Browse files Browse the repository at this point in the history
Fix front notifiers
  • Loading branch information
GlassAlo authored Jan 14, 2024
2 parents 2f44ff0 + 7b9f0fb commit c415c7f
Show file tree
Hide file tree
Showing 11 changed files with 176 additions and 129 deletions.
12 changes: 7 additions & 5 deletions flutter_area/lib/Core/Manager/action_reaction_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;

import '../../UI/NewTask/new_task_viewmodel.dart';
import '../../Utils/constants.dart';
import '../../Utils/mk_print.dart';
import '../Locator/locator.dart';
Expand Down Expand Up @@ -133,6 +134,7 @@ class MkReaction {

class ActionReactionManager extends ChangeNotifier {
List<MkActionReaction> actionsReactions = <MkActionReaction>[];
NewTaskViewModel? newTaskViewModel;

Future<void> getActionsReactions() async {
try {
Expand Down Expand Up @@ -177,7 +179,7 @@ class ActionReactionManager extends ChangeNotifier {
name: name,
action: MkAction(type: type),
));
notifyListeners();
newTaskViewModel?.notify();
}

Future<bool> addAction(ActionType actionType, String name,
Expand Down Expand Up @@ -214,7 +216,7 @@ class ActionReactionManager extends ChangeNotifier {
actionsReactions[localIndex].id = id;
actionsReactions[localIndex].name = name;
actionsReactions[localIndex].action = MkAction(type: actionType);
notifyListeners();
newTaskViewModel?.notify();
return true;
} catch (e) {
mkPrint('Error: $e');
Expand All @@ -239,7 +241,7 @@ class ActionReactionManager extends ChangeNotifier {
final int index = actionsReactions.indexWhere(
(MkActionReaction element) => element.id == actionReactionId);
actionsReactions[index].reaction = MkReaction(type: type);
notifyListeners();
newTaskViewModel?.notify();
return true;
} catch (e) {
mkPrint('Error: $e');
Expand All @@ -251,7 +253,7 @@ class ActionReactionManager extends ChangeNotifier {
final int index = actionsReactions.indexWhere(
(MkActionReaction element) => element.id == actionReactionId);
actionsReactions[index].reaction = null;
notifyListeners();
newTaskViewModel?.notify();
}

Future<void> deleteActionReaction(String actionReactionId) async {
Expand All @@ -268,7 +270,7 @@ class ActionReactionManager extends ChangeNotifier {
}
actionsReactions.removeWhere(
(MkActionReaction element) => element.id == actionReactionId);
notifyListeners();
newTaskViewModel?.notify();
} catch (e) {
mkPrint('Error: $e');
}
Expand Down
2 changes: 1 addition & 1 deletion flutter_area/lib/Core/Manager/github_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class GithubManager {
body: jsonEncode(<String, String>{'githubToken': 'none'}));
if (response.statusCode == 201) {
userManager.isGithubLogged = false;
userManager.notify();
userManager.connectionsViewModel?.notify();
}
}
}
2 changes: 1 addition & 1 deletion flutter_area/lib/Core/Manager/google_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class GoogleManager {
final UserManager userManager = locator<UserManager>();
userManager.storeUser(jsonBody['user'] as Map<String, dynamic>);
userManager.storeAccessToken(jsonBody['accessToken'] as String);
userManager.notify();
userManager.connectionsViewModel?.notify();
return true;
}
return false;
Expand Down
9 changes: 3 additions & 6 deletions flutter_area/lib/Core/Manager/user_manager.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:shared_preferences/shared_preferences.dart';

import '../../UI/Connections/connections_viewmodel.dart';
import '../../Utils/constants.dart';
import '../../Utils/mk_print.dart';

class UserManager extends ChangeNotifier {
class UserManager {
String? username;
String? fullName;
String? email;
String? accessToken;
bool? isGoogleLogged;
bool? isGithubLogged;
ConnectionsViewModel? connectionsViewModel;

AuthStateEnum state = AuthStateEnum.splash;

Expand Down Expand Up @@ -140,10 +141,6 @@ class UserManager extends ChangeNotifier {
}
return null;
}

void notify() {
notifyListeners();
}
}

enum AuthStateEnum { authenticated, unauthenticated, splash }
2 changes: 1 addition & 1 deletion flutter_area/lib/UI/Callback/callback_github.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class CallbackGithubViewState extends State<CallbackGithubView> {
body: jsonEncode(<String, String>{'githubToken': token!}));
if (response.statusCode == 201) {
userManager.isGithubLogged = true;
userManager.notify();
userManager.connectionsViewModel?.notify();
mkPrint('Github token saved');
} else {
mkPrint('Échec de la requête : ${response.statusCode}');
Expand Down
206 changes: 112 additions & 94 deletions flutter_area/lib/UI/Connections/connections_mobile_view.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:provider/provider.dart';

import '../../Core/Locator/locator.dart';
import '../../Core/Manager/github_manager.dart';
import '../../Core/Manager/slack_manager.dart';
import '../../Core/Manager/theme_manager.dart';
import '../../Core/Manager/user_manager.dart';
import '../../Utils/Extensions/double_extensions.dart';
import '../ReusableWidgets/mk_background.dart';
import '../ReusableWidgets/mk_button.dart';
import '../ReusableWidgets/mk_input.dart';
import 'connections_viewmodel.dart';

class ConnectionsMobileView extends StatefulWidget {
const ConnectionsMobileView({super.key});
Expand All @@ -22,107 +25,122 @@ class _ConnectionsMobileStateView extends State<ConnectionsMobileView> {
ThemeManager themeManager = locator<ThemeManager>();
SlackManager slackManager = locator<SlackManager>();
GithubManager githubManager = locator<GithubManager>();
UserManager userManager = locator<UserManager>();

String slackBotTokenInput = '';

@override
Widget build(BuildContext context) {
return SafeArea(
child: MkBackground(
child: Padding(
padding: EdgeInsets.only(
top: 45.0.ratioH(),
left: 37.0.ratioW(),
right: 37.0.ratioW(),
bottom: 36.0.ratioH()),
child: Column(
children: <Widget>[
Row(children: <Widget>[
Text(AppLocalizations.of(context)!.connection,
style: Theme.of(context).textTheme.titleMedium)
]),
const Divider(
endIndent: 0,
indent: 0,
),
Row(children: <Widget>[
const Icon(FontAwesomeIcons.github, size: 20),
Text(AppLocalizations.of(context)!.github,
style: Theme.of(context).textTheme.labelLarge)
]),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Flexible(
child: Text(AppLocalizations.of(context)!.connectGithub,
style: Theme.of(context).textTheme.labelMedium),
)
],
),
MkButton(
label: AppLocalizations.of(context)!.connect,
onPressed: () async {
await githubManager.signInWithGitHub();
},
),
const Divider(
endIndent: 0,
indent: 0,
),
Row(children: <Widget>[
const Icon(FontAwesomeIcons.google, size: 20),
Text(AppLocalizations.of(context)!.google,
style: Theme.of(context).textTheme.labelLarge)
]),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Flexible(
child: Text(AppLocalizations.of(context)!.connectGoogle,
style: Theme.of(context).textTheme.labelMedium),
),
],
),
MkButton(
label: AppLocalizations.of(context)!.connect,
onPressed: () {},
),
const Divider(
endIndent: 0,
indent: 0,
),
Row(children: <Widget>[
const Icon(FontAwesomeIcons.slack, size: 20),
Text(AppLocalizations.of(context)!.slack,
style: Theme.of(context).textTheme.labelLarge)
]),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Flexible(
child: Text(AppLocalizations.of(context)!.connectSlack,
style: Theme.of(context).textTheme.labelMedium),
return ChangeNotifierProvider(
create: (BuildContext context) => ConnectionsViewModel(),
builder: (BuildContext context, Widget? child) {
return Consumer<ConnectionsViewModel>(
builder:
(BuildContext context, ConnectionsViewModel vm, Widget? child) {
userManager.connectionsViewModel = vm;
return SafeArea(
child: MkBackground(
child: Padding(
padding: EdgeInsets.only(
top: 45.0.ratioH(),
left: 37.0.ratioW(),
right: 37.0.ratioW(),
bottom: 36.0.ratioH()),
child: Column(
children: <Widget>[
Row(children: <Widget>[
Text(AppLocalizations.of(context)!.connection,
style: Theme.of(context).textTheme.titleMedium)
]),
const Divider(
endIndent: 0,
indent: 0,
),
Row(children: <Widget>[
const Icon(FontAwesomeIcons.github, size: 20),
Text(AppLocalizations.of(context)!.github,
style: Theme.of(context).textTheme.labelLarge)
]),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Flexible(
child: Text(
AppLocalizations.of(context)!.connectGithub,
style: Theme.of(context).textTheme.labelMedium),
)
],
),
MkButton(
label: AppLocalizations.of(context)!.connect,
onPressed: () async {
await githubManager.signInWithGitHub();
},
),
const Divider(
endIndent: 0,
indent: 0,
),
Row(children: <Widget>[
const Icon(FontAwesomeIcons.google, size: 20),
Text(AppLocalizations.of(context)!.google,
style: Theme.of(context).textTheme.labelLarge)
]),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Flexible(
child: Text(
AppLocalizations.of(context)!.connectGoogle,
style: Theme.of(context).textTheme.labelMedium),
),
],
),
MkButton(
label: AppLocalizations.of(context)!.connect,
onPressed: () {},
),
const Divider(
endIndent: 0,
indent: 0,
),
Row(children: <Widget>[
const Icon(FontAwesomeIcons.slack, size: 20),
Text(AppLocalizations.of(context)!.slack,
style: Theme.of(context).textTheme.labelLarge)
]),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Flexible(
child: Text(
AppLocalizations.of(context)!.connectSlack,
style: Theme.of(context).textTheme.labelMedium),
),
],
),
MkInput(
placeholder: 'xxxx-...',
onChanged: (String value) {
setState(() {
slackBotTokenInput = value;
});
},
),
MkButton(
label: AppLocalizations.of(context)!.validate,
onPressed: () {
SlackManager().updateBotToken(slackBotTokenInput);
},
),
],
),
],
),
MkInput(
placeholder: 'xxxx-...',
onChanged: (String value) {
setState(() {
slackBotTokenInput = value;
});
},
),
MkButton(
label: AppLocalizations.of(context)!.validate,
onPressed: () {
SlackManager().updateBotToken(slackBotTokenInput);
},
),
),
],
),
),
),
);
},
);
},
);
}
}
Loading

0 comments on commit c415c7f

Please sign in to comment.