implemented global user search integration for Talk chats with role-coded badges and direct chat creation logic
This commit is contained in:
@@ -2,14 +2,14 @@ import 'package:async/async.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../api/errors/error_mapper.dart';
|
||||
import '../../../api/marianumcloud/autocomplete/autocomplete_api.dart';
|
||||
import '../../../api/marianumcloud/autocomplete/autocomplete_response.dart';
|
||||
import '../../../model/endpoint_data.dart';
|
||||
import '../../../api/marianumconnect/queries/user_search/user_search.dart';
|
||||
import '../../../api/marianumconnect/queries/user_search/user_search_response.dart';
|
||||
import '../../../widget/app_progress_indicator.dart';
|
||||
import '../../../widget/placeholder_view.dart';
|
||||
import 'widgets/user_search_tile.dart';
|
||||
|
||||
class JoinChat extends SearchDelegate<String> {
|
||||
CancelableOperation<AutocompleteResponse>? future;
|
||||
CancelableOperation<UserSearchResponse>? future;
|
||||
|
||||
@override
|
||||
List<Widget>? buildActions(BuildContext context) => [
|
||||
@@ -27,7 +27,7 @@ class JoinChat extends SearchDelegate<String> {
|
||||
},
|
||||
),
|
||||
if (query.isNotEmpty)
|
||||
IconButton(onPressed: () => query = '', icon: const Icon(Icons.delete)),
|
||||
IconButton(onPressed: () => query = '', icon: const Icon(Icons.clear)),
|
||||
];
|
||||
|
||||
@override
|
||||
@@ -39,36 +39,30 @@ class JoinChat extends SearchDelegate<String> {
|
||||
|
||||
if (query.isEmpty) {
|
||||
return const PlaceholderView(
|
||||
text: 'Suche nach benutzern',
|
||||
text: 'Suche nach Schülerinnen, Schülern und Lehrkräften',
|
||||
icon: Icons.person_search_outlined,
|
||||
);
|
||||
}
|
||||
|
||||
future = CancelableOperation.fromFuture(AutocompleteApi().find(query));
|
||||
return FutureBuilder<AutocompleteResponse>(
|
||||
future = CancelableOperation.fromFuture(UserSearch().run(query));
|
||||
return FutureBuilder<UserSearchResponse>(
|
||||
future: future!.value,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
final results = snapshot.data!.result;
|
||||
if (results.isEmpty) {
|
||||
return PlaceholderView(
|
||||
icon: Icons.person_off_outlined,
|
||||
text: 'Keine Treffer für „$query"',
|
||||
);
|
||||
}
|
||||
return ListView.builder(
|
||||
itemCount: snapshot.data!.data.length,
|
||||
itemCount: results.length,
|
||||
itemBuilder: (context, index) {
|
||||
var object = snapshot.data!.data[index];
|
||||
var circleAvatar = CircleAvatar(
|
||||
foregroundImage: Image.network(
|
||||
'https://${EndpointData().nextcloud().full()}/avatar/${object.id}/128',
|
||||
).image,
|
||||
backgroundColor: Theme.of(context).primaryColor,
|
||||
foregroundColor: Colors.white,
|
||||
child: const Icon(Icons.person),
|
||||
);
|
||||
return ListTile(
|
||||
leading: circleAvatar,
|
||||
title: Text(object.label),
|
||||
subtitle: Text(object.id),
|
||||
trailing: const Icon(Icons.arrow_right),
|
||||
onTap: () {
|
||||
close(context, object.id);
|
||||
},
|
||||
final object = results[index];
|
||||
return UserSearchTile(
|
||||
user: object,
|
||||
onTap: () => close(context, object.username),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user