Skip to content

Commit b86b8fe

Browse files
author
Vladimir Minkin
committed
Example SPA update - navigation from TRIALS back to MAIN
1 parent f1a3dfb commit b86b8fe

File tree

15 files changed

+218
-1420
lines changed

15 files changed

+218
-1420
lines changed

example/spa/package-lock.json

Lines changed: 129 additions & 1332 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/spa/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ environment:
77
sdk: '>=2.17.5 <3.0.0'
88

99
dependencies:
10-
wire: ^1.5.0
10+
wire: ^1.5.1
1111
states: ^1.1.0
12-
sporran: ^6.1.0
12+
sporran: ^6.2.0
1313
tuple: ^2.0.1
1414

1515
dev_dependencies:
Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,8 @@
1-
<!--<div class="mdc-layout-grid" id="loginPage">-->
2-
<!-- <div class="mdc-layout-grid__inner header">-->
3-
<!-- <h1 class="mdc-typography&#45;&#45;headline4">Login</h1>-->
4-
<!-- </div>-->
5-
<!-- <div class="mdc-layout-grid__inner">-->
6-
<!-- <button id="btnConfirm" class="mdc-button mdc-button&#45;&#45;outlined">-->
7-
<!-- <div class="mdc-button__ripple"></div>-->
8-
<!-- <span class="mdc-button__label">Confirm</span>-->
9-
<!-- </button>-->
10-
<!-- </div>-->
11-
<!--</div>-->
12-
<main class="spectrum-grid" id="loginPage">
13-
<div class="spectrum-Typography">
14-
<h1 class="spectrum-Heading spectrum-Heading--sizeXL">Login Page</h1>
15-
<p class="spectrum-Body spectrum-Body--sizeXL">This is a webpage</p>
1+
<main id="loginPage">
2+
<div>
3+
<h1>Login Page</h1>
4+
<p>This is a webpage</p>
165
</div>
17-
<sp-button size="m" id="btnConfirm">Confirm</sp-button>
6+
<button id="btnConfirm">Confirm</button>
187
</main>
198

example/spa/web/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
</style>
1313
<!-- <link href="https://unpkg.com/material-components-web@latest/dist/material-components-web.min.css" rel="stylesheet">-->
1414
<!-- <script src="https://unpkg.com/material-components-web@latest/dist/material-components-web.min.js"></script>-->
15-
<script src="https://jspm.dev/@spectrum-web-components/bundle/elements.js" type="module"></script>
15+
<!-- <script src="https://jspm.dev/@spectrum-web-components/bundle/elements.js" type="module"></script>-->
1616
</head>
1717

1818
<body>
19-
<sp-theme id="root" color="darkest" scale="large">
19+
<div id="root">
2020
<div id="router"></div>
21-
</sp-theme>
21+
</div>
2222
</body>
2323
<script type="module" src="main.dart.js"></script>
2424
</html>

example/spa/web/main.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import 'dart:html';
22

33
import 'src/constants/dom.dart';
44
import 'src/constants/pages.dart';
5-
import 'src/controller/auth.controller.dart';
6-
import 'src/controller/routes.controller.dart';
5+
import 'src/controller/auth_controller.dart';
6+
import 'src/controller/routes_controller.dart';
77
import 'src/view/application.dart';
88

99
void main() async {

example/spa/web/src/controller/auth.controller.dart

Lines changed: 0 additions & 55 deletions
This file was deleted.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import 'package:states/states.dart';
2+
import 'package:wire/wire.dart';
3+
4+
import '../constants/action.dart';
5+
import '../constants/data.dart';
6+
import '../constants/signals.dart';
7+
import '../states/auth_states.dart';
8+
9+
class AuthController {
10+
AuthController() {
11+
Wire.add<String>(this, Signals.STATES_ACTION__AUTH, (action, wid) async {
12+
final statesAuthWireData = Wire.data(Data.STATES_AUTH);
13+
(statesAuthWireData.value as AuthStates).execute(action!);
14+
});
15+
}
16+
17+
void initialize() {
18+
final authStatesWireData = Wire.data(Data.STATES_AUTH);
19+
if (!authStatesWireData.isSet) {
20+
Wire.data(Data.STATES_AUTH, value: AuthStates()).lock(WireDataLockToken());
21+
}
22+
23+
final authStates = authStatesWireData.value as AuthStates;
24+
authStates.when(
25+
at: AuthStates.USER_LOGGED_OUT,
26+
to: AuthStates.USER_LOGIN_VALIDATE,
27+
on: Action.USER_LOGIN_VALIDATE,
28+
handler: (StatesTransition t) {
29+
print('> AuthController -> authStates: USER_LOGIN_VALIDATE - ${t.toString()}');
30+
});
31+
authStates.when(
32+
at: AuthStates.USER_LOGIN_VALIDATE,
33+
to: AuthStates.USER_LOGGED_IN,
34+
on: Action.USER_LOGIN_COMPLETE,
35+
handler: (StatesTransition t) {
36+
print('> AuthController -> authStates: USER_LOGIN_COMPLETE - ${t.toString()}');
37+
});
38+
authStates.when(
39+
at: AuthStates.USER_LOGIN_VALIDATE,
40+
to: AuthStates.USER_LOGIN_ERROR,
41+
on: Action.USER_LOGIN_ERROR,
42+
handler: (StatesTransition t) {
43+
print('> AuthController -> authStates: USER_LOGIN_ERROR - ${t.toString()}');
44+
});
45+
authStates.when(
46+
at: AuthStates.USER_LOGIN_ERROR,
47+
to: AuthStates.USER_LOGGED_OUT,
48+
on: Action.USER_LOGOUT,
49+
handler: (StatesTransition t) {
50+
print('> AuthController -> authStates: USER_LOGIN_ERROR - ${t.toString()}');
51+
});
52+
authStates.when(
53+
at: AuthStates.USER_LOGGED_IN,
54+
to: AuthStates.USER_LOGGED_OUT,
55+
on: Action.USER_LOGOUT,
56+
handler: (StatesTransition t) {});
57+
}
58+
}

example/spa/web/src/controller/routes.controller.dart renamed to example/spa/web/src/controller/routes_controller.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import 'package:wire/wire.dart';
66
import '../constants/action.dart';
77
import '../constants/data.dart';
88
import '../constants/signals.dart';
9-
import '../states/router.states.dart';
9+
import '../states/router_states.dart';
1010
import '../view/base/page.dart';
1111
import '../view/pages/login.page.dart';
1212
import '../view/pages/main.page.dart';
@@ -55,12 +55,19 @@ class RoutesController {
5555
to: RouterStates.PAGE_TRIALS,
5656
on: Action.NAVIGATE_TO_TRIALS,
5757
handler: (StatesTransition transition) => {navigateFromTo(TrialsPage())});
58+
routerStates.when(
59+
at: RouterStates.PAGE_TRIALS,
60+
to: RouterStates.PAGE_MAIN,
61+
on: Action.NAVIGATE_TO_MAIN,
62+
handler: (StatesTransition transition) => {navigateFromTo(MainPage())});
5863
}
5964

6065
Future<void> navigateFromTo(Page toPage) async {
6166
final hasCurrentPage = _currentPage != null;
6267
if (hasCurrentPage) await _currentPage?.beforeLeave();
6368

69+
print('> RoutesController -> navigateFromTo: ${_currentPage} - ${toPage.path}');
70+
6471
final template = await HttpRequest.getString('${_templatePath}${toPage.path}.html');
6572
// ignore: unsafe_html
6673
toPage.dom.setInnerHtml(template, treeSanitizer: NodeTreeSanitizer.trusted);

example/spa/web/src/controller/user.controller.dart renamed to example/spa/web/src/controller/user_controller.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'package:wire/wire.dart';
22

33
import '../constants/data.dart';
4-
import '../states/user.states.dart';
4+
import '../states/user_states.dart';
55

66
class UserController {
77
UserController();

0 commit comments

Comments
 (0)