Skip to content
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

[ToBF] Refinement 26.04.23 #26428

Merged
merged 4 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions learning/tour-of-beam/frontend/lib/models/node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,5 @@ abstract class NodeModel {
}
}

NodeModel getFirstUnit();

NodeModel? getNodeByTreeIds(List<String> treeIds);
}
3 changes: 0 additions & 3 deletions learning/tour-of-beam/frontend/lib/models/parent_node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ abstract class ParentNodeModel extends NodeModel {
required this.nodes,
});

@override
NodeModel getFirstUnit() => nodes[0].getFirstUnit();

@override
NodeModel? getNodeByTreeIds(List<String> treeIds) {
final firstId = treeIds.firstOrNull;
Expand Down
3 changes: 0 additions & 3 deletions learning/tour-of-beam/frontend/lib/models/unit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ class UnitModel extends NodeModel {
title: unit.title,
);

@override
NodeModel getFirstUnit() => this;

@override
NodeModel? getNodeByTreeIds(List<String> treeIds) => this;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ import 'package:get_it/get_it.dart';
import 'package:playground_components/playground_components.dart';

import '../../../cache/content_tree.dart';
import '../../../models/group.dart';

import '../../../models/node.dart';
import '../../../models/parent_node.dart';
import '../../../models/unit.dart';
import '../../../state.dart';

class ContentTreeController extends ChangeNotifier {
Sdk _sdk;
final Sdk initialSdk;
List<String> _treeIds;
NodeModel? _currentNode;
final _contentTreeCache = GetIt.instance.get<ContentTreeCache>();
Expand All @@ -35,29 +37,27 @@ class ContentTreeController extends ChangeNotifier {
Set<String> get expandedIds => _expandedIds;

ContentTreeController({
required Sdk initialSdk,
required this.initialSdk,
List<String> initialTreeIds = const [],
}) : _sdk = initialSdk,
_treeIds = initialTreeIds {
}) : _treeIds = initialTreeIds {
_expandedIds.addAll(initialTreeIds);

_contentTreeCache.addListener(_onContentTreeCacheChange);
_onContentTreeCacheChange();
}

Sdk get sdk => _sdk;

set sdk(Sdk newValue) {
_sdk = newValue;
notifyListeners();
}

Sdk get sdk => GetIt.instance.get<AppNotifier>().sdk ?? initialSdk;
List<String> get treeIds => _treeIds;
NodeModel? get currentNode => _currentNode;

void onNodePressed(NodeModel node) {
if (node is GroupModel) {
_onGroupPressed(node);
_toggleNode(node);
notifyListeners();
}

void _toggleNode(NodeModel node) {
if (node is ParentNodeModel) {
_onParentNodePressed(node);
} else if (node is UnitModel) {
if (node != _currentNode) {
_currentNode = node;
Expand All @@ -67,28 +67,28 @@ class ContentTreeController extends ChangeNotifier {
if (_currentNode != null) {
_treeIds = _getNodeAncestors(_currentNode!, [_currentNode!.id]);
}
notifyListeners();
}

void _onGroupPressed(GroupModel group) {
if (_expandedIds.contains(group.id)) {
_expandedIds.remove(group.id);
void _onParentNodePressed(ParentNodeModel node) {
if (_expandedIds.contains(node.id)) {
_expandedIds.remove(node.id);
notifyListeners();
} else {
_expandedIds.add(group.id);
final groupFirstUnit = group.nodes.first;
if (groupFirstUnit != _currentNode) {
onNodePressed(groupFirstUnit);
_expandedIds.add(node.id);

final firstChildNode = node.nodes.first;
if (firstChildNode != _currentNode) {
_toggleNode(firstChildNode);
}
}
}

void expandGroup(GroupModel group) {
void expandParentNode(ParentNodeModel group) {
_expandedIds.add(group.id);
notifyListeners();
}

void collapseGroup(GroupModel group) {
void collapseParentNode(ParentNodeModel group) {
_expandedIds.remove(group.id);
notifyListeners();
}
Expand All @@ -104,13 +104,13 @@ class ContentTreeController extends ChangeNotifier {
}

void _onContentTreeCacheChange() {
final contentTree = _contentTreeCache.getContentTree(_sdk);
final contentTree = _contentTreeCache.getContentTree(sdk);
if (contentTree == null) {
return;
}

onNodePressed(
contentTree.getNodeByTreeIds(_treeIds) ?? contentTree.getFirstUnit(),
_toggleNode(
contentTree.getNodeByTreeIds(_treeIds) ?? contentTree.modules.first,
);

notifyListeners();
Expand Down
6 changes: 2 additions & 4 deletions learning/tour-of-beam/frontend/lib/pages/tour/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ class TourNotifier extends ChangeNotifier with PageStateMixin<void> {
}

Future<void> _onAppNotifierChanged() async {
contentTreeController.sdk = currentSdk;
playgroundController.setSdk(currentSdk);
_listenToCurrentSnippetEditingController();

Expand All @@ -134,9 +133,8 @@ class TourNotifier extends ChangeNotifier with PageStateMixin<void> {
if (currentNode is! UnitModel) {
await _emptyPlayground();
} else {
final sdk = contentTreeController.sdk;
final content = await _unitContentCache.getUnitContent(
sdk.id,
currentSdk.id,
currentNode.id,
);
_setUnitContent(content);
Expand Down Expand Up @@ -324,7 +322,7 @@ class TourNotifier extends ChangeNotifier with PageStateMixin<void> {
await playgroundController.examplesLoader.loadIfNew(
ExamplesLoadingDescriptor(
descriptors: [
EmptyExampleLoadingDescriptor(sdk: contentTreeController.sdk),
EmptyExampleLoadingDescriptor(sdk: currentSdk),
],
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
*/

import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
import 'package:playground_components/playground_components.dart';

import '../../../components/builders/content_tree.dart';
import '../../../state.dart';
import '../controllers/content_tree.dart';
import 'content_tree_title.dart';
import 'module.dart';
Expand All @@ -36,31 +38,34 @@ class ContentTreeWidget extends StatelessWidget {
Widget build(BuildContext context) {
return SizedBox(
width: 250,
child: ContentTreeBuilder(
sdk: controller.sdk,
builder: (context, contentTree, child) {
if (contentTree == null) {
return Container();
}
child: AnimatedBuilder(
animation: GetIt.instance.get<AppNotifier>(),
builder: (context, child) => ContentTreeBuilder(
sdk: controller.sdk,
builder: (context, contentTree, child) {
if (contentTree == null) {
return Container();
}

return SingleChildScrollView(
padding: const EdgeInsets.symmetric(
horizontal: BeamSizes.size12,
),
child: Column(
children: [
const ContentTreeTitleWidget(),
...contentTree.modules.map(
(module) => ModuleWidget(
module: module,
contentTreeController: controller,
return SingleChildScrollView(
padding: const EdgeInsets.symmetric(
horizontal: BeamSizes.size12,
),
child: Column(
children: [
const ContentTreeTitleWidget(),
...contentTree.modules.map(
(module) => ModuleWidget(
module: module,
contentTreeController: controller,
),
),
),
const SizedBox(height: BeamSizes.size12),
],
),
);
},
const SizedBox(height: BeamSizes.size12),
],
),
);
},
),
),
);
}
Expand Down
38 changes: 10 additions & 28 deletions learning/tour-of-beam/frontend/lib/pages/tour/widgets/group.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ import 'package:flutter/material.dart';

import '../../../models/group.dart';
import '../controllers/content_tree.dart';
import 'group_nodes.dart';
import 'group_title.dart';
import 'stateless_expansion_tile.dart';
import 'parent_node.dart';

class GroupWidget extends StatelessWidget {
final GroupModel group;
Expand All @@ -35,32 +34,15 @@ class GroupWidget extends StatelessWidget {

@override
Widget build(BuildContext context) {
return AnimatedBuilder(
animation: contentTreeController,
builder: (context, child) {
final isExpanded = contentTreeController.expandedIds.contains(group.id);

return StatelessExpansionTile(
isExpanded: isExpanded,
onExpansionChanged: (isExpanding) {
if (isExpanding) {
contentTreeController.expandGroup(group);
} else {
contentTreeController.collapseGroup(group);
}
},
title: GroupTitleWidget(
group: group,
onTap: () {
contentTreeController.onNodePressed(group);
},
),
child: GroupNodesWidget(
nodes: group.nodes,
contentTreeController: contentTreeController,
),
);
},
return ParentNodeWidget(
contentTreeController: contentTreeController,
node: group,
title: GroupTitleWidget(
group: group,
onTap: () {
contentTreeController.onNodePressed(group);
},
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ class GroupTitleWidget extends StatelessWidget {
child: Row(
children: [
_GroupProgressIndicator(group: group),
Text(
group.title,
style: Theme.of(context).textTheme.headlineMedium,
Expanded(
child: Text(
group.title,
style: Theme.of(context).textTheme.headlineMedium,
),
),
],
),
Expand Down
28 changes: 8 additions & 20 deletions learning/tour-of-beam/frontend/lib/pages/tour/widgets/module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@
*/

import 'package:flutter/material.dart';
import 'package:playground_components/playground_components.dart';

import '../../../models/module.dart';
import '../controllers/content_tree.dart';
import 'module_title.dart';
import 'node.dart';
import 'parent_node.dart';

class ModuleWidget extends StatelessWidget {
final ModuleModel module;
Expand All @@ -35,24 +34,13 @@ class ModuleWidget extends StatelessWidget {

@override
Widget build(BuildContext context) {
return Column(
children: [
ModuleTitleWidget(
module: module,
onTap: () => contentTreeController.onNodePressed(module),
),
...module.nodes
.map(
(node) => NodeWidget(
node: node,
contentTreeController: contentTreeController,
),
)
.toList(growable: false),
const BeamDivider(
margin: EdgeInsets.symmetric(vertical: BeamSizes.size10),
),
],
return ParentNodeWidget(
contentTreeController: contentTreeController,
node: module,
title: ModuleTitleWidget(
module: module,
onTap: () => contentTreeController.onNodePressed(module),
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,17 @@ class ModuleTitleWidget extends StatelessWidget {
child: Padding(
padding: const EdgeInsets.only(bottom: BeamSizes.size6),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
module.title,
style: Theme.of(context).textTheme.headlineMedium,
),
Padding(
padding: const EdgeInsets.only(right: BeamSizes.size4),
child: ComplexityWidget(complexity: module.complexity),
),
Expanded(
child: Text(
module.title,
style: Theme.of(context).textTheme.headlineMedium,
),
),
],
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import '../../../models/node.dart';
import '../controllers/content_tree.dart';
import 'node.dart';

class GroupNodesWidget extends StatelessWidget {
class NodesWidget extends StatelessWidget {
final List<NodeModel> nodes;
final ContentTreeController contentTreeController;

const GroupNodesWidget({
const NodesWidget({
required this.nodes,
required this.contentTreeController,
});
Expand Down
Loading