-
Notifications
You must be signed in to change notification settings - Fork 39
Draggable Space Ordering and Space Folders #701
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Contributor
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. move these into new |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import 'package:commet/client/client.dart'; | ||
|
|
||
| sealed class ResolvedSidebarItem { | ||
| const ResolvedSidebarItem(); | ||
| } | ||
|
|
||
| class ResolvedSpace extends ResolvedSidebarItem { | ||
| final Space space; | ||
| const ResolvedSpace(this.space); | ||
| } | ||
|
|
||
| class ResolvedFolder extends ResolvedSidebarItem { | ||
| final String id; | ||
| final String name; | ||
| final List<Space> spaces; | ||
| final bool isExpanded; | ||
|
|
||
| const ResolvedFolder({ | ||
| required this.id, | ||
| required this.name, | ||
| required this.spaces, | ||
| this.isExpanded = false, | ||
|
Contributor
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. UI state probably shouldn't be stored here, at the moment for subspaces we store expanded state just in the widget itself, which I think is preferable |
||
| }); | ||
| } | ||
|
Contributor
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. This should be implemented as a Client Component, with an abstract |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import 'package:commet/client/sidebar/sidebar_model.dart'; | ||
|
|
||
| class SidebarData { | ||
| static const String accountDataType = 'im.commet.space_sidebar'; | ||
|
Contributor
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. use |
||
| static const int currentVersion = 1; | ||
|
|
||
| final int version; | ||
| final List<SidebarItem> items; | ||
|
|
||
| const SidebarData({this.version = currentVersion, this.items = const []}); | ||
|
|
||
| factory SidebarData.fromJson(Map<String, dynamic> json) { | ||
| final version = json['version'] as int? ?? currentVersion; | ||
| final rawItems = json['items'] as List<dynamic>? ?? []; | ||
|
|
||
| final items = <SidebarItem>[]; | ||
| for (final raw in rawItems) { | ||
| if (raw is! Map<String, dynamic>) continue; | ||
|
|
||
| final type = raw['type'] as String?; | ||
| switch (type) { | ||
| case 'space': | ||
| final id = raw['id'] as String?; | ||
| if (id != null) items.add(SidebarSpace(id)); | ||
| break; | ||
| case 'folder': | ||
| final id = raw['id'] as String?; | ||
| final name = raw['name'] as String? ?? ''; | ||
| final children = (raw['children'] as List<dynamic>?) | ||
| ?.whereType<String>() | ||
| .toList() ?? | ||
| []; | ||
| if (id != null && children.isNotEmpty) { | ||
| items.add(SidebarFolder(id: id, name: name, children: children)); | ||
| } | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| return SidebarData(version: version, items: items); | ||
| } | ||
|
|
||
| Map<String, dynamic> toJson() { | ||
| return { | ||
| 'version': version, | ||
| 'items': items.map((item) { | ||
|
Contributor
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. Instead of a list, store in a Map, and sort by |
||
| return switch (item) { | ||
| SidebarSpace s => {'type': 'space', 'id': s.spaceId}, | ||
| SidebarFolder f => { | ||
| 'type': 'folder', | ||
| 'id': f.id, | ||
| 'name': f.name, | ||
| 'children': f.children, | ||
| }, | ||
| }; | ||
| }).toList(), | ||
| }; | ||
| } | ||
|
|
||
| static SidebarData empty() => const SidebarData(); | ||
| } | ||
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 dont think this needs to exist in ClientManager, maybe in the state of
SideNavigationBarmakes more sense?