-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ToB] [Frontend] Authentication, unit progress, complete unit, SDK selection #24457
Merged
Merged
Changes from all commits
Commits
Show all changes
73 commits
Select commit
Hold shift + click to select a range
7c23033
Content tree navigation (#23593)
5978d37
AnimatedBuilders instead of StatefulWidgets in unit & group (#23593)
8807c00
fixed _getNodeAncestors (#23593)
8e8d8c9
get sdkId (#23593)
2ab4b3b
addressing comments (#23593)
57800ee
sdkId getter & StatelessExpansionTile (#23593)
28cb6b8
expand & collapse group (#23593)
85e1234
StatelessExpansionTile (#23593)
8dc7719
license (#23593)
e4dee7b
ValueChanged and ValueKey in StatelessExpansionTile (#23593)
5b07e91
optional SDK selector in tour scaffold
497ff7c
AppNotifier
83c9c0e
moved AppNotifier into _initializeState
9d1f49b
StorageKeys
b78bbd3
remove listener
5297d25
auth, complete unit, user progress
d25eaf5
Merge branch 'master' into issue23692_auth
nausharipov 12a685d
unit file fix
3c534d8
Merge remote-tracking branch 'origin/tour-header-sdk-selector' into a…
nausharipov de0f7c3
sdk selection works with auth
3a10e8d
show sdk selector in welcome screen
de273ba
hide back button after navigating from welcome
70c0d61
comments (0)
6f53e30
cache license
4aedd5a
SDK selector with fixed comments
5ad067f
non-nullable onChanged
10b287b
Merge pull request #324 from akvelon/tour-header-sdk-selector
nausharipov a6597d4
untested refinement
2068ce9
deleted show sdk selector
52838e5
notifier objects naming
3df27bc
untested refinement (1)
0b6fc8f
candidate repository
7fbaf38
new configs & todos
64965a1
canCompleteCurrentUnit (#23692)
6d21e1e
kOpenLoginOverlay (#23692)
2c90ced
login_overlay (#23692)
6ed38ac
unused import (#23692)
adbdeb6
deleted file (#23692)
c2f74a5
review comments (2)
a575717
deleted pubspec.lock
8607808
pubspec.lock in gitignore
1bbc092
comment fixes (3)
65dc521
updating & blocking complete unit button (#23692)
d55622e
missing await
c6004b0
no final else
0a76b40
pubspec.lock ignored only in PGC
749d8b1
pubspec.lock
fb1fea1
comment fixes (4)
ef63740
rearranged completeUnit (#23692)
4b2d855
renamed user progress model to unit progress (#23692)
27b26e4
clearUpdatingUnitId (#23692)
b6c4e3e
added async (#23692)
1e38328
removed "fix exception" todo after filing an issue (#23692)
96e41f7
Merge from master
e215ec4
generated files
a107952
renamed user progress cache to unit progress (#23692)
8b639d0
all caches extend cache (#23692)
c8db1ef
refined open overlay (#23692)
869b40c
extracted overlay body (#23692)
9720c13
moved dismissible overlay (#23692)
9e1bbb0
specific imports (#23692)
af936d0
added firebase_options.dart into gradle rat exclusions & added a miss…
d060372
removed padding from user menu (#23692)
a988404
documentation update (#23692)
943391d
Merge branch 'master' into issue23692_auth
dbcf032
Merge branch 'master' into issue23692_auth
d8b5c11
removed goToContextLine
ff8d32b
sdk getter (#23692)
256d7b7
todo: remove sdkId getter and setter (#23692)
6dd0a3b
todo: add unit and integration tests (#23692)
fddeaee
updated readme (#23692)
dc4e142
Merge branch 'master' into issue23692_auth
f33a4c2
addressing comments (#23692)
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import 'dart:async'; | ||
|
||
import 'package:firebase_auth/firebase_auth.dart'; | ||
import 'package:firebase_auth_platform_interface/firebase_auth_platform_interface.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class AuthNotifier extends ChangeNotifier { | ||
AuthNotifier() { | ||
FirebaseAuth.instance.authStateChanges().listen((user) { | ||
notifyListeners(); | ||
}); | ||
} | ||
|
||
bool get isAuthenticated => FirebaseAuth.instance.currentUser != null; | ||
|
||
Future<String?> getToken() async { | ||
return await FirebaseAuth.instance.currentUser?.getIdToken(); | ||
} | ||
|
||
Future<void> logIn(AuthProvider authProvider) async { | ||
await FirebaseAuth.instance.signInWithPopup(authProvider); | ||
} | ||
|
||
Future<void> logOut() async { | ||
await FirebaseAuth.instance.signOut(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,24 +18,19 @@ | |
|
||
import 'dart:async'; | ||
|
||
import 'package:flutter/widgets.dart'; | ||
|
||
import '../models/content_tree.dart'; | ||
import '../repositories/client/client.dart'; | ||
import 'cache.dart'; | ||
|
||
class ContentTreeCache extends ChangeNotifier { | ||
final TobClient client; | ||
class ContentTreeCache extends Cache { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does a ContentTreeCache cache? Would code comments help explain this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added a comment to the |
||
ContentTreeCache({ | ||
required super.client, | ||
}); | ||
|
||
final _treesBySdkId = <String, ContentTreeModel>{}; | ||
final _futuresBySdkId = <String, Future<ContentTreeModel>>{}; | ||
|
||
ContentTreeCache({ | ||
required this.client, | ||
}); | ||
|
||
ContentTreeModel? getContentTree(String sdkId) { | ||
final future = _futuresBySdkId[sdkId]; | ||
if (future == null) { | ||
if (_futuresBySdkId.containsKey(sdkId)) { | ||
unawaited(_loadContentTree(sdkId)); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
learning/tour-of-beam/frontend/lib/cache/unit_progress.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import 'dart:async'; | ||
|
||
import 'package:get_it/get_it.dart'; | ||
|
||
import '../auth/notifier.dart'; | ||
import '../enums/unit_completion.dart'; | ||
import '../repositories/models/get_user_progress_response.dart'; | ||
import '../state.dart'; | ||
import 'cache.dart'; | ||
|
||
class UnitProgressCache extends Cache { | ||
UnitProgressCache({required super.client}); | ||
|
||
final _completedUnitIds = <String>{}; | ||
final _updatingUnitIds = <String>{}; | ||
Future<GetUserProgressResponse?>? _future; | ||
|
||
Set<String> getUpdatingUnitIds() => _updatingUnitIds; | ||
|
||
void addUpdatingUnitId(String unitId) { | ||
_updatingUnitIds.add(unitId); | ||
notifyListeners(); | ||
} | ||
|
||
void clearUpdatingUnitId(String unitId) { | ||
_updatingUnitIds.remove(unitId); | ||
notifyListeners(); | ||
} | ||
|
||
bool canCompleteUnit(String? unitId) { | ||
if (unitId == null) { | ||
return false; | ||
} | ||
return _getUnitCompletion(unitId) == UnitCompletion.uncompleted; | ||
} | ||
|
||
UnitCompletion _getUnitCompletion(String unitId) { | ||
final authNotifier = GetIt.instance.get<AuthNotifier>(); | ||
if (!authNotifier.isAuthenticated) { | ||
return UnitCompletion.unauthenticated; | ||
} | ||
if (_updatingUnitIds.contains(unitId)) { | ||
return UnitCompletion.updating; | ||
} | ||
if (isUnitCompleted(unitId)) { | ||
return UnitCompletion.completed; | ||
} | ||
return UnitCompletion.uncompleted; | ||
} | ||
|
||
bool isUnitCompleted(String? unitId) { | ||
return getCompletedUnits().contains(unitId); | ||
} | ||
|
||
Future<void> updateCompletedUnits() async { | ||
final sdkId = GetIt.instance.get<AppNotifier>().sdkId; | ||
if (sdkId != null) { | ||
await _loadCompletedUnits(sdkId); | ||
} | ||
} | ||
|
||
Set<String> getCompletedUnits() { | ||
if (_future == null) { | ||
unawaited(updateCompletedUnits()); | ||
} | ||
|
||
return _completedUnitIds; | ||
} | ||
|
||
Future<void> _loadCompletedUnits(String sdkId) async { | ||
_future = client.getUserProgress(sdkId); | ||
final result = await _future; | ||
|
||
_completedUnitIds.clear(); | ||
if (result != null) { | ||
for (final unitProgress in result.units) { | ||
if (unitProgress.isCompleted) { | ||
_completedUnitIds.add(unitProgress.id); | ||
} | ||
} | ||
} | ||
|
||
notifyListeners(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert? Looks like it is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alexeyinkin and I have updated README.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the instructions, received the following error:
So ran,
flutter pub get
. FYI I saw a new file to be staged in git:Then followed the original instructions:
flutter pub run build_runner build
and received the error:Steps to reproduce:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added
flutter pub run build_runner build --delete-conflicting-outputs
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've committed a fresh
pubspec.lock
file.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@damondouglas this README is anyway temporary because Gradle tasks are also in the line for the review: