Skip to content

Commit

Permalink
Merge pull request #2 from pangeachat/no-space-message
Browse files Browse the repository at this point in the history
When no class/exchanges, give message on toggle dropdown
  • Loading branch information
wcjord authored Nov 30, 2023
2 parents 229836e + f54b32d commit 294d5a2
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 85 deletions.
3 changes: 2 additions & 1 deletion assets/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -3937,5 +3937,6 @@
"searchChatsRooms": "Search for #chats, @users...",
"groupName": "Group name",
"createGroupAndInviteUsers": "Create a group and invite users",
"groupCanBeFoundViaSearch": "Group can be found via search"
"groupCanBeFoundViaSearch": "Group can be found via search",
"inNoSpaces": "You are not a member of any classes or exchanges"
}
98 changes: 60 additions & 38 deletions lib/pangea/widgets/class/add_space_toggles.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ class AddToSpaceToggles extends StatefulWidget {
final String? activeSpaceId;
final AddToClassMode mode;

const AddToSpaceToggles(
{Key? key,
this.roomId,
this.startOpen = false,
this.activeSpaceId,
required this.mode})
: super(key: key);
const AddToSpaceToggles({
super.key,
this.roomId,
this.startOpen = false,
this.activeSpaceId,
required this.mode,
});

@override
AddToSpaceState createState() => AddToSpaceState();
Expand All @@ -55,16 +55,20 @@ class AddToSpaceState extends State<AddToSpaceToggles> {
possibleParents = Matrix.of(context)
.client
.rooms
.where(widget.mode == AddToClassMode.exchange
? (Room r) => r.isPangeaClass && widget.roomId != r.id
: (Room r) =>
(r.isPangeaClass || r.isExchange) && widget.roomId != r.id)
.where(
widget.mode == AddToClassMode.exchange
? (Room r) => r.isPangeaClass && widget.roomId != r.id
: (Room r) =>
(r.isPangeaClass || r.isExchange) && widget.roomId != r.id,
)
.toList();

parents = widget.roomId != null
? possibleParents
.where((r) =>
r.spaceChildren.any((room) => room.roomId == widget.roomId))
.where(
(r) =>
r.spaceChildren.any((room) => room.roomId == widget.roomId),
)
.map((r) => SuggestionStatus(false, r))
.cast<SuggestionStatus>()
.toList()
Expand Down Expand Up @@ -115,8 +119,10 @@ class AddToSpaceState extends State<AddToSpaceToggles> {

Future<void> _addSingleSpace(String roomToAddId, Room newParent) {
GoogleAnalytics.addParent(roomToAddId, newParent.classCode);
return newParent.setSpaceChild(roomToAddId,
suggested: isSuggestedInSpace(newParent));
return newParent.setSpaceChild(
roomToAddId,
suggested: isSuggestedInSpace(newParent),
);
}

Future<void> addSpaces(String roomToAddId) async {
Expand All @@ -141,8 +147,10 @@ class AddToSpaceState extends State<AddToSpaceToggles> {
setState(
() => add
? parents.add(SuggestionStatus(false, possibleParent))
: parents.removeWhere((suggestionStatus) =>
suggestionStatus.room.id == possibleParent.id),
: parents.removeWhere(
(suggestionStatus) =>
suggestionStatus.room.id == possibleParent.id,
),
);
}

Expand Down Expand Up @@ -246,29 +254,43 @@ class AddToSpaceState extends State<AddToSpaceToggles> {
setState(() => isOpen = !isOpen);
},
),
if (isOpen)
Scrollbar(
controller: scrollController,
thumbVisibility: true,
child: SingleChildScrollView(
controller: scrollController,
child: Column(
children: [
const Divider(height: 1),
SizedBox(
height: min(possibleParents.length * 55, 500),
child: ListView.builder(
shrinkWrap: true,
itemCount: possibleParents.length,
itemBuilder: (BuildContext context, int i) {
return getAddToSpaceToggleItem(i);
},
if (isOpen) ...[
const Divider(height: 1),
possibleParents.isNotEmpty
? Scrollbar(
controller: scrollController,
thumbVisibility: true,
child: SingleChildScrollView(
controller: scrollController,
child: Column(
children: [
const Divider(height: 1),
SizedBox(
height: min(possibleParents.length * 55, 500),
child: ListView.builder(
shrinkWrap: true,
itemCount: possibleParents.length,
itemBuilder: (BuildContext context, int i) {
return getAddToSpaceToggleItem(i);
},
),
),
],
),
),
],
),
),
),
)
: Center(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Text(
L10n.of(context)!.inNoSpaces,
style: TextStyle(
color: Theme.of(context).colorScheme.secondary,
),
),
),
),
],
],
);
}
Expand Down
Loading

0 comments on commit 294d5a2

Please sign in to comment.