mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-07 00:24:18 +00:00
Merge branch 'master' into email-copy
This commit is contained in:
commit
86f2d0c0bb
|
@ -18,6 +18,32 @@ class UsersState extends ServerInstallationDependendState {
|
|||
@override
|
||||
List<Object> get props => [users, isLoading];
|
||||
|
||||
/// Makes a copy of existing users list, but places 'primary'
|
||||
/// to the beginning and sorts the rest alphabetically
|
||||
///
|
||||
/// If found a 'root' user, it doesn't get copied into the result
|
||||
List<User> get orderedUsers {
|
||||
User? primaryUser;
|
||||
final List<User> normalUsers = [];
|
||||
for (final User user in users) {
|
||||
if (user.type == UserType.primary) {
|
||||
primaryUser = user;
|
||||
continue;
|
||||
}
|
||||
if (user.type == UserType.root) {
|
||||
continue;
|
||||
}
|
||||
normalUsers.add(user);
|
||||
}
|
||||
|
||||
normalUsers.sort(
|
||||
(final User a, final User b) =>
|
||||
a.login.toLowerCase().compareTo(b.login.toLowerCase()),
|
||||
);
|
||||
|
||||
return primaryUser == null ? normalUsers : [primaryUser] + normalUsers;
|
||||
}
|
||||
|
||||
UsersState copyWith({
|
||||
final List<User>? users,
|
||||
final bool? isLoading,
|
||||
|
|
|
@ -3,11 +3,11 @@ part of 'users.dart';
|
|||
class _User extends StatelessWidget {
|
||||
const _User({
|
||||
required this.user,
|
||||
required this.isRootUser,
|
||||
required this.isPrimaryUser,
|
||||
});
|
||||
|
||||
final User user;
|
||||
final bool isRootUser;
|
||||
final bool isPrimaryUser;
|
||||
@override
|
||||
Widget build(final BuildContext context) => InkWell(
|
||||
onTap: () {
|
||||
|
@ -32,7 +32,7 @@ class _User extends StatelessWidget {
|
|||
user.login,
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
color: Theme.of(context).colorScheme.onBackground,
|
||||
decoration: isRootUser
|
||||
decoration: isPrimaryUser
|
||||
? TextDecoration.underline
|
||||
: user.isFoundOnServer
|
||||
? TextDecoration.none
|
||||
|
|
|
@ -47,15 +47,7 @@ class UsersPage extends StatelessWidget {
|
|||
} else {
|
||||
child = BlocBuilder<UsersCubit, UsersState>(
|
||||
builder: (final BuildContext context, final UsersState state) {
|
||||
final List<User> users = state.users
|
||||
.where((final user) => user.type != UserType.root)
|
||||
.toList();
|
||||
// final List<User> users = [];
|
||||
users.sort(
|
||||
(final User a, final User b) =>
|
||||
a.login.toLowerCase().compareTo(b.login.toLowerCase()),
|
||||
);
|
||||
|
||||
final users = state.orderedUsers;
|
||||
if (users.isEmpty) {
|
||||
if (state.isLoading) {
|
||||
return const Center(
|
||||
|
@ -117,7 +109,7 @@ class UsersPage extends StatelessWidget {
|
|||
itemBuilder:
|
||||
(final BuildContext context, final int index) => _User(
|
||||
user: users[index],
|
||||
isRootUser: users[index].type == UserType.primary,
|
||||
isPrimaryUser: users[index].type == UserType.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
|
Loading…
Reference in a new issue