mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-08 00:51:20 +00:00
refactor(ui): Make users be ordered properly on users page
- Resolves https://git.selfprivacy.org/SelfPrivacy/selfprivacy.org.app/issues/340
This commit is contained in:
parent
eb92a8ee56
commit
5c329d47c1
|
@ -18,6 +18,32 @@ class UsersState extends ServerInstallationDependendState {
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [users, isLoading];
|
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({
|
UsersState copyWith({
|
||||||
final List<User>? users,
|
final List<User>? users,
|
||||||
final bool? isLoading,
|
final bool? isLoading,
|
||||||
|
|
|
@ -3,11 +3,11 @@ part of 'users.dart';
|
||||||
class _User extends StatelessWidget {
|
class _User extends StatelessWidget {
|
||||||
const _User({
|
const _User({
|
||||||
required this.user,
|
required this.user,
|
||||||
required this.isRootUser,
|
required this.isUserPrimary,
|
||||||
});
|
});
|
||||||
|
|
||||||
final User user;
|
final User user;
|
||||||
final bool isRootUser;
|
final bool isUserPrimary;
|
||||||
@override
|
@override
|
||||||
Widget build(final BuildContext context) => InkWell(
|
Widget build(final BuildContext context) => InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
|
@ -32,7 +32,7 @@ class _User extends StatelessWidget {
|
||||||
user.login,
|
user.login,
|
||||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||||
color: Theme.of(context).colorScheme.onBackground,
|
color: Theme.of(context).colorScheme.onBackground,
|
||||||
decoration: isRootUser
|
decoration: isUserPrimary
|
||||||
? TextDecoration.underline
|
? TextDecoration.underline
|
||||||
: user.isFoundOnServer
|
: user.isFoundOnServer
|
||||||
? TextDecoration.none
|
? TextDecoration.none
|
||||||
|
|
|
@ -45,15 +45,7 @@ class UsersPage extends StatelessWidget {
|
||||||
} else {
|
} else {
|
||||||
child = BlocBuilder<UsersCubit, UsersState>(
|
child = BlocBuilder<UsersCubit, UsersState>(
|
||||||
builder: (final BuildContext context, final UsersState state) {
|
builder: (final BuildContext context, final UsersState state) {
|
||||||
final List<User> users = state.users
|
final users = state.orderedUsers;
|
||||||
.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()),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (users.isEmpty) {
|
if (users.isEmpty) {
|
||||||
if (state.isLoading) {
|
if (state.isLoading) {
|
||||||
return const Center(
|
return const Center(
|
||||||
|
@ -115,7 +107,7 @@ class UsersPage extends StatelessWidget {
|
||||||
itemBuilder:
|
itemBuilder:
|
||||||
(final BuildContext context, final int index) => _User(
|
(final BuildContext context, final int index) => _User(
|
||||||
user: users[index],
|
user: users[index],
|
||||||
isRootUser: users[index].type == UserType.primary,
|
isUserPrimary: users[index].type == UserType.primary,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in a new issue