Add unreads back

This commit is contained in:
Henry Hiles 2025-11-23 14:07:47 -05:00
commit 76b81ab8c4
No known key found for this signature in database
4 changed files with 36 additions and 47 deletions

View file

@ -1,16 +1,19 @@
import "package:color_hash/color_hash.dart"; import "package:color_hash/color_hash.dart";
import "package:flutter/material.dart";
import "package:flutter/widgets.dart"; import "package:flutter/widgets.dart";
class AvatarOrHash extends StatelessWidget { class AvatarOrHash extends StatelessWidget {
final Uri? avatar; final Uri? avatar;
final String title; final String title;
final Widget? fallback; final Widget? fallback;
final bool hasBadge;
final double height; final double height;
final Map<String, String> headers; final Map<String, String> headers;
const AvatarOrHash( const AvatarOrHash(
this.avatar, this.avatar,
this.title, { this.title, {
this.fallback, this.fallback,
this.hasBadge = false,
this.height = 24, this.height = 24,
required this.headers, required this.headers,
super.key, super.key,
@ -22,18 +25,24 @@ class AvatarOrHash extends StatelessWidget {
color: ColorHash(title).color, color: ColorHash(title).color,
child: Center(child: Text(title[0])), child: Center(child: Text(title[0])),
); );
return ClipRRect( return Center(
borderRadius: BorderRadius.all(Radius.circular(4)), child: ClipRRect(
child: SizedBox( borderRadius: BorderRadius.all(Radius.circular(4)),
height: height, child: Badge(
width: height, isLabelVisible: hasBadge,
child: avatar == null smallSize: 10,
? fallback ?? box backgroundColor: Theme.of(context).colorScheme.primary,
: Image.network( child: avatar == null
avatar.toString(), ? fallback ?? box
headers: headers, : Image.network(
errorBuilder: (_, _, _) => box, avatar.toString(),
), headers: headers,
width: height,
height: height,
fit: BoxFit.contain,
errorBuilder: (_, _, _) => box,
),
),
), ),
); );
} }

View file

@ -26,7 +26,7 @@ class RoomAppbar extends StatelessWidget implements PreferredSizeWidget {
? AvatarOrHash( ? AvatarOrHash(
room.avatar, room.avatar,
room.title, room.title,
height: 32, height: 24,
fallback: Icon(Icons.numbers), fallback: Icon(Icons.numbers),
headers: room.roomData.client.headers, headers: room.roomData.client.headers,
) )

View file

@ -8,7 +8,6 @@ import "package:nexus/controllers/spaces_controller.dart";
import "package:nexus/helpers/extension_helper.dart"; import "package:nexus/helpers/extension_helper.dart";
import "package:nexus/pages/settings_page.dart"; import "package:nexus/pages/settings_page.dart";
import "package:nexus/widgets/avatar_or_hash.dart"; import "package:nexus/widgets/avatar_or_hash.dart";
import "package:nexus/widgets/chat_page/unread.dart";
class Sidebar extends HookConsumerWidget { class Sidebar extends HookConsumerWidget {
const Sidebar({super.key}); const Sidebar({super.key});
@ -47,18 +46,16 @@ class Sidebar extends HookConsumerWidget {
destinations: spaces destinations: spaces
.map( .map(
(space) => NavigationRailDestination( (space) => NavigationRailDestination(
icon: Unread( icon: AvatarOrHash(
isUnread: space.avatar,
fallback: space.icon,
space.title,
headers: space.client.headers,
hasBadge:
space.children.firstWhereOrNull( space.children.firstWhereOrNull(
(room) => room.roomData.hasNewMessages, (room) => room.roomData.hasNewMessages,
) != ) !=
null, null,
child: AvatarOrHash(
space.avatar,
fallback: space.icon,
space.title,
headers: space.client.headers,
),
), ),
label: Text(space.title), label: Text(space.title),
padding: EdgeInsets.only(top: 4), padding: EdgeInsets.only(top: 4),
@ -110,16 +107,14 @@ class Sidebar extends HookConsumerWidget {
.map( .map(
(room) => NavigationRailDestination( (room) => NavigationRailDestination(
label: Text(room.title), label: Text(room.title),
icon: Unread( icon: AvatarOrHash(
isUnread: room.roomData.hasNewMessages, hasBadge: room.roomData.hasNewMessages,
child: AvatarOrHash( room.avatar,
room.avatar, room.title,
room.title, fallback: selectedSpace == 1
fallback: selectedSpace == 1 ? null
? null : Icon(Icons.numbers),
: Icon(Icons.numbers), headers: space.client.headers,
headers: space.client.headers,
),
), ),
), ),
) )

View file

@ -1,15 +0,0 @@
import "package:flutter/material.dart";
class Unread extends StatelessWidget {
final bool isUnread;
final Widget child;
const Unread({required this.isUnread, required this.child, super.key});
@override
Widget build(BuildContext context) => Badge(
smallSize: 8,
backgroundColor: Theme.of(context).colorScheme.primary,
isLabelVisible: isUnread,
child: child,
);
}